diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 78fc9674..a6f50c87 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -14,24 +14,20 @@ "ctrIncludePaths": [ "${workspaceFolder}/platform/ctr/include/**", "${workspaceFolder}/platform/ctr/libraries/**", - "${env:DEVKITPRO}/devkitARM/arm-none-eabi/include/**", - "${env:DEVKITPRO}/devkitARM/lib/gcc/arm-none-eabi/**", - "${env:DEVKITPRO}/libctru/include/**", - "${env:DEVKITPRO}/portlibs/3ds/include/**" + "C:/msys64/opt/devkitpro/libctru/include/**", + "C:/msys64/opt/devkitpro/portlibs/3ds/include/**" ], "ctrDefines": [ "__3DS__", "__OS__=\"Horizon\"", "__CONSOLE__=\"3DS\"" ], - "ctrCompilerPath": "${env:DEVKITPRO}/devkitARM/bin/arm-none-eabi-g++", + "ctrCompilerPath": "C:/msys64/opt/devkitpro/devkitARM/bin/arm-none-eabi-g++", /* Switch paths and info */ "hacIncludePaths": [ "${workspaceFolder}/platform/hac/include/**", - "${env:DEVKITPRO}/devkitA64/aarch64-none-elf/include/**", - "${env:DEVKITPRO}/devkitA64/lib/gcc/aarch64-none-elf/**", - "${env:DEVKITPRO}/libnx/include/**", - "${env:DEVKITPRO}/portlibs/switch/include/**" + "C:/msys64/opt/devkitpro/libnx/include/**", + "C:/msys64/opt/devkitpro/portlibs/switch/include/**" ], "hacDefines": [ "__SWITCH__", @@ -39,22 +35,20 @@ "__CONSOLE__=\"Switch\"", "__OS__=\"Horizon\"" ], - "hacCompilerPath": "${env:DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++", + "hacCompilerPath": "C:/msys64/opt/devkitpro/devkitA64/bin/aarch64-none-elf-g++", /* Wii U paths and info */ "cafeIncludePaths": [ "${workspaceFolder}/platform/cafe/include/**", - "${env:DEVKITPRO}/devkitPPC/powerpc-eabi/include/**", - "${env:DEVKITPRO}/devkitPPC/lib/gcc/powerpc-eabi/**", - "${env:DEVKITPRO}/wut/include/**", - "${env:DEVKITPRO}/portlibs/wiiu/include/**", - "${env:DEVKITPRO}/portlibs/ppc/include/**" + "C:/msys64/opt/devkitpro/wut/include/**", + "C:/msys64/opt/devkitpro/portlibs/wiiu/include/**", + "C:/msys64/opt/devkitpro/portlibs/ppc/include/**" ], "cafeDefines": [ "__WIIU__", "__OS__=\"Cafe\"", "__CONSOLE__=\"Wii U\"" ], - "cafeCompilerPath": "${env:DEVKITPRO}/devkitPPC/bin/powerpc-eabi-g++" + "cafeCompilerPath": "C:/msys64/opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++" }, "configurations": [ { diff --git a/platform/cafe/include/modules/keyboard_ext.hpp b/platform/cafe/include/modules/keyboard_ext.hpp index 8126c189..8c1758f7 100644 --- a/platform/cafe/include/modules/keyboard_ext.hpp +++ b/platform/cafe/include/modules/keyboard_ext.hpp @@ -25,15 +25,12 @@ namespace love virtual ~Keyboard(); - void Draw(GX2ContextState* restored) + void SetContextState() { - if (!this->showing) + if (!this->IsShowing()) return; - nn::swkbd::DrawDRC(); - - GX2SetContextState(restored); - Shader<>::current->Attach(true); + GX2SetContextState(this->state); } void SetTextInput(const KeyboardOptions& options); @@ -45,13 +42,13 @@ namespace love const bool IsShowing() const { - return this->showing; + auto state = nn::swkbd::GetStateInputForm(); + return state != nn::swkbd::State::Hidden; } void HideKeyboard() { nn::swkbd::DisappearInputForm(); - this->showing = false; } void Utf16toUtf8Text(); @@ -72,6 +69,5 @@ namespace love FSClient* client; bool inited; - bool showing; }; } // namespace love diff --git a/platform/cafe/source/modules/keyboard_ext.cpp b/platform/cafe/source/modules/keyboard_ext.cpp index 26416680..1de1d7b9 100644 --- a/platform/cafe/source/modules/keyboard_ext.cpp +++ b/platform/cafe/source/modules/keyboard_ext.cpp @@ -14,17 +14,20 @@ Keyboard::Keyboard() : createArgs {}, appearArgs {}, client(nullptr), - inited(false), - showing(false) + inited(false) {} void Keyboard::Initialize() { this->state = (GX2ContextState*)memalign(GX2_CONTEXT_STATE_ALIGNMENT, sizeof(GX2ContextState)); - this->client = (FSClient*)MEMAllocFromDefaultHeap(sizeof(FSClient)); + if (!this->state) + throw love::Exception("Failed to allocate GX2ContextState for nn::swkbd!"); + GX2SetupContextStateEx(this->state, false); + this->client = (FSClient*)MEMAllocFromDefaultHeap(sizeof(FSClient)); + if (!this->client) throw love::Exception("Failed to allocate FSClient for nn::swkbd!"); @@ -83,8 +86,5 @@ void Keyboard::SetTextInput(const KeyboardOptions& options) this->appearArgs.inputFormArg.maxTextLength = options.maxLength; this->appearArgs.inputFormArg.passwordMode = GetPasswordMode(options.isPassword); - if (!nn::swkbd::AppearInputForm(this->appearArgs)) - return; - - this->showing = true; + nn::swkbd::AppearInputForm(this->appearArgs); } diff --git a/platform/cafe/source/utilities/driver/framebuffer.cpp b/platform/cafe/source/utilities/driver/framebuffer.cpp index bae88144..469a9fec 100644 --- a/platform/cafe/source/utilities/driver/framebuffer.cpp +++ b/platform/cafe/source/utilities/driver/framebuffer.cpp @@ -1,5 +1,7 @@ #include +#include + #include #include @@ -15,6 +17,8 @@ using namespace love; +#define Keyboard() (Module::GetInstance>(Module::M_KEYBOARD)) + Framebuffer::Framebuffer() : modelView(1.0f), transform(nullptr), @@ -182,7 +186,7 @@ void Framebuffer::SetDRCScanBuffer() void Framebuffer::CopyScanBuffer() { - const auto target = Framebuffer::SCAN_TARGETS[(uint8_t)this->id]; + auto target = (this->Is(Screen::TV)) ? GX2_SCAN_TARGET_TV : GX2_SCAN_TARGET_DRC; GX2CopyColorBufferToScanBuffer(&this->colorBuffer, target); } diff --git a/platform/cafe/source/utilities/driver/renderer_ext.cpp b/platform/cafe/source/utilities/driver/renderer_ext.cpp index ee9ac571..d0e9eec2 100644 --- a/platform/cafe/source/utilities/driver/renderer_ext.cpp +++ b/platform/cafe/source/utilities/driver/renderer_ext.cpp @@ -12,8 +12,6 @@ #include #include -#include - using namespace love; #define Keyboard() (Module::GetInstance>(Module::M_KEYBOARD)) @@ -63,7 +61,8 @@ Renderer::Renderer() : GX2SetupContextStateEx(this->state, false); GX2SetContextState(this->state); - GX2SetDepthOnlyControl(true, true, GX2_COMPARE_FUNC_ALWAYS); + GX2SetDepthOnlyControl(false, false, GX2_COMPARE_FUNC_ALWAYS); + // GX2SetAlphaTest(true, GX2_COMPARE_FUNC_GREATER, 0); GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, false, true); GX2SetSwapInterval(1); @@ -249,22 +248,21 @@ void Renderer::BindFramebuffer(Texture* texture) void Renderer::Present() { - if (Keyboard() != nullptr) - Keyboard()->Draw(this->state); - - /* flush commands before copying color buffers */ - GX2Flush(); + if (Keyboard()->IsShowing()) + { + nn::swkbd::DrawDRC(); + GX2SetContextState(this->state); + Shader::current->Attach(true); + } /* copy our color buffers to their scan buffers */ - for (auto& framebuffer : this->framebuffers) - framebuffer.second.CopyScanBuffer(); + this->framebuffers[Screen::TV].CopyScanBuffer(); + + this->framebuffers[Screen::GAMEPAD].CopyScanBuffer(); /* swap scan buffers */ GX2SwapScanBuffers(); - /* reset state for next frame */ - GX2SetContextState(this->state); - /* ** flush again as GX2WaitForFlip ** will block the CPU diff --git a/platform/hac/CMakeLists.txt b/platform/hac/CMakeLists.txt index 16804de7..6d7e8f9b 100644 --- a/platform/hac/CMakeLists.txt +++ b/platform/hac/CMakeLists.txt @@ -43,7 +43,6 @@ target_sources(${PROJECT_NAME} PRIVATE source/objects/wrap_imagedata_ext.cpp source/objects/wrap_joystick_ext.cpp source/runtime.cpp - source/utilities/driver/CImage.cpp source/utilities/driver/CIntrusiveTree.cpp source/utilities/driver/CMemPool.cpp source/utilities/driver/dsp_ext.cpp diff --git a/platform/hac/source/utilities/driver/CImage.cpp b/platform/hac/source/utilities/driver/CImage.cpp deleted file mode 100644 index 38310066..00000000 --- a/platform/hac/source/utilities/driver/CImage.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -** Sample Framework for deko3d Applications -** CExternalImage.cpp: Utility class for loading images from the filesystem -*/ -#include -#include - -#include - -using namespace love; - -bool CImage::load(love::PixelFormat pixelFormat, bool isSRGB, void* buffer, size_t size, int width, - int height, bool empty) -{ - return false; -} - -/* replace the pixels at a location */ -bool CImage::replacePixels(CMemPool& scratchPool, dk::Device device, const void* data, size_t size, - dk::Queue transferQueue, const love::Rect& rect) -{ - if (data == nullptr) - return false; - - CMemPool::Handle tempImageMemory = scratchPool.allocate(size, DK_IMAGE_LINEAR_STRIDE_ALIGNMENT); - - if (!tempImageMemory) - return false; - - memcpy(tempImageMemory.getCpuAddr(), data, size); - - /* - ** We need to have a command buffer and some more memory for it - ** so allocate both and add the memory to the temporary command buffer - */ - dk::UniqueCmdBuf tempCmdBuff = dk::CmdBufMaker { device }.create(); - CMemPool::Handle tempCmdMem = scratchPool.allocate(DK_MEMBLOCK_ALIGNMENT); - tempCmdBuff.addMemory(tempCmdMem.getMemBlock(), tempCmdMem.getOffset(), tempCmdMem.getSize()); - - dk::ImageView imageView { m_image }; - tempCmdBuff.copyBufferToImage( - { tempImageMemory.getGpuAddr() }, imageView, - { uint32_t(rect.x), uint32_t(rect.y), 0, uint32_t(rect.w), uint32_t(rect.h), 1 }); - - // Submit the commands to the transfer queue - transferQueue.submitCommands(tempCmdBuff.finishList()); - transferQueue.waitIdle(); - - // Destroy the memory we don't need - tempCmdMem.destroy(); - tempImageMemory.destroy(); - - return true; -} - -/* load a CImage with transparent black pixels */ -bool CImage::loadEmptyPixels(CMemPool& imagePool, CMemPool& scratchPool, dk::Device device, - dk::Queue transferQueue, uint32_t width, uint32_t height, - DkImageFormat dkFormat, uint32_t flags) -{ - PixelFormat format; - // if (!Renderer::pixelFormat.Find(dkFormat)) - // return false; - - size_t size = love::GetPixelFormatSliceSize(format, width, height); - - if (size <= 0) - return false; - - CMemPool::Handle tempImageMemory = scratchPool.allocate(size, DK_IMAGE_LINEAR_STRIDE_ALIGNMENT); - - if (!tempImageMemory) - return false; - - /* memcpy for transparent black pixels */ - std::vector empty(size, 0); - memcpy(tempImageMemory.getCpuAddr(), empty.data(), sizeof(uint8_t) * empty.size()); - - /* - ** We need to have a command buffer and some more memory for it - ** so allocate both and add the memory to the temporary command buffer - */ - dk::UniqueCmdBuf tempCmdBuff = dk::CmdBufMaker { device }.create(); - CMemPool::Handle tempCmdMem = scratchPool.allocate(DK_MEMBLOCK_ALIGNMENT); - tempCmdBuff.addMemory(tempCmdMem.getMemBlock(), tempCmdMem.getOffset(), tempCmdMem.getSize()); - - // Set the image layout for the image - dk::ImageLayout layout; - dk::ImageLayoutMaker { device } - .setFlags(flags) - .setFormat(dkFormat) - .setDimensions(width, height) - .initialize(layout); - - // Create the image - m_mem = imagePool.allocate(layout.getSize(), layout.getAlignment()); - m_image.initialize(layout, m_mem.getMemBlock(), m_mem.getOffset()); - m_descriptor.initialize(m_image); - - dk::ImageView imageView { m_image }; - tempCmdBuff.copyBufferToImage({ tempImageMemory.getGpuAddr() }, imageView, - { 0, 0, 0, width, height, 1 }); - - // Submit the commands to the transfer queue - transferQueue.submitCommands(tempCmdBuff.finishList()); - transferQueue.waitIdle(); - - // Destroy the memory we don't need - tempCmdMem.destroy(); - tempImageMemory.destroy(); - - return true; -} - -bool CImage::loadMemory(CMemPool& imagePool, CMemPool& scratchPool, dk::Device device, - dk::Queue transferQueue, const void* data, uint32_t width, uint32_t height, - DkImageFormat dkFormat, uint32_t flags) -{ - if (data == nullptr) - return false; - - // Allocate temporary memory for the image - PixelFormat format; - // if (!::deko3d::GetConstant(dkFormat, format)) - // return false; - - size_t size = love::GetPixelFormatSliceSize(format, width, height); - - if (size <= 0) - return false; - - CMemPool::Handle tempImageMemory = scratchPool.allocate(size, DK_IMAGE_LINEAR_STRIDE_ALIGNMENT); - - if (!tempImageMemory) - return false; - - memcpy(tempImageMemory.getCpuAddr(), data, size); - - /* - ** We need to have a command buffer and some more memory for it - ** so allocate both and add the memory to the temporary command buffer - */ - dk::UniqueCmdBuf tempCmdBuff = dk::CmdBufMaker { device }.create(); - CMemPool::Handle tempCmdMem = scratchPool.allocate(DK_MEMBLOCK_ALIGNMENT); - tempCmdBuff.addMemory(tempCmdMem.getMemBlock(), tempCmdMem.getOffset(), tempCmdMem.getSize()); - - // Set the image layout for the image - dk::ImageLayout layout; - dk::ImageLayoutMaker { device } - .setFlags(flags) - .setFormat(dkFormat) - .setDimensions(width, height) - .initialize(layout); - - // Create the image - m_mem = imagePool.allocate(layout.getSize(), layout.getAlignment()); - m_image.initialize(layout, m_mem.getMemBlock(), m_mem.getOffset()); - m_descriptor.initialize(m_image); - - /* - ** Create the image's view and copy the data - ** to the temporary image memory - */ - dk::ImageView imageView { m_image }; - tempCmdBuff.copyBufferToImage({ tempImageMemory.getGpuAddr() }, imageView, - { 0, 0, 0, width, height, 1 }, 0); - - // Submit the commands to the transfer queue - transferQueue.submitCommands(tempCmdBuff.finishList()); - transferQueue.waitIdle(); - - // Destroy the memory we don't need - tempCmdMem.destroy(); - tempImageMemory.destroy(); - - return true; -}