# Rewrite 5
- Move Libraries Source into pd directory and give them all their own CMakeLists.txt - Partial rewrite core (color, autogenerated vec), lithium (now uses UNIQUE PTR for Commands), UI7 - Use MenuV2 as new standart in UI7 - Implementz ViewPort Pre alpha to UI7 - Add Line Drawing to DrawList (not Working) - Implement a Complete new drievrs API (static Drivers) - NO SUPPORT FOR SHARED LIBRARY BUILDS IN VERSION 5 YET - Add Tools to Autogenerate Headers and Stuff
This commit is contained in:
		
							
								
								
									
										25
									
								
								backends/3ds/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										25
									
								
								backends/3ds/CMakeLists.txt
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,18 +1,13 @@ | ||||
| cmake_minimum_required(VERSION 3.22) | ||||
|  | ||||
| # Make sure to use 3ds toolschain for 3ds build :) | ||||
| if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) | ||||
|     if(DEFINED ENV{DEVKITPRO}) | ||||
|         set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/3DS.cmake" CACHE PATH "toolchain file") | ||||
|     else() | ||||
|         message(FATAL_ERROR "Please define DEVKITPRO to point to your SDK path!") | ||||
|     endif() | ||||
| endif() | ||||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O3") | ||||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions") | ||||
| project(pd-3ds LANGUAGES CXX VERSION 0.5.0) | ||||
|  | ||||
| add_library(pd-backend-3ds STATIC | ||||
| source/li_backend_c3d.cpp | ||||
| source/pd_hid_3ds.cpp) | ||||
| target_include_directories(pd-backend-3ds PUBLIC include) | ||||
| target_link_libraries(pd-backend-3ds PUBLIC palladium) | ||||
| set(SRC | ||||
|     source/bknd-gfx.cpp | ||||
|     source/bknd-hid.cpp | ||||
|     source/pd-3ds.cpp | ||||
| ) | ||||
|  | ||||
| pd_add_lib(pd-3ds SRC_FILES ${SRC}) | ||||
| target_include_directories(pd-3ds PUBLIC include) | ||||
| target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d) | ||||
|   | ||||
							
								
								
									
										32
									
								
								backends/3ds/include/pd-3ds.hpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								backends/3ds/include/pd-3ds.hpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| #pragma once | ||||
|  | ||||
| /* | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) 2024 - 2025 tobid7 | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| #include <pd-3ds/bknd-gfx.hpp> | ||||
| #include <pd-3ds/bknd-hid.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| void Init(void* data = nullptr); | ||||
| } | ||||
							
								
								
									
										46
									
								
								backends/3ds/include/li_backend_c3d.hpp → backends/3ds/include/pd-3ds/bknd-gfx.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										46
									
								
								backends/3ds/include/li_backend_c3d.hpp → backends/3ds/include/pd-3ds/bknd-gfx.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -22,15 +22,12 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
| */ | ||||
| 
 | ||||
| #pragma once | ||||
|  */ | ||||
| 
 | ||||
| #include <3ds.h> | ||||
| #include <citro3d.h> | ||||
| 
 | ||||
| #include <pd/core/core.hpp> | ||||
| #include <pd/lithium/backend.hpp> | ||||
| #include <pd/lithium/lithium.hpp> | ||||
| 
 | ||||
| namespace PD { | ||||
| template <typename T> | ||||
| @@ -43,30 +40,27 @@ class LinearAlloc : public Allocator<T> { | ||||
|   T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); } | ||||
|   void Deallocate(T* ptr) { linearFree(ptr); } | ||||
| }; | ||||
| namespace LI { | ||||
| class Backend_C3D : public PD::LI::Backend { | ||||
| 
 | ||||
| namespace Li { | ||||
| class GfxC3D : public GfxDriver { | ||||
|  public: | ||||
|   Backend_C3D() : LI::Backend("Citro3D") {} | ||||
|   ~Backend_C3D() {} | ||||
|   PD_SMART_CTOR(Backend_C3D) | ||||
|   GfxC3D() : GfxDriver("Citro3D") {} | ||||
|   ~GfxC3D() = default; | ||||
| 
 | ||||
|   PD_SHARED(GfxC3D); | ||||
| 
 | ||||
|   void Init() override; | ||||
| 
 | ||||
|   void Deinit() override; | ||||
| 
 | ||||
|   void NewFrame() override; | ||||
| 
 | ||||
|   void BindTexture(PD::LI::TexAddress addr) override; | ||||
| 
 | ||||
|   void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override; | ||||
| 
 | ||||
|   PD::LI::Texture::Ref LoadTexture( | ||||
|   void BindTex(PD::Li::TexAddress addr) override; | ||||
|   void RenderDrawData( | ||||
|       const std::vector<PD::Li::Command::Ref>& Commands) override; | ||||
|   PD::Li::Texture::Ref LoadTex( | ||||
|       const std::vector<PD::u8>& pixels, int w, int h, | ||||
|       PD::LI::Texture::Type type = PD::LI::Texture::Type::RGBA32, | ||||
|       PD::LI::Texture::Filter filter = | ||||
|           PD::LI::Texture::Filter::LINEAR) override; | ||||
|       PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32, | ||||
|       PD::Li::Texture::Filter filter = | ||||
|           PD::Li::Texture::Filter::LINEAR) override; | ||||
| 
 | ||||
|  private: | ||||
|   Vec<Vertex, LinearAlloc<Vertex>> VertexBuffer; | ||||
|   Vec<u16, LinearAlloc<u16>> IndexBuffer; | ||||
|   size_t CurrentVertex = 0; | ||||
| @@ -76,9 +70,9 @@ class Backend_C3D : public PD::LI::Backend { | ||||
|   DVLB_s* ShaderCode; | ||||
|   shaderProgram_s Shader; | ||||
|   C3D_AttrInfo ShaderInfo; | ||||
|   // For Stats
 | ||||
|   PD::u32 num_vtx = 0; | ||||
|   PD::u32 num_idx = 0; | ||||
|   // Stats oder so IDNK zu lange her
 | ||||
|   PD::u32 NumVtx; | ||||
|   PD::u32 NumIdx; | ||||
| }; | ||||
| }  // namespace LI
 | ||||
| }  // namespace Li
 | ||||
| }  // namespace PD
 | ||||
							
								
								
									
										16
									
								
								backends/3ds/include/pd_hid_3ds.hpp → backends/3ds/include/pd-3ds/bknd-hid.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										16
									
								
								backends/3ds/include/pd_hid_3ds.hpp → backends/3ds/include/pd-3ds/bknd-hid.hpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,7 +2,8 @@ | ||||
| 
 | ||||
| /*
 | ||||
| MIT License | ||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) | ||||
| 
 | ||||
| Copyright (c) 2024 - 2025 tobid7 | ||||
| 
 | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| @@ -23,21 +24,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  */ | ||||
| 
 | ||||
| #include <pd/core/hid_driver.hpp> | ||||
| #include <pd/drivers/drivers.hpp> | ||||
| 
 | ||||
| namespace PD { | ||||
| class Hid3DS : public Hid { | ||||
| class Hid3DS : public HidDriver { | ||||
|  public: | ||||
|   /**
 | ||||
|    * Constructor to setup Key binds | ||||
|    */ | ||||
|   Hid3DS(); | ||||
|   ~Hid3DS() = default; | ||||
|   PD_SMART_CTOR(Hid3DS) | ||||
| 
 | ||||
|   /**
 | ||||
|    * Overrideing the Update Function for Input Checking etc | ||||
|    */ | ||||
|   PD_SHARED(Hid3DS); | ||||
| 
 | ||||
|   void Update() override; | ||||
| }; | ||||
| }  // namespace PD
 | ||||
| @@ -1,117 +0,0 @@ | ||||
| #pragma once | ||||
|  | ||||
| /* | ||||
| MIT License | ||||
| Copyright (c) 2024 - 2025 René Amthor (tobid7) | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| #include <3ds.h> | ||||
| #include <arpa/inet.h> | ||||
| #include <malloc.h> | ||||
| #include <netinet/in.h> | ||||
| #include <sys/socket.h> | ||||
|  | ||||
| #include <pd/net/backend.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| class NetBackend3DS : public Net::Backend { | ||||
|  public: | ||||
|   NetBackend3DS() : Net::Backend("3DS") {} | ||||
|   ~NetBackend3DS() = default; | ||||
|   PD_SMART_CTOR(NetBackend3DS) | ||||
|  | ||||
|   bool Init() override { | ||||
|     pSocBuffer = (uint32_t*)memalign(pSocAlign, pSocBufferSize); | ||||
|     Result ret = 0; | ||||
|     if (pSocBuffer == NULL) { | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     if ((ret = socInit(pSocBuffer, pSocBufferSize)) != 0) { | ||||
|       return false; | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   void Deinit() override { socExit(); } | ||||
|   int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); } | ||||
|   void Close(int sock_id) override { close(sock_id); } | ||||
|   int GetInvalidRef() const override { return -1; } | ||||
|  | ||||
|   bool Bind(int sock_id, u16 port) { | ||||
|     sockaddr_in addr{}; | ||||
|     addr.sin_family = AF_INET; | ||||
|     addr.sin_port = htons(port); | ||||
|     addr.sin_addr.s_addr = INADDR_ANY; | ||||
|     return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1; | ||||
|   } | ||||
|   bool Listen(int sock_id, int backlog = 5) { | ||||
|     return listen(sock_id, backlog) != -1; | ||||
|   } | ||||
|  | ||||
|   bool WaitForRead(int sock_id, int timeout_ms) override { | ||||
|     fd_set set; | ||||
|     FD_ZERO(&set); | ||||
|     FD_SET(sock_id, &set); | ||||
|  | ||||
|     timeval timeout{}; | ||||
|     timeout.tv_sec = timeout_ms / 1000; | ||||
|     timeout.tv_usec = (timeout_ms % 1000) * 1000; | ||||
|  | ||||
|     int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout); | ||||
|     return (result > 0 && FD_ISSET(sock_id, &set)); | ||||
|   } | ||||
|  | ||||
|   bool Accept(int sock_id, Net::Socket::Ref client) { | ||||
|     int client_soc = accept(sock_id, nullptr, nullptr); | ||||
|     if (client_soc == -1) { | ||||
|       return false; | ||||
|     } | ||||
|     client->pSocket = client_soc; | ||||
|     return true; | ||||
|   } | ||||
|   bool Connect(int sock_id, const std::string& ip, u16 port) { | ||||
|     sockaddr_in addr{}; | ||||
|     addr.sin_family = AF_INET; | ||||
|     addr.sin_port = htons(port); | ||||
|     inet_pton(AF_INET, ip.c_str(), &addr.sin_addr); | ||||
|     return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1; | ||||
|   } | ||||
|   int Send(int sock_id, const std::string& data) { | ||||
|     return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0); | ||||
|   } | ||||
|   int Receive(int sock_id, std::string& data, int size = 1024) { | ||||
|     char* tmp = new char[size]; | ||||
|     int res = recv(sock_id, tmp, size, 0); | ||||
|     if (res > 0) { | ||||
|       data.assign(tmp, res); | ||||
|     } | ||||
|     delete[] tmp; | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   /** using libctru u32 here */ | ||||
|   const uint32_t pSocAlign = 0x1000; | ||||
|   const uint32_t pSocBufferSize = 0x100000; | ||||
|   uint32_t* pSocBuffer = nullptr; | ||||
| }; | ||||
| }  // namespace PD | ||||
							
								
								
									
										87
									
								
								backends/3ds/source/li_backend_c3d.cpp → backends/3ds/source/bknd-gfx.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										87
									
								
								backends/3ds/source/li_backend_c3d.cpp → backends/3ds/source/bknd-gfx.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -1,4 +1,28 @@ | ||||
| #include <li_backend_c3d.hpp> | ||||
| /*
 | ||||
| MIT License | ||||
| 
 | ||||
| Copyright (c) 2024 - 2025 tobid7 | ||||
| 
 | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
| 
 | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
| 
 | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  */ | ||||
| 
 | ||||
| #include <pd-3ds/bknd-gfx.hpp> | ||||
| 
 | ||||
| /// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
 | ||||
| const char* LIShaderCTR = R"( | ||||
| @@ -44,8 +68,9 @@ unsigned char li_shader[] = { | ||||
|   }; | ||||
| // clang-format on
 | ||||
| size_t li_shader_size = 0x124; | ||||
| 
 | ||||
| namespace PD { | ||||
| namespace LI { | ||||
| namespace Li { | ||||
| GPU_TEXCOLOR GetTexFmt(Texture::Type type) { | ||||
|   if (type == Texture::RGBA32) | ||||
|     return GPU_RGBA8; | ||||
| @@ -64,51 +89,47 @@ int GetBPP(Texture::Type type) { | ||||
|     return 1; | ||||
|   return 0;  // Error
 | ||||
| } | ||||
| void Backend_C3D::Init() { | ||||
|   std::cout << "[BACKEND_C3D]: Setting up Buffers" << std::endl; | ||||
| 
 | ||||
| void GfxC3D::Init() { | ||||
|   VertexBuffer.Resize(4 * 8192); | ||||
|   IndexBuffer.Resize(6 * 8192); | ||||
| 
 | ||||
|   Flags |= LIBackendFlags_FlipUV_Y; | ||||
|   Flags |= LiBackendFlags_FlipUV_Y; | ||||
| 
 | ||||
|   std::cout << "[BACKEND_C3D]: Loading shader..." << std::endl; | ||||
|   ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size); | ||||
|   shaderProgramInit(&Shader); | ||||
|   shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]); | ||||
|   pLocProjection = | ||||
|       shaderInstanceGetUniformLocation(Shader.vertexShader, "projection"); | ||||
| 
 | ||||
|   std::cout << "[BACKEND_C3D]: Setting up Attr Info" << std::endl; | ||||
|   AttrInfo_Init(&ShaderInfo); | ||||
|   AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2); | ||||
|   AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2); | ||||
|   AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4); | ||||
|   std::cout << "[BACKEND_C3D]: Backend init done!" << std::endl; | ||||
| } | ||||
| 
 | ||||
| void Backend_C3D::Deinit() { | ||||
| void GfxC3D::Deinit() { | ||||
|   shaderProgramFree(&Shader); | ||||
|   DVLB_Free(ShaderCode); | ||||
| } | ||||
| 
 | ||||
| void Backend_C3D::NewFrame() { | ||||
| void GfxC3D::NewFrame() { | ||||
|   C3D_BindProgram(&Shader); | ||||
|   C3D_SetAttrInfo(&ShaderInfo); | ||||
|   CurrentIndex = 0; | ||||
|   CurrentVertex = 0; | ||||
|   FrameCounter++; | ||||
|   VertexCounter = num_vtx; | ||||
|   IndexCounter = num_idx; | ||||
|   num_vtx = 0; | ||||
|   num_idx = 0; | ||||
|   VertexCounter = NumVtx; | ||||
|   IndexCounter = NumIdx; | ||||
|   NumVtx = 0; | ||||
|   NumIdx = 0; | ||||
| } | ||||
| 
 | ||||
| void Backend_C3D::BindTexture(PD::LI::TexAddress addr) { | ||||
| void GfxC3D::BindTex(PD::Li::TexAddress addr) { | ||||
|   C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr)); | ||||
| } | ||||
| 
 | ||||
| void Backend_C3D::RenderDrawData( | ||||
|     const PD::Vec<PD::LI::Command::Ref>& Commands) { | ||||
| void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) { | ||||
|   C3D_BindProgram(&Shader); | ||||
|   C3D_SetAttrInfo(&ShaderInfo); | ||||
|   C3D_Mtx proj; | ||||
| @@ -120,26 +141,26 @@ void Backend_C3D::RenderDrawData( | ||||
|   C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0); | ||||
|   C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); | ||||
|   size_t index = 0; | ||||
|   while (index < Commands.Size()) { | ||||
|     PD::LI::Texture::Ref Tex = Commands[index]->Tex; | ||||
|   while (index < Commands.size()) { | ||||
|     PD::Li::Texture::Ref Tex = Commands[index]->Tex; | ||||
|     if (!Tex) { | ||||
|       index++; | ||||
|       continue; | ||||
|     } | ||||
|     bool ScissorEnabled = Commands[index]->ScissorEnabled; | ||||
|     bool ScissorEnabled = Commands[index]->ScissorOn; | ||||
|     ivec4 ScissorRect = Commands[index]->ScissorRect; | ||||
|     size_t StartIndex = CurrentIndex; | ||||
| 
 | ||||
|     while (index < Commands.Size() && Commands[index]->Tex == Tex && | ||||
|            Commands[index]->ScissorEnabled == ScissorEnabled && | ||||
|     while (index < Commands.size() && Commands[index]->Tex == Tex && | ||||
|            Commands[index]->ScissorOn == ScissorEnabled && | ||||
|            Commands[index]->ScissorRect == ScissorRect) { | ||||
|       auto c = Commands[index]; | ||||
|       auto c = Commands[index].get(); | ||||
|       for (size_t i = 0; i < c->IndexBuffer.Size(); i++) { | ||||
|         num_idx++; | ||||
|         NumIdx++; | ||||
|         IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i); | ||||
|       } | ||||
|       for (size_t i = 0; i < c->VertexBuffer.Size(); i++) { | ||||
|         num_vtx++; | ||||
|         NumVtx++; | ||||
|         VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i); | ||||
|       } | ||||
|       index++; | ||||
| @@ -153,7 +174,7 @@ void Backend_C3D::RenderDrawData( | ||||
|     } else { | ||||
|       C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0); | ||||
|     } | ||||
|     BindTexture(Tex->Address); | ||||
|     BindTex(Tex->Address); | ||||
|     auto bufInfo = C3D_GetBufInfo(); | ||||
|     BufInfo_Init(bufInfo); | ||||
|     BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Vertex), 3, 0x210); | ||||
| @@ -164,16 +185,14 @@ void Backend_C3D::RenderDrawData( | ||||
|   C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL); | ||||
| } | ||||
| 
 | ||||
| PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels, | ||||
|                                               int w, int h, | ||||
|                                               PD::LI::Texture::Type type, | ||||
|                                               PD::LI::Texture::Filter filter) { | ||||
|   std::cout << "Loading Tex " << std::format("[{}, {}]", w, h) << std::endl; | ||||
| PD::Li::Texture::Ref GfxC3D::LoadTex(const std::vector<PD::u8>& pixels, int w, | ||||
|                                      int h, PD::Li::Texture::Type type, | ||||
|                                      PD::Li::Texture::Filter filter) { | ||||
|   if (w > 1024 || h > 1024) { | ||||
|     return nullptr; | ||||
|   } | ||||
|   // Don't check here as check done before
 | ||||
|   PD::LI::Texture::Ref res = PD::LI::Texture::New(); | ||||
|   PD::Li::Texture::Ref res = PD::Li::Texture::New(); | ||||
|   int bpp = GetBPP(type); | ||||
|   ivec2 tex_size(w, h); | ||||
|   // Pow2
 | ||||
| @@ -227,5 +246,5 @@ PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels, | ||||
|             << std::endl; | ||||
|   return res; | ||||
| } | ||||
| }  // namespace LI
 | ||||
| }  // namespace PD
 | ||||
| }  // namespace Li
 | ||||
| }  // namespace PD
 | ||||
							
								
								
									
										85
									
								
								backends/3ds/source/bknd-hid.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										85
									
								
								backends/3ds/source/bknd-hid.cpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,85 @@ | ||||
| /* | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) 2024 - 2025 tobid7 | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| #include <3ds.h> | ||||
|  | ||||
| #include <pd-3ds/bknd-hid.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| Hid3DS::Hid3DS() : HidDriver("Hid3DS") { | ||||
|   pBinds[KEY_A] = A; | ||||
|   pBinds[KEY_B] = B; | ||||
|   pBinds[KEY_X] = X; | ||||
|   pBinds[KEY_Y] = Y; | ||||
|   pBinds[KEY_START] = Start; | ||||
|   pBinds[KEY_SELECT] = Select; | ||||
|   pBinds[KEY_L] = L; | ||||
|   pBinds[KEY_R] = R; | ||||
|   pBinds[KEY_DUP] = DUp; | ||||
|   pBinds[KEY_DDOWN] = DDown; | ||||
|   pBinds[KEY_DLEFT] = DLeft; | ||||
|   pBinds[KEY_DRIGHT] = DRight; | ||||
|   pBinds[KEY_CPAD_UP] = CPUp; | ||||
|   pBinds[KEY_CPAD_DOWN] = CPDown; | ||||
|   pBinds[KEY_CPAD_LEFT] = CPLeft; | ||||
|   pBinds[KEY_CPAD_RIGHT] = CPRight; | ||||
|   pBinds[KEY_CSTICK_UP] = CSUp; | ||||
|   pBinds[KEY_CSTICK_DOWN] = CSDown; | ||||
|   pBinds[KEY_CSTICK_LEFT] = CSLeft; | ||||
|   pBinds[KEY_CSTICK_RIGHT] = CSRight; | ||||
|   pBinds[KEY_ZL] = ZL; | ||||
|   pBinds[KEY_ZR] = ZR; | ||||
|   pBinds[KEY_TOUCH] = Touch; | ||||
| } | ||||
|  | ||||
| void Hid3DS::Update() { | ||||
|   hidScanInput(); | ||||
|   for (int i = 0; i < 2; i++) { | ||||
|     KeyEvents[i][Event_Down] = 0; | ||||
|     KeyEvents[i][Event_Held] = 0; | ||||
|     KeyEvents[i][Event_Up] = 0; | ||||
|   } | ||||
|   u32 kd = hidKeysDown(); | ||||
|   u32 kh = hidKeysHeld(); | ||||
|   u32 ku = hidKeysUp(); | ||||
|   for (auto &b : pBinds) { | ||||
|     if (b.first & kd) { | ||||
|       KeyEvents[0][Event_Down] |= b.second; | ||||
|     } | ||||
|     if (b.first & kh) { | ||||
|       KeyEvents[0][Event_Held] |= b.second; | ||||
|     } | ||||
|     if (b.first & ku) { | ||||
|       KeyEvents[0][Event_Up] |= b.second; | ||||
|     } | ||||
|   } | ||||
|   if (pLocked) { | ||||
|     SwapTab(); | ||||
|   } | ||||
|   touchPosition t; | ||||
|   hidTouchRead(&t); | ||||
|   pMouse[1] = pMouse[0];  // Cycle pMouse pos | ||||
|   pMouse[0] = fvec2(t.px, t.py); | ||||
| } | ||||
| }  // namespace PD | ||||
							
								
								
									
										36
									
								
								backends/3ds/source/pd-3ds.cpp
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										36
									
								
								backends/3ds/source/pd-3ds.cpp
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| /* | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) 2024 - 2025 tobid7 | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| #include <palladium> | ||||
| #include <pd-3ds.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| void Init(void* data) { | ||||
|   // Dekstop Init Stage | ||||
|   // First use default OS Driver | ||||
|   PD::OS::Init(); | ||||
|   PD::Li::Gfx::Init(PD::Li::GfxC3D::New()); | ||||
|   PD::Hid::Init(PD::Hid3DS::New()); | ||||
| } | ||||
| }  // namespace PD | ||||
| @@ -1,60 +0,0 @@ | ||||
| #include <3ds.h> | ||||
|  | ||||
| #include <pd_hid_3ds.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| Hid3DS::Hid3DS() : Hid("3DS") { | ||||
|   binds[KEY_A] = A; | ||||
|   binds[KEY_B] = B; | ||||
|   binds[KEY_X] = X; | ||||
|   binds[KEY_Y] = Y; | ||||
|   binds[KEY_START] = Start; | ||||
|   binds[KEY_SELECT] = Select; | ||||
|   binds[KEY_L] = L; | ||||
|   binds[KEY_R] = R; | ||||
|   binds[KEY_DUP] = DUp; | ||||
|   binds[KEY_DDOWN] = DDown; | ||||
|   binds[KEY_DLEFT] = DLeft; | ||||
|   binds[KEY_DRIGHT] = DRight; | ||||
|   binds[KEY_CPAD_UP] = CPUp; | ||||
|   binds[KEY_CPAD_DOWN] = CPDown; | ||||
|   binds[KEY_CPAD_LEFT] = CPLeft; | ||||
|   binds[KEY_CPAD_RIGHT] = CPRight; | ||||
|   binds[KEY_CSTICK_UP] = CSUp; | ||||
|   binds[KEY_CSTICK_DOWN] = CSDown; | ||||
|   binds[KEY_CSTICK_LEFT] = CSLeft; | ||||
|   binds[KEY_CSTICK_RIGHT] = CSRight; | ||||
|   binds[KEY_ZL] = ZL; | ||||
|   binds[KEY_ZR] = ZR; | ||||
|   binds[KEY_TOUCH] = Touch; | ||||
| } | ||||
| void Hid3DS::Update() { | ||||
|   hidScanInput(); | ||||
|   for (int i = 0; i < 2; i++) { | ||||
|     key_events[i][Event_Down] = 0; | ||||
|     key_events[i][Event_Held] = 0; | ||||
|     key_events[i][Event_Up] = 0; | ||||
|   } | ||||
|   u32 kd = hidKeysDown(); | ||||
|   u32 kh = hidKeysHeld(); | ||||
|   u32 ku = hidKeysUp(); | ||||
|   for (auto &b : binds) { | ||||
|     if (b.first & kd) { | ||||
|       key_events[0][Event_Down] |= b.second; | ||||
|     } | ||||
|     if (b.first & kh) { | ||||
|       key_events[0][Event_Held] |= b.second; | ||||
|     } | ||||
|     if (b.first & ku) { | ||||
|       key_events[0][Event_Up] |= b.second; | ||||
|     } | ||||
|   } | ||||
|   if (locked) { | ||||
|     SwappyTable(); | ||||
|   } | ||||
|   touchPosition t; | ||||
|   hidTouchRead(&t); | ||||
|   touch[1] = touch[0];  // Cycle touch pos | ||||
|   touch[0] = fvec2(t.px, t.py); | ||||
| } | ||||
| }  // namespace PD | ||||
		Reference in New Issue
	
	Block a user