From a9ec4eff3c9e16b7d0dc1c5490eff159b223e01d Mon Sep 17 00:00:00 2001 From: TurtleP Date: Sun, 29 Sep 2024 12:46:25 -0400 Subject: [PATCH] push whatever this was --- CMakeLists.txt | 2 ++ include/modules/keyboard/Keyboard.tcc | 2 ++ .../include/driver/graphics/StreamBuffer.hpp | 26 +++++++------------ platform/cafe/source/driver/display/GX2.cpp | 19 +++++--------- .../cafe/source/modules/graphics/Graphics.cpp | 15 ++++++----- .../cafe/source/modules/graphics/Shader.cpp | 20 +++++++------- source/modules/graphics/Graphics.cpp | 6 +++-- source/modules/graphics/wrap_Graphics.cpp | 2 +- 8 files changed, 43 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ace4e9b3..9d37dc00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,6 +180,8 @@ if (NINTENDO_WIIU) find_package(Freetype REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE Freetype::Freetype bz2 png turbojpeg ddsparse) + + execute_process(COMMAND patch -d ${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket -N -i ${PROJECT_SOURCE_DIR}/platform/cafe/libraries/luasocket.patch) endif() add_custom_target(test diff --git a/include/modules/keyboard/Keyboard.tcc b/include/modules/keyboard/Keyboard.tcc index 5c80e55f..7d02827b 100644 --- a/include/modules/keyboard/Keyboard.tcc +++ b/include/modules/keyboard/Keyboard.tcc @@ -26,6 +26,8 @@ namespace love using ValidationError = const char**; #elif defined(__SWITCH__) using ValidationError = char*; +#else + using ValidationError = void*; #endif typedef KeyboardResult (*KeyboardValidationCallback)(const KeyboardValidationInfo* info, diff --git a/platform/cafe/include/driver/graphics/StreamBuffer.hpp b/platform/cafe/include/driver/graphics/StreamBuffer.hpp index b9552545..145b8109 100644 --- a/platform/cafe/include/driver/graphics/StreamBuffer.hpp +++ b/platform/cafe/include/driver/graphics/StreamBuffer.hpp @@ -15,19 +15,14 @@ namespace love public: StreamBuffer(BufferUsage usage, size_t size) : StreamBufferBase(usage, size) { - this->buffer = new GX2RBuffer(); - - if (this->buffer == nullptr) - throw love::Exception(E_OUT_OF_MEMORY); - auto flags = (usage == BufferUsage::BUFFERUSAGE_VERTEX) ? GX2R_RESOURCE_BIND_VERTEX_BUFFER : GX2R_RESOURCE_BIND_INDEX_BUFFER; - this->buffer->elemCount = size; - this->buffer->elemSize = sizeof(T); - this->buffer->flags = flags | BUFFER_CREATE_FLAGS; + this->buffer.elemCount = size; + this->buffer.elemSize = sizeof(T); + this->buffer.flags = flags | BUFFER_CREATE_FLAGS; - if (!GX2RCreateBuffer(this->buffer)) + if (!GX2RCreateBuffer(&this->buffer)) throw love::Exception("Failed to create StreamBuffer"); } @@ -35,7 +30,7 @@ namespace love { MapInfo info {}; - auto* data = (T*)GX2RLockBufferEx(this->buffer, GX2R_RESOURCE_BIND_NONE); + auto* data = (T*)GX2RLockBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE); info.data = &data[this->index]; info.size = this->bufferSize - this->frameGPUReadOffset; @@ -45,29 +40,28 @@ namespace love size_t unmap(size_t) { - GX2RUnlockBufferEx(this->buffer, GX2R_RESOURCE_BIND_NONE); + GX2RUnlockBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE); if (this->usage == BufferUsage::BUFFERUSAGE_VERTEX) - GX2RSetAttributeBuffer(this->buffer, 0, this->buffer->elemSize, 0); + GX2RSetAttributeBuffer(&this->buffer, 0, this->buffer.elemSize, 0); return this->index; } ~StreamBuffer() { - GX2RDestroyBufferEx(this->buffer, GX2R_RESOURCE_BIND_NONE); - delete this->buffer; + GX2RDestroyBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE); } ptrdiff_t getHandle() const override { - return (ptrdiff_t)this->buffer; + return (ptrdiff_t)std::addressof(this->buffer); } private: static constexpr auto BUFFER_CREATE_FLAGS = GX2R_RESOURCE_USAGE_CPU_READ | GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ; - GX2RBuffer* buffer; + GX2RBuffer buffer; }; } // namespace love diff --git a/platform/cafe/source/driver/display/GX2.cpp b/platform/cafe/source/driver/display/GX2.cpp index fa2a87eb..e1d5718d 100644 --- a/platform/cafe/source/driver/display/GX2.cpp +++ b/platform/cafe/source/driver/display/GX2.cpp @@ -112,8 +112,6 @@ namespace love GX2Init(attributes); - this->createFramebuffers(); - this->state = (GX2ContextState*)memalign(GX2_CONTEXT_STATE_ALIGNMENT, sizeof(GX2ContextState)); if (!this->state) @@ -122,8 +120,10 @@ namespace love GX2SetupContextStateEx(this->state, false); GX2SetContextState(this->state); + this->createFramebuffers(); + GX2SetDepthOnlyControl(false, false, GX2_COMPARE_FUNC_ALWAYS); - GX2SetAlphaTest(false, GX2_COMPARE_FUNC_ALWAYS, 0.0f); + // GX2SetAlphaTest(false, GX2_COMPARE_FUNC_ALWAYS, 0.0f); GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, false, true); GX2SetSwapInterval(1); @@ -157,12 +157,7 @@ namespace love const auto& info = love::getScreenInfo(); for (size_t index = 0; index < info.size(); ++index) - { - Framebuffer framebuffer {}; - framebuffer.create(info[index]); - - this->targets[index] = std::move(framebuffer); - } + this->targets[index].create(info[index]); } GX2ColorBuffer& GX2::getInternalBackbuffer() @@ -190,7 +185,7 @@ namespace love { if (!this->inFrame) { - GX2SetContextState(this->state); + // GX2SetContextState(this->state); this->inFrame = true; } } @@ -228,6 +223,7 @@ namespace love if (bindingModified) { + // this->targets[love::currentScreen].useState(); GX2SetColorBuffer(target, GX2_RENDER_TARGET_0); this->setMode(target->surface.width, target->surface.height); } @@ -323,10 +319,7 @@ namespace love } if (Keyboard()->hasTextInput()) - { nn::swkbd::DrawDRC(); - GX2SetContextState(this->state); - } for (auto& target : this->targets) target.copyScanBuffer(); diff --git a/platform/cafe/source/modules/graphics/Graphics.cpp b/platform/cafe/source/modules/graphics/Graphics.cpp index 207425b0..91fe7262 100644 --- a/platform/cafe/source/modules/graphics/Graphics.cpp +++ b/platform/cafe/source/modules/graphics/Graphics.cpp @@ -373,13 +373,14 @@ namespace love gx2.prepareDraw(this); gx2.bindTextureToUnit(command.texture, 0); - auto* buffer = (GX2RBuffer*)command.indexBuffer->getHandle(); - const size_t offset = command.indexBufferOffset; - - const auto mode = GX2::getPrimitiveType(command.primitiveType); - const auto indexType = GX2::getIndexType(command.indexType); - - GX2RDrawIndexed(mode, buffer, indexType, command.indexCount, offset, 0, command.instanceCount); + const auto mode = GX2::getPrimitiveType(command.primitiveType); + auto* buffer = (GX2RBuffer*)command.indexBuffer->getHandle(); + const auto indexType = GX2::getIndexType(command.indexType); + const uint32_t count = (uint32_t)command.indexCount; + const uint32_t offset = (uint32_t)command.indexBufferOffset; + const uint32_t instanceCount = (uint32_t)command.instanceCount; + + GX2RDrawIndexed(mode, buffer, indexType, count, offset, 0, instanceCount); ++this->drawCalls; } diff --git a/platform/cafe/source/modules/graphics/Shader.cpp b/platform/cafe/source/modules/graphics/Shader.cpp index 101daf66..259e694e 100644 --- a/platform/cafe/source/modules/graphics/Shader.cpp +++ b/platform/cafe/source/modules/graphics/Shader.cpp @@ -108,7 +108,7 @@ namespace love auto transform = graphics->getTransform(); - GX2Invalidate(INVALIDATE_UNIFORM_BLOCK, uniform, sizeof(Uniform)); + GX2Invalidate(GX2_INVALIDATE_MODE_UNIFORM_BLOCK, uniform, sizeof(Uniform)); GX2SetVertexUniformBlock(this->uniform.location, sizeof(Uniform), uniform); } @@ -119,18 +119,18 @@ namespace love void Shader::attach() { - if (current != this) - { - Graphics::flushBatchedDrawsGlobal(); + // if (current != this) + // { + Graphics::flushBatchedDrawsGlobal(); - GX2SetShaderMode(GX2_SHADER_MODE_UNIFORM_BLOCK); + GX2SetShaderMode(GX2_SHADER_MODE_UNIFORM_BLOCK); - GX2SetFetchShader(&this->program.fetchShader); - GX2SetVertexShader(this->program.vertexShader); - GX2SetPixelShader(this->program.pixelShader); + GX2SetFetchShader(&this->program.fetchShader); + GX2SetVertexShader(this->program.vertexShader); + GX2SetPixelShader(this->program.pixelShader); - current = this; - } + current = this; + // } } bool Shader::validate(const char* filepath, std::string& error) diff --git a/source/modules/graphics/Graphics.cpp b/source/modules/graphics/Graphics.cpp index 41c35fd7..74e2c651 100644 --- a/source/modules/graphics/Graphics.cpp +++ b/source/modules/graphics/Graphics.cpp @@ -4,6 +4,8 @@ #include "common/Console.hpp" #include "common/screen.hpp" +#include + namespace love { GraphicsBase::GraphicsBase(const char* name) : @@ -991,8 +993,8 @@ namespace love for (int index = 0; index < points; ++index, phi += shift) { - coords[index].x = x + a * std::cosf(phi); - coords[index].y = y + b * std::sinf(phi); + coords[index].x = x + a * cosf(phi); + coords[index].y = y + b * sinf(phi); } coords[points] = coords[0]; diff --git a/source/modules/graphics/wrap_Graphics.cpp b/source/modules/graphics/wrap_Graphics.cpp index a57a68cb..33122efb 100644 --- a/source/modules/graphics/wrap_Graphics.cpp +++ b/source/modules/graphics/wrap_Graphics.cpp @@ -872,7 +872,7 @@ static void luax_checktexturesettings(lua_State* L, int index, bool optional, bo lua_rawgeti(L, -1, index); const char* formatName = luaL_checkstring(L, -1); - PixelFormat format; + PixelFormat format = PIXELFORMAT_UNKNOWN; if (!love::getConstant(formatName, format)) luax_enumerror(L, "pixel format", formatName);