Skip to content

Commit

Permalink
fix lots of text usage crashing, needs optimizing
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Nov 15, 2023
1 parent fc6290b commit d8c295b
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 64 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ FetchContent_Declare(lua-https
GIT_TAG TurtleP/certs
)

FetchContent_MakeAvailable(lua-https)
FetchContent_GetProperties(lua-https)
if(NOT lua-https_POPULATED)
FetchContent_Populate(lua-https)
add_subdirectory(${lua-https_SOURCE_DIR} ${lua-https_BINARY_DIR})
endif()

add_library(lua-https STATIC
${lua-https_SOURCE_DIR}/src/common/config.h
Expand Down
4 changes: 2 additions & 2 deletions include/modules/graphics/graphics.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ namespace love
bool is2D = transform.IsAffine2DTransform();

const int count = points.size() - (skipLastVertex ? 1 : 0);
DrawCommand<Console::Which> command(count, vertex::PRIMITIVE_TRIANGLE_FAN);
DrawCommand command(count, vertex::PRIMITIVE_TRIANGLE_FAN);

if (is2D)
transform.TransformXY(std::span(command.Positions().get(), command.count),
Expand Down Expand Up @@ -1398,7 +1398,7 @@ namespace love
const auto& transform = this->GetTransform();
bool is2D = transform.IsAffine2DTransform();

DrawCommand<Console::Which> command(points.size(), vertex::PRIMITIVE_POINTS);
DrawCommand command(points.size(), vertex::PRIMITIVE_POINTS);

if (is2D)
transform.TransformXY(std::span(command.Positions().get(), points.size()), points);
Expand Down
8 changes: 4 additions & 4 deletions include/objects/font/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <objects/rasterizer/rasterizer.hpp>
#include <utilities/shaper/textshaper.hpp>

#include <map>
#include <vector>

#if defined(__3DS__)
Expand Down Expand Up @@ -99,8 +100,7 @@ namespace love
const Matrix4& localTransform, const Color& color);

void Printf(Graphics<Console::ALL>& graphics, const ColoredStrings& text, float wrap,
AlignMode alignment, const Matrix4& localTransform,
const Color& color);
AlignMode alignment, const Matrix4& localTransform, const Color& color);

int GetAscent() const;

Expand Down Expand Up @@ -175,7 +175,7 @@ namespace love

const Glyph& FindGlyph(TextShaper::GlyphIndex glyphIndex);

void Printv(Graphics<Console::ALL>& graphics, const Matrix4& transform,
void Render(Graphics<Console::ALL>& graphics, const Matrix4& transform,
const std::vector<DrawCommand>& drawCommands,
const std::vector<vertex::Vertex>& vertices);

Expand All @@ -196,7 +196,7 @@ namespace love

StrongReference<TextShaper> shaper;

std::unordered_map<uint32_t, Glyph> glyphs;
std::map<uint32_t, Glyph> glyphs;
std::unordered_map<uint64_t, float> kernings;

static constexpr auto SPACES_PER_TAB = 0x04;
Expand Down
14 changes: 11 additions & 3 deletions include/utilities/driver/renderer/drawcommand.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace love
#else
using Handle = Texture<Console::Which>;
#endif

template<Console::Platform T = Console::ALL>
struct DrawCommand
{
public:
Expand Down Expand Up @@ -68,11 +66,21 @@ namespace love
return this->positions;
}

const std::span<Vector2> GetPositions() const
{
return std::span<Vector2>(this->positions.get(), this->count);
}

const std::unique_ptr<Vertex[]>& Vertices() const
{
return this->vertices;
}

const std::span<Vertex> GetVertices() const
{
return std::span<Vertex>(this->vertices.get(), this->count);
}

/* primitive */
void FillVertices(const Color& color)
{
Expand Down Expand Up @@ -166,4 +174,4 @@ namespace love
std::vector<Handle*> handles;
CullMode cullMode;
}; // namespace love
} // namespace love
} // namespace love
17 changes: 17 additions & 0 deletions include/utilities/driver/renderer/renderstate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ namespace love
}
};

struct StencilState
{
CompareMode compare = COMPARE_ALWAYS;
StencilAction action = STENCIL_KEEP;

int value = 0;
uint32_t readMask = 0xFFFFFFFF;
uint32_t writeMask = 0xFFFFFFFF;

bool operator==(const StencilState& other) const
{
return this->compare == other.compare && this->action == other.action &&
this->value == other.value && this->readMask == other.readMask &&
this->writeMask == other.writeMask;
}
};

struct ColorMask
{
bool r : 1, g : 1, b : 1, a : 1;
Expand Down
4 changes: 2 additions & 2 deletions platform/cafe/include/utilities/driver/renderer_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace love

void SetPointSize(float size);

bool Render(DrawCommand<Console::CAFE>& command);
bool Render(DrawCommand& command);

void UseProgram(const WHBGfxShaderGroup& group);

Expand Down Expand Up @@ -253,7 +253,7 @@ namespace love
Framebuffer* current;
GX2ContextState* state;

static inline std::vector<DrawCommand<Console::CAFE>> m_commands {};
static inline std::vector<DrawCommand m_commands {};
static inline CommonFormat m_format = CommonFormat::NONE;
static inline GX2RBuffer m_buffer {};
static inline size_t m_vertexOffset = 0;
Expand Down
2 changes: 1 addition & 1 deletion platform/cafe/source/objects/texture_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void Texture<Console::CAFE>::Draw(Graphics<Console::CAFE>& graphics, Quad* quad,

Matrix4 transform(stateTransform, matrix);

love::DrawCommand<Console::CAFE> command(4);
love::DrawCommand command(4);
command.shader = Shader<>::STANDARD_TEXTURE;
command.format = vertex::CommonFormat::TEXTURE;
command.type = vertex::PRIMITIVE_QUADS;
Expand Down
2 changes: 1 addition & 1 deletion platform/cafe/source/utilities/driver/renderer_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void Renderer<Console::CAFE>::FlushVertices()
m_commands.clear();
}

bool Renderer<Console::CAFE>::Render(DrawCommand<Console::CAFE>& command)
bool Renderer<Console::CAFE>::Render(DrawCommand& command)
{
if (!Shader<Console::CAFE>::IsDefaultActive(command.shader))
{
Expand Down
12 changes: 10 additions & 2 deletions platform/ctr/include/utilities/driver/renderer_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <utilities/driver/framebuffer_ext.hpp>
#include <utilities/driver/renderer/drawcommand.tcc>
#include <utilities/driver/renderer/renderstate.hpp>
#include <utilities/driver/renderer/samplerstate.hpp>
#include <utilities/driver/renderer/vertex.hpp>

Expand Down Expand Up @@ -65,7 +66,7 @@ namespace love
/* todo: canvases */
void BindFramebuffer(Texture<Console::ALL>* texture = nullptr);

bool Render(DrawCommand<Console::CTR>& command);
bool Render(DrawCommand& command);

void Present();

Expand Down Expand Up @@ -202,6 +203,13 @@ namespace love
C3D_Mtx modelView;
C3D_Mtx projection;
C3D_RenderTarget* target;
bool dirtyProjection;

vertex::CullMode cullMode;

love::RenderState::ColorMask colorMask;
love::RenderState::BlendState blendState;
love::RenderState::StencilState stencilState;
} context;

std::vector<std::function<void()>> deferred;
Expand All @@ -212,7 +220,7 @@ namespace love
static inline PrimitiveType currentPrimitiveType = PRIMITIVE_MAX_ENUM;
static inline int totalVertices = 0;

static inline std::vector<DrawCommand<Console::CTR>> m_commands {};
static inline std::vector<DrawCommand> m_commands {};

C3D_BufInfo bufferInfo;

Expand Down
2 changes: 1 addition & 1 deletion platform/ctr/source/objects/texture_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void Texture<Console::CTR>::Draw(Graphics<Console::CTR>& graphics, Quad* quad,

Matrix4 translated(graphics.GetTransform(), matrix);

DrawCommand<Console::CTR> command(0x04, vertex::PRIMITIVE_TRIANGLE_FAN);
DrawCommand command(0x04, vertex::PRIMITIVE_TRIANGLE_FAN);
command.handles = { this->texture };
command.format = CommonFormat::TEXTURE;

Expand Down
31 changes: 24 additions & 7 deletions platform/ctr/source/utilities/driver/renderer/renderer_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ void Renderer<Console::CTR>::DestroyFramebuffers()

void Renderer<Console::CTR>::Clear(const Color& color)
{
C3D_FrameSplit(0);
C3D_RenderTargetClear(this->context.target, C3D_CLEAR_ALL, color.abgr(), 0);
}

Expand Down Expand Up @@ -152,20 +151,22 @@ void Renderer<Console::CTR>::FlushVertices()
m_commands.clear();
}

bool Renderer<Console::CTR>::Render(DrawCommand<Console::CTR>& command)
bool Renderer<Console::CTR>::Render(DrawCommand& command)
{
{
Shader<Console::CTR>::defaults[command.shader]->Attach();

auto uniforms = Shader<Console::CTR>::current->GetUniformLocations();

C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uniforms.uLocProjMtx, &this->context.projection);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uniforms.uLocMdlView, &this->context.modelView);
if (this->context.dirtyProjection)
{
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uniforms.uLocProjMtx, &this->context.projection);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uniforms.uLocMdlView, &this->context.modelView);
this->context.dirtyProjection = false;
}
}

// check if texture is the same, or no texture at all
if (command.handles.empty() ||
(command.handles.size() > 0 && this->currentTexture == command.handles.back()))
if (command.handles.empty() || (this->currentTexture == command.handles.back()))
{
++drawCalls;
m_commands.push_back(command.Clone());
Expand All @@ -182,6 +183,7 @@ bool Renderer<Console::CTR>::Render(DrawCommand<Console::CTR>& command)

C3D_TexBind(0, command.handles.back());
}

++drawCalls;
m_commands.push_back(command.Clone());
return true;
Expand Down Expand Up @@ -221,17 +223,20 @@ void Renderer<Console::CTR>::SetViewport(const Rect& rect, bool tilt)
if (newView.w == GSP_SCREEN_HEIGHT_TOP || newView.w == GSP_SCREEN_HEIGHT_TOP_2X)
{
Mtx_Copy(&this->context.projection, &this->targets[0].GetProjView());
this->context.dirtyProjection = true;
return;
}
else if (newView.w == GSP_SCREEN_HEIGHT_BOTTOM)
{
Mtx_Copy(&this->context.projection, &this->targets[2].GetProjView());
this->context.dirtyProjection = true;
return;
}
}

auto* ortho = tilt ? Mtx_OrthoTilt : Mtx_Ortho;
ortho(&this->context.projection, 0.0f, rect.w, rect.h, 0.0f, Z_NEAR, Z_FAR, true);
this->context.dirtyProjection = true;

C3D_SetViewport(0, 0, rect.w, rect.h);
}
Expand Down Expand Up @@ -259,7 +264,11 @@ void Renderer<Console::CTR>::SetMeshCullMode(vertex::CullMode mode)
if (!(cullMode = Renderer::cullModes.Find(mode)))
return;

if (this->context.cullMode == mode)
return;

C3D_CullFace(*cullMode);
this->context.cullMode = mode;
}

/* ??? */
Expand Down Expand Up @@ -300,6 +309,10 @@ void Renderer<Console::CTR>::SetColorMask(const RenderState::ColorMask& mask)
uint8_t writeMask = GPU_WRITE_DEPTH;
writeMask |= mask.GetColorMask();

if (this->context.colorMask == mask)
return;

this->context.colorMask = mask;
C3D_DepthTest(true, GPU_GEQUAL, (GPU_WRITEMASK)writeMask);
}

Expand Down Expand Up @@ -329,5 +342,9 @@ void Renderer<Console::CTR>::SetBlendMode(const RenderState::BlendState& state)
if (!(dstAlpha = Renderer::blendFactors.Find(state.dstFactorA)))
return;

if (this->context.blendState == state)
return;

this->context.blendState = state;
C3D_AlphaBlend(*opRGB, *opAlpha, *srcColor, *dstColor, *srcAlpha, *dstAlpha);
}
2 changes: 1 addition & 1 deletion platform/hac/include/utilities/driver/renderer_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace love

void CheckDescriptorsDirty(const std::vector<DkResHandle>& handles);

bool Render(const DrawCommand<Console::HAC>& command);
bool Render(const DrawCommand& command);

void UseProgram(Shader<Console::Which>::Program program);

Expand Down
2 changes: 1 addition & 1 deletion platform/hac/source/objects/texture_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void Texture<Console::HAC>::Draw(Graphics<Console::HAC>& graphics, Quad* quad,

Matrix4 transform(stateTransform, matrix);

DrawCommand<Console::HAC> command(4);
DrawCommand command(4);
command.shader = Shader<>::STANDARD_TEXTURE;
command.format = vertex::CommonFormat::TEXTURE;
command.type = vertex::PRIMITIVE_QUADS;
Expand Down
2 changes: 1 addition & 1 deletion platform/hac/source/utilities/driver/renderer_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void Renderer<Console::HAC>::SetAttributes(const vertex::attributes::Attribs& at
this->commandBuffer.bindVtxBufferState(attributes.bufferState);
}

bool Renderer<Console::HAC>::Render(const DrawCommand<Console::HAC>& command)
bool Renderer<Console::HAC>::Render(const DrawCommand& command)
{
if (command.count > (this->vertices.getSize() - this->firstVertex))
return false;
Expand Down
3 changes: 0 additions & 3 deletions source/modules/graphics/wrap_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,14 @@ getImageData(lua_State* L, int index, bool allowCompressed, float* dpiScale)

if (allowCompressed && module->IsCompressed(data))
{
LOG("Loading compressed image.");
luax::CatchException(L, [&]() {
compressed.Set(module->NewCompressedImageData(data), Acquire::NORETAIN);
});
LOG("Compressed image loaded.");
}
else
{
luax::CatchException(
L, [&]() { image.Set(module->NewImageData(data), Acquire::NORETAIN); });
LOG("Imagedata loaded.");
}
}
else
Expand Down
Loading

0 comments on commit d8c295b

Please sign in to comment.