Skip to content

Commit

Permalink
push some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Jun 27, 2024
1 parent 6415ec7 commit 7ff0e70
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
4 changes: 3 additions & 1 deletion platform/cafe/include/driver/display/GX2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include "driver/display/Framebuffer.hpp"
#include "driver/display/Renderer.tcc"
#include "driver/display/Uniform.hpp"

#include "modules/graphics/vertex.hpp"

#include <gx2/enum.h>
#include <gx2/sampler.h>
#include <gx2/texture.h>
Expand Down Expand Up @@ -180,6 +180,8 @@ namespace love
GX2ColorBuffer* boundFramebuffer = nullptr;
} context;

Uniform* uniform;

bool inForeground;

void* commandBuffer;
Expand Down
12 changes: 7 additions & 5 deletions platform/cafe/include/driver/display/Uniform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

#include "utility/logfile.hpp"

namespace love
{
static void updateGlmMatrix(glm::mat4& out, const glm::mat4& matrix)
static glm::mat4 updateMatrix(const glm::mat4& matrix)
{
glm::mat4 out(1.0f);

unsigned int* destination = (unsigned int*)glm::value_ptr(out);
const unsigned int* source = (const unsigned int*)glm::value_ptr(matrix);

Expand All @@ -17,7 +21,7 @@ namespace love
for (size_t i = 0; i < count; i++)
destination[i] = __builtin_bswap32(source[i]);

out = glm::make_mat4(destination);
return glm::make_mat4(destination);
}

struct Uniform
Expand All @@ -28,9 +32,7 @@ namespace love
public:
Uniform()
{
updateGlmMatrix(this->modelView, glm::mat4(1.0f));
this->modelView = updateMatrix(glm::mat4(1.0f));
}
};

static Uniform* uniform;
} // namespace love
2 changes: 1 addition & 1 deletion platform/cafe/include/driver/graphics/StreamBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace love
else
info.data = &this->data[this->index];

info.size = this->bufferSize;
info.size = this->bufferSize - this->frameGPUReadOffset;
return info;
}

Expand Down
2 changes: 1 addition & 1 deletion platform/cafe/include/modules/graphics/Shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace love

ptrdiff_t getHandle() const override;

void updateBuiltinUniforms(GraphicsBase* graphics);
void updateBuiltinUniforms(GraphicsBase* graphics, Uniform* uniform);

uint32_t getPixelSamplerLocation(int index);

Expand Down
9 changes: 6 additions & 3 deletions platform/cafe/source/driver/display/GX2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace love

GX2Shutdown();

delete this->uniform;

free(this->state);
this->state = nullptr;

Expand Down Expand Up @@ -137,7 +139,8 @@ namespace love
this->context.depthWrite = false;
this->context.compareMode = GX2_COMPARE_FUNC_ALWAYS;

uniform = (Uniform*)std::aligned_alloc(0x100, sizeof(Uniform));
this->uniform = new (std::align_val_t(0x100)) Uniform();

this->bindFramebuffer(&this->targets[0].get());

this->initialized = true;
Expand Down Expand Up @@ -257,7 +260,7 @@ namespace love
if ((Shader*)ShaderBase::current != nullptr)
{
auto* shader = (Shader*)ShaderBase::current;
shader->updateBuiltinUniforms(graphics);
shader->updateBuiltinUniforms(graphics, this->uniform);
}
}

Expand Down Expand Up @@ -324,7 +327,7 @@ namespace love
GX2SetViewport(x, y, width, height, Framebuffer::Z_NEAR, Framebuffer::Z_FAR);

auto ortho = glm::ortho(x, width, height, y, (int)Framebuffer::Z_NEAR, (int)Framebuffer::Z_FAR);
updateGlmMatrix(love::uniform->projection, ortho);
this->uniform->projection = updateMatrix(ortho);

this->context.viewport = viewport;
}
Expand Down
7 changes: 4 additions & 3 deletions platform/cafe/source/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <gx2/draw.h>
#include <gx2r/draw.h>

#include "utility/logfile.hpp"

namespace love
{
Graphics::Graphics() : GraphicsBase("love.graphics.gx2")
Expand Down Expand Up @@ -273,7 +275,6 @@ namespace love
else
gx2.bindFramebuffer((GX2ColorBuffer*)targets.getFirstTarget().texture->getRenderTargetHandle());

bool tilt = isWindow ? true : false;
gx2.setViewport({ 0, 0, pixelWidth, pixelHeight });

if (state.scissor)
Expand Down Expand Up @@ -379,8 +380,8 @@ namespace love

const auto mode = GX2::getPrimitiveType(command.primitiveType);
const auto indexType = GX2::getIndexType(command.indexType);

GX2DrawIndexedEx(mode, command.indexCount, indexType, buffer, offset, command.instanceCount);
LOG("{:d}", (int)indexType);
GX2DrawIndexedEx(mode, command.indexCount, indexType, &buffer[offset], 0, command.instanceCount);

++this->drawCalls;
}
Expand Down
6 changes: 3 additions & 3 deletions platform/cafe/source/modules/graphics/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ namespace love
return this->program.pixelShader->samplerVars[index].location;
}

void Shader::updateBuiltinUniforms(GraphicsBase* graphics)
void Shader::updateBuiltinUniforms(GraphicsBase* graphics, Uniform* uniform)
{
if (current != this)
return;

GX2Invalidate(INVALIDATE_UNIFORM_BLOCK, (void*)&love::uniform, sizeof(Uniform));
GX2SetVertexUniformBlock(1, sizeof(Uniform), (const void*)&love::uniform);
GX2Invalidate(INVALIDATE_UNIFORM_BLOCK, (void*)uniform, sizeof(Uniform));
GX2SetVertexUniformBlock(1, sizeof(Uniform), (const void*)uniform);
}

ptrdiff_t Shader::getHandle() const
Expand Down

0 comments on commit 7ff0e70

Please sign in to comment.