0.7.0 rewrite dev
- remove everyting - keep core -rename bit_utils to bits - add formatter for color - add float getters to color - start with new drivers api
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-3ds LANGUAGES CXX VERSION 0.6.0)
|
||||
|
||||
set(SRC
|
||||
source/bknd-gfx.cpp
|
||||
source/bknd-hid.cpp
|
||||
source/pd-3ds.cpp
|
||||
)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libpicasso)
|
||||
add_library(pd-3ds STATIC ${SRC})
|
||||
target_include_directories(pd-3ds PUBLIC
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d pica::pica)
|
||||
add_library(palladium::pd-3ds ALIAS pd-3ds)
|
||||
install(TARGETS pd-3ds
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(DIRECTORY include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(TARGETS pica
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd-3ds/bknd-gfx.hpp>
|
||||
#include <pd-3ds/bknd-hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD::Li::Font::Ref LoadSystemFont(Context& ctx);
|
||||
void Init(void* data = nullptr);
|
||||
} // namespace PD
|
||||
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <citro3d.h>
|
||||
|
||||
#include <pd-3ds/linearAllocator.hpp>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
|
||||
namespace PD {
|
||||
class GfxC3D : public GfxDriver {
|
||||
public:
|
||||
GfxC3D(PDDriverData data = nullptr) : GfxDriver("Citro3D") {}
|
||||
~GfxC3D() = default;
|
||||
|
||||
PD_SHARED(GfxC3D);
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
void NewFrame() override;
|
||||
void BindTex(PD::Li::TexAddress addr) override;
|
||||
void RenderDrawData(const PD::Li::CmdPool& 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;
|
||||
void DestroyTex(PD::Li::Texture::Ref tex) override;
|
||||
|
||||
std::vector<Li::Vertex, LinearAllocator<Li::Vertex>> VertexBuffer;
|
||||
std::vector<u16, LinearAllocator<u16>> IndexBuffer;
|
||||
int pLocProjection = 0;
|
||||
DVLB_s* ShaderCode;
|
||||
shaderProgram_s Shader;
|
||||
C3D_AttrInfo ShaderInfo;
|
||||
std::vector<u8> pRawShader;
|
||||
u32 pCountVertices = 0;
|
||||
u32 pCountIndices = 0;
|
||||
u32 pCountDrawCalls = 0;
|
||||
u32 pDrawCommands = 0;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd/drivers/drivers.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Hid3DS : public HidDriver {
|
||||
public:
|
||||
Hid3DS(PDDriverData data = nullptr);
|
||||
~Hid3DS() = default;
|
||||
|
||||
PD_SHARED(Hid3DS);
|
||||
|
||||
void Update() override;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd/core/common.hpp>
|
||||
|
||||
// Custom C++ Allocator class to interface with libctru linear heap memory
|
||||
// based on this guide:
|
||||
// https://johnfarrier.com/custom-allocators-in-c-high-performance-memory-management/
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class LinearAllocator {
|
||||
public:
|
||||
using value_type = T;
|
||||
LinearAllocator() noexcept = default;
|
||||
template <typename U>
|
||||
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
|
||||
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > max_size()) {
|
||||
PD::Throw("[PD] LinearAllocator: Bad alloc!");
|
||||
}
|
||||
return static_cast<T*>(linearAlloc(n * sizeof(T)));
|
||||
}
|
||||
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
|
||||
|
||||
template <class U, class... Args>
|
||||
void construct(U* p, Args&&... args) {
|
||||
::new ((void*)p) U(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void destroy(U* p) {
|
||||
p->~U();
|
||||
}
|
||||
|
||||
friend bool operator==(const LinearAllocator, const LinearAllocator) {
|
||||
return true;
|
||||
}
|
||||
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use linearSpace free as max_size to not allocate out of bounds
|
||||
// or to b eable to see a crash report screen.
|
||||
size_t max_size() const noexcept { return linearSpaceFree(); }
|
||||
};
|
||||
} // namespace PD
|
||||
Submodule backends/3ds/libpicasso deleted from a6b1e8ddbd
@@ -1,281 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd-3ds/bknd-gfx.hpp>
|
||||
#include <pica.hpp>
|
||||
|
||||
const char* LIShaderCTR = R"(
|
||||
; LI7 Shader
|
||||
; Constants
|
||||
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
||||
.alias ones myconst.yyyy ; Vector full of ones
|
||||
|
||||
; Uniforms
|
||||
.fvec projection[4]
|
||||
|
||||
; Outputs
|
||||
.out out_position position
|
||||
.out out_color color
|
||||
.out out_uv texcoord0
|
||||
|
||||
; Inputs
|
||||
.alias in_xy v0
|
||||
.alias in_uvc v1
|
||||
.alias in_col v2
|
||||
|
||||
.entry vmain
|
||||
.proc vmain
|
||||
mov r0.xy, in_xy.xy
|
||||
mov r0.w, ones
|
||||
|
||||
dp4 out_position.x, projection[0], r0
|
||||
dp4 out_position.y, projection[1], r0
|
||||
dp4 out_position.z, projection[2], r0
|
||||
dp4 out_position.w, projection[3], r0
|
||||
|
||||
mov out_uv, in_uvc.xy
|
||||
|
||||
mul r1, myconst.zzzz, in_col
|
||||
mov out_color, r1
|
||||
end
|
||||
.end
|
||||
)";
|
||||
|
||||
namespace PD {
|
||||
GPU_TEXCOLOR GetTexFmt(Li::Texture::Type type) {
|
||||
if (type == Li::Texture::RGBA32)
|
||||
return GPU_RGBA8;
|
||||
else if (type == Li::Texture::RGB24)
|
||||
return GPU_RGB8;
|
||||
else if (type == Li::Texture::A8)
|
||||
return GPU_A8;
|
||||
return GPU_RGBA8; // Default
|
||||
}
|
||||
int GetBPP(Li::Texture::Type type) {
|
||||
if (type == Li::Texture::RGBA32)
|
||||
return 4;
|
||||
else if (type == Li::Texture::RGB24)
|
||||
return 3;
|
||||
else if (type == Li::Texture::A8)
|
||||
return 1;
|
||||
return 0; // Error
|
||||
}
|
||||
|
||||
void FragCfg(GPU_TEXCOLOR clr) {
|
||||
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvInit(env);
|
||||
switch (clr) {
|
||||
case GPU_A4:
|
||||
case GPU_A8:
|
||||
case GPU_L4:
|
||||
case GPU_L8:
|
||||
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
|
||||
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
|
||||
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
|
||||
break;
|
||||
case GPU_RGB565:
|
||||
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
|
||||
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
|
||||
C3D_TexEnvFunc(env, C3D_Alpha, GPU_REPLACE);
|
||||
break;
|
||||
|
||||
default:
|
||||
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
|
||||
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GfxC3D::Init() {
|
||||
VertexBuffer.resize(4 * 8192);
|
||||
IndexBuffer.resize(6 * 8192);
|
||||
|
||||
Flags |= LiBackendFlags_FlipUV_Y;
|
||||
|
||||
pRawShader = Pica::AssembleCode(LIShaderCTR);
|
||||
ShaderCode = DVLB_ParseFile((uint32_t*)&pRawShader[0], pRawShader.size());
|
||||
shaderProgramInit(&Shader);
|
||||
shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]);
|
||||
pLocProjection =
|
||||
shaderInstanceGetUniformLocation(Shader.vertexShader, "projection");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void GfxC3D::Deinit() {
|
||||
shaderProgramFree(&Shader);
|
||||
DVLB_Free(ShaderCode);
|
||||
}
|
||||
|
||||
void GfxC3D::NewFrame() {
|
||||
C3D_BindProgram(&Shader);
|
||||
C3D_SetAttrInfo(&ShaderInfo);
|
||||
CurrentIndex = 0;
|
||||
CurrentVertex = 0;
|
||||
FrameCounter++;
|
||||
/** Probably completly incorrect but just do it like that */
|
||||
VertexCounter = pCountVertices;
|
||||
IndexCounter = pCountIndices;
|
||||
DrawCalls = pCountDrawCalls;
|
||||
DrawCommands = pDrawCommands;
|
||||
pCountDrawCalls = 0;
|
||||
pCountIndices = 0;
|
||||
pCountVertices = 0;
|
||||
pDrawCommands = 0;
|
||||
}
|
||||
|
||||
void GfxC3D::BindTex(PD::Li::TexAddress addr) {
|
||||
C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr));
|
||||
}
|
||||
|
||||
void GfxC3D::RenderDrawData(const PD::Li::CmdPool& Commands) {
|
||||
pDrawCommands += Commands.Size();
|
||||
shaderProgramUse(&Shader);
|
||||
C3D_SetAttrInfo(&ShaderInfo);
|
||||
C3D_Mtx proj;
|
||||
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
|
||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &proj);
|
||||
// Mat4 proj = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
|
||||
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, (C3D_Mtx*)&proj);
|
||||
size_t index = 0;
|
||||
while (index < Commands.Size()) {
|
||||
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
|
||||
if (!Tex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
bool ScissorEnabled = Commands.GetCmd(index)->ScissorOn;
|
||||
ivec4 ScissorRect = Commands.GetCmd(index)->ScissorRect;
|
||||
size_t StartIndex = CurrentIndex;
|
||||
|
||||
while (index < Commands.Size() && Commands.GetCmd(index)->Tex == Tex &&
|
||||
Commands.GetCmd(index)->ScissorOn == ScissorEnabled &&
|
||||
Commands.GetCmd(index)->ScissorRect == ScissorRect) {
|
||||
auto c = Commands.GetCmd(index);
|
||||
pCountIndices += c->IndexBuffer.size();
|
||||
pCountVertices += c->VertexBuffer.size();
|
||||
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
|
||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
|
||||
}
|
||||
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
|
||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (ScissorEnabled) {
|
||||
// Figure out this setup was pain
|
||||
C3D_SetScissor(GPU_SCISSOR_NORMAL,
|
||||
std::clamp(ViewPort.y - (ScissorRect.y + ScissorRect.w), 0,
|
||||
ViewPort.y),
|
||||
std::clamp(ViewPort.x - (ScissorRect.x + ScissorRect.z), 0,
|
||||
ViewPort.x),
|
||||
ViewPort.y - ScissorRect.y, ViewPort.x - ScissorRect.x);
|
||||
} else {
|
||||
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
|
||||
}
|
||||
FragCfg(((C3D_Tex*)Tex)->fmt);
|
||||
BindTex(Tex);
|
||||
auto bufInfo = C3D_GetBufInfo();
|
||||
BufInfo_Init(bufInfo);
|
||||
BufInfo_Add(bufInfo, VertexBuffer.data(), sizeof(Li::Vertex), 3, 0x210);
|
||||
|
||||
C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex,
|
||||
C3D_UNSIGNED_SHORT, IndexBuffer.data() + StartIndex);
|
||||
pCountDrawCalls++;
|
||||
}
|
||||
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
|
||||
}
|
||||
|
||||
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();
|
||||
int bpp = GetBPP(type);
|
||||
ivec2 tex_size(w, h);
|
||||
// Pow2
|
||||
if (!PD::BitUtil::IsSingleBit(w)) {
|
||||
tex_size.x = PD::BitUtil::GetPow2((unsigned int)w);
|
||||
}
|
||||
if (!PD::BitUtil::IsSingleBit(h)) {
|
||||
tex_size.y = PD::BitUtil::GetPow2((unsigned int)h);
|
||||
}
|
||||
res->Size.x = w;
|
||||
res->Size.y = h;
|
||||
res->UV = fvec4(0.f, 1.f, ((float)w / (float)tex_size.x),
|
||||
1.0 - ((float)h / (float)tex_size.y));
|
||||
|
||||
// Texture Setup
|
||||
auto fltr = (filter == Li::Texture::NEAREST ? GPU_NEAREST : GPU_LINEAR);
|
||||
auto tex_fmt = GetTexFmt(type);
|
||||
auto tex = new C3D_Tex;
|
||||
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
|
||||
C3D_TexSetFilter(tex, fltr, fltr);
|
||||
|
||||
// Using std::fill_n instead cause i hate this error lines
|
||||
// under the memset func in my editor
|
||||
std::fill_n((PD::u8*)tex->data, tex->size, 0);
|
||||
// memset(tex->data, 0, tex->size);s
|
||||
|
||||
/// Probably Remove this if statement in future
|
||||
/// This are the things confirmed as working
|
||||
if (bpp == 3 || bpp == 4 || bpp == 1) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
|
||||
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||
bpp;
|
||||
int src_pos = (y * w + x) * bpp;
|
||||
/// Best idea i had
|
||||
for (int i = 0; i < bpp; i++) {
|
||||
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
C3D_TexFlush(tex);
|
||||
}
|
||||
|
||||
tex->border = 0x00000000;
|
||||
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
|
||||
res->Address = (Li::TexAddress)tex;
|
||||
std::cout << std::format("Tex {:#08x} Addr {:#08X}",
|
||||
(Li::TexAddress)res.get(), res->Address)
|
||||
<< std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
void GfxC3D::DestroyTex(PD::Li::Texture::Ref tex) {
|
||||
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex->Address);
|
||||
C3D_TexDelete(t);
|
||||
delete t;
|
||||
tex->Address = 0;
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd-3ds/bknd-hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
Hid3DS::Hid3DS(PDDriverData data) : HidDriver("Hid3DS") {
|
||||
this->Flags |= Flags_HasTouch;
|
||||
this->Flags |= FLags_HasGamepad;
|
||||
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
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <palladium>
|
||||
#include <pd-3ds.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD::Li::Font::Ref LoadSystemFont(Context& ctx) {
|
||||
TT::Scope st(*ctx.Os(), "LI_SystemFont"); // Trace loading time
|
||||
Li::Font::Ref ret = Li::Font::New(ctx);
|
||||
fontEnsureMapped(); // Call this to be sure the font is mapped
|
||||
// Get some const references for system font loading
|
||||
const auto fnt = fontGetSystemFont();
|
||||
const auto fnt_info = fontGetInfo(fnt);
|
||||
const auto glyph_info = fontGetGlyphInfo(fnt);
|
||||
// Resize the Texture list by the num of sysfont textures
|
||||
ret->Textures.resize(glyph_info->nSheets + 1);
|
||||
/// Modify the Pixel Height by 1.1f to fit the
|
||||
/// Size og ttf font Rendering
|
||||
ret->PixelHeight = glyph_info->cellHeight;
|
||||
// Load the Textures and make sure they don't auto unload
|
||||
for (size_t i = 0; i < glyph_info->nSheets; i++) {
|
||||
auto stex = Li::Texture::New();
|
||||
auto tx = new C3D_Tex;
|
||||
tx->data = fontGetGlyphSheetTex(fnt, i);
|
||||
tx->fmt = (GPU_TEXCOLOR)glyph_info->sheetFmt;
|
||||
tx->size = glyph_info->sheetSize;
|
||||
tx->width = glyph_info->sheetWidth;
|
||||
tx->height = glyph_info->sheetHeight;
|
||||
tx->param = GPU_TEXTURE_MAG_FILTER(GPU_LINEAR) |
|
||||
GPU_TEXTURE_MIN_FILTER(GPU_LINEAR) |
|
||||
GPU_TEXTURE_WRAP_S(GPU_REPEAT) | GPU_TEXTURE_WRAP_T(GPU_REPEAT);
|
||||
tx->border = 0xffffffff;
|
||||
tx->lodParam = 0;
|
||||
stex->Address = (Li::TexAddress)tx;
|
||||
stex->Size = fvec2(tx->width, tx->height);
|
||||
stex->UV = fvec4(0, 1, 1, 0);
|
||||
ret->Textures[i] = stex;
|
||||
}
|
||||
std::vector<unsigned int> charSet;
|
||||
// Write the Charset into a vector
|
||||
for (auto cmap = fnt_info->cmap; cmap; cmap = cmap->next) {
|
||||
if (cmap->mappingMethod == CMAP_TYPE_DIRECT) {
|
||||
if (cmap->codeEnd >= cmap->codeBegin) {
|
||||
charSet.reserve(charSet.size() + cmap->codeEnd - cmap->codeBegin + 1);
|
||||
for (auto i = cmap->codeBegin; i <= cmap->codeEnd; ++i) {
|
||||
if (cmap->indexOffset + (i - cmap->codeBegin) == 0xFFFF) break;
|
||||
charSet.emplace_back(i);
|
||||
}
|
||||
}
|
||||
} else if (cmap->mappingMethod == CMAP_TYPE_TABLE) {
|
||||
if (cmap->codeEnd >= cmap->codeBegin) {
|
||||
charSet.reserve(charSet.size() + cmap->codeEnd - cmap->codeBegin + 1);
|
||||
for (auto i = cmap->codeBegin; i <= cmap->codeEnd; ++i) {
|
||||
if (cmap->indexTable[i - cmap->codeBegin] == 0xFFFF) continue;
|
||||
charSet.emplace_back(i);
|
||||
}
|
||||
}
|
||||
} else if (cmap->mappingMethod == CMAP_TYPE_SCAN) {
|
||||
charSet.reserve(charSet.size() + cmap->nScanEntries);
|
||||
for (unsigned i = 0; i < cmap->nScanEntries; ++i) {
|
||||
if (cmap->scanEntries[i].code >= cmap->codeBegin &&
|
||||
cmap->scanEntries[i].code <= cmap->codeEnd) {
|
||||
if (cmap->scanEntries[i].glyphIndex != 0xFFFF) {
|
||||
charSet.emplace_back(cmap->scanEntries[i].code);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the charset and make sure all values are unique
|
||||
std::sort(charSet.begin(), charSet.end());
|
||||
charSet.erase(std::unique(charSet.begin(), charSet.end()));
|
||||
|
||||
// Setup the Codepoint map by the charset
|
||||
for (auto cp : charSet) {
|
||||
int gidx = fontGlyphIndexFromCodePoint(fnt, cp);
|
||||
if (gidx >= 0xFFFF) continue;
|
||||
Li::Font::Codepoint codepoint;
|
||||
fontGlyphPos_s dat;
|
||||
fontCalcGlyphPos(&dat, fnt, gidx, GLYPH_POS_CALC_VTXCOORD, 1.f, 1.f);
|
||||
|
||||
codepoint.pCodepoint = cp;
|
||||
codepoint.SimpleUV = fvec4(dat.texcoord.left, dat.texcoord.top,
|
||||
dat.texcoord.right, dat.texcoord.bottom);
|
||||
|
||||
if (dat.sheetIndex < (int)ret->Textures.size()) {
|
||||
codepoint.Tex = ret->Textures[dat.sheetIndex];
|
||||
} else {
|
||||
codepoint.pInvalid = true;
|
||||
}
|
||||
codepoint.Size = fvec2(dat.vtxcoord.right, dat.vtxcoord.bottom);
|
||||
codepoint.Offset = 0;
|
||||
ret->CodeMap[cp] = codepoint;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Init(void* data) {
|
||||
// Dekstop Init Stage
|
||||
// First use default OS Driver
|
||||
// PD::OS::Init();
|
||||
// PD::Gfx::Init(PD::GfxC3D::New());
|
||||
// PD::Hid::Init(PD::Hid3DS::New());
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -1,62 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-desktop LANGUAGES CXX VERSION 0.5.0)
|
||||
|
||||
set(PD_GL_VERSION 21 CACHE STRING "OpenGL Version (2.1 -> 21, 3.3 -> 33)")
|
||||
|
||||
if(APPLE)
|
||||
set(PD_GL_VERSION 33 CACHE STRING "33" FORCE)
|
||||
endif()
|
||||
|
||||
message("Using OpenGL: " ${PD_GL_VERSION})
|
||||
|
||||
add_subdirectory(glad)
|
||||
add_subdirectory(glfw)
|
||||
|
||||
set(SRC
|
||||
source/bknd-gfx.cpp
|
||||
source/bknd-hid.cpp
|
||||
source/pd-desktop.cpp
|
||||
)
|
||||
|
||||
add_library(pd-desktop STATIC ${SRC})
|
||||
target_include_directories(pd-desktop
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(pd-desktop PUBLIC palladium glad glfw)
|
||||
|
||||
target_compile_definitions(pd-desktop
|
||||
PRIVATE PD_OPENGL=${PD_GL_VERSION}
|
||||
)
|
||||
|
||||
add_library(palladium::pd-desktop ALIAS pd-desktop)
|
||||
|
||||
install(TARGETS pd-desktop
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(DIRECTORY include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(TARGETS glad
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
if(PD_BUNDLE_GLFW)
|
||||
install(TARGETS glfw
|
||||
EXPORT palladiumTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
endif()
|
||||
@@ -1,8 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
add_library(glad source/glad.c)
|
||||
target_include_directories(glad
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
@@ -1,311 +0,0 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are 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 Materials.
|
||||
**
|
||||
** THE MATERIALS ARE 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
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with
|
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||
* unsigned long long or similar (this results in different C++ name mangling).
|
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||
* platforms where the size of a pointer is larger than the size of long.
|
||||
*/
|
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||
#define KHRONOS_USE_INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef KHRONOS_USE_INTPTR_T
|
||||
typedef intptr_t khronos_intptr_t;
|
||||
typedef uintptr_t khronos_uintptr_t;
|
||||
#elif defined(_WIN64)
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Submodule backends/desktop/glfw deleted from e7ea71be03
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd-desktop/bknd-gfx.hpp>
|
||||
#include <pd-desktop/bknd-hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
void Init(void* data = nullptr);
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <glad/glad.h>
|
||||
|
||||
/** SEPARATOR */
|
||||
#include <GLFW/glfw3.h>
|
||||
/** SEPARATOR */
|
||||
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
|
||||
namespace PD {
|
||||
class GfxGL2 : public GfxDriver {
|
||||
public:
|
||||
GfxGL2(PDDriverData data = nullptr) : GfxDriver("OpenGL2") {}
|
||||
~GfxGL2() = default;
|
||||
|
||||
PD_SHARED(GfxGL2);
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
void NewFrame() override;
|
||||
void BindTex(PD::Li::TexAddress addr) override;
|
||||
void RenderDrawData(const Li::CmdPool& 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;
|
||||
|
||||
std::vector<Li::Vertex> VertexBuffer;
|
||||
std::vector<PD::u16> IndexBuffer;
|
||||
GLuint Shader;
|
||||
GLuint pLocProjection;
|
||||
GLuint pLocTex;
|
||||
GLuint pLocAlfa;
|
||||
GLuint VBO, IBO, VAO; // vao is only used in > 3.3
|
||||
};
|
||||
|
||||
class GfxGL3 : public GfxDriver2 {
|
||||
public:
|
||||
GfxGL3() : GfxDriver2("OpenGL3") {}
|
||||
~GfxGL3() = default;
|
||||
|
||||
PD_SHARED(GfxGL3);
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
// void NewFrame() override;
|
||||
void TexBind(PD::Li::TexAddress addr) override;
|
||||
void Draw(const Li::CmdPool& pool) override;
|
||||
PD::Li::TexAddress TexLoad(
|
||||
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;
|
||||
void TexDelete(PD::Li::TexAddress tex) override;
|
||||
|
||||
std::vector<Li::Vertex> VertexBuffer;
|
||||
std::vector<PD::u16> IndexBuffer;
|
||||
GLuint Shader;
|
||||
GLuint pLocProjection;
|
||||
GLuint pLocTex;
|
||||
GLuint pLocAlfa;
|
||||
GLuint VBO, IBO, VAO; // vao is only used in > 3.3
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <GLFW/glfw3.h>
|
||||
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
|
||||
namespace PD {
|
||||
class HidGLFW : public HidDriver {
|
||||
public:
|
||||
HidGLFW(PDDriverData data);
|
||||
~HidGLFW() = default;
|
||||
|
||||
PD_SHARED(HidGLFW);
|
||||
|
||||
void Update() override;
|
||||
void GetInputStr(std::string& str) override;
|
||||
void HandleTextOps();
|
||||
bool pTimedHeld(KbKey k) {
|
||||
if (pTimings.count(k)) {
|
||||
if (IsEvent(Event_Up, k)) {
|
||||
pTimings.erase(k);
|
||||
return false;
|
||||
}
|
||||
return 0; //(PD::OS::GetTime() - pTimings[k]) > 50;
|
||||
}
|
||||
if (!IsEvent(Event_Held, k)) {
|
||||
if (pTimings.count(k)) {
|
||||
pTimings.erase(k);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (IsEvent(Event_Held, k)) {
|
||||
pTimings[k] = 0; // PD::OS::GetTime();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Data section */
|
||||
GLFWwindow* Window;
|
||||
int PrevState;
|
||||
std::unordered_map<int, int> PrevStates;
|
||||
static GLFWcharfun pOldTextCB;
|
||||
static std::string* pText;
|
||||
bool pInTextMode = false;
|
||||
PD::u64 pLastUpdate = 0;
|
||||
std::unordered_map<KbKey, u64> pTimings;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,502 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd-desktop/bknd-gfx.hpp>
|
||||
|
||||
namespace PD {
|
||||
#if PD_OPENGL >= 21 && PD_OPENGL < 33
|
||||
const char* vertex_shader = R"(
|
||||
#version 120
|
||||
|
||||
attribute vec2 pos;
|
||||
attribute vec2 uv;
|
||||
attribute vec4 color;
|
||||
|
||||
varying vec2 oUV;
|
||||
varying vec4 oColor;
|
||||
|
||||
// Probably forgot about this matrix and
|
||||
// searched hours for why the rendering isn't working :/
|
||||
uniform mat4 projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection*vec4(pos, 0.0, 1.0);
|
||||
oUV = uv;
|
||||
oColor = color;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* frag_shader = R"(
|
||||
#version 120
|
||||
|
||||
varying vec2 oUV;
|
||||
varying vec4 oColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform bool alfa;
|
||||
|
||||
void main() {
|
||||
vec4 tc = texture2D(tex, oUV);
|
||||
if (alfa) {
|
||||
gl_FragColor = vec4(oColor.rgb, tc.a * oColor.a);
|
||||
} else {
|
||||
gl_FragColor = tc * oColor;
|
||||
}
|
||||
}
|
||||
)";
|
||||
#elif PD_OPENGL >= 33
|
||||
const char* vertex_shader = R"(
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec2 pos;
|
||||
layout(location = 1) in vec2 uv;
|
||||
layout(location = 2) in vec4 color;
|
||||
|
||||
out vec2 oUV;
|
||||
out vec4 oColor;
|
||||
|
||||
// Probably forgot about this matrix and
|
||||
// searched hours for why the rendering isn't working :/
|
||||
uniform mat4 projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection*vec4(pos, 0.0, 1.0);
|
||||
oUV = uv;
|
||||
oColor = color;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* frag_shader = R"(
|
||||
#version 330 core
|
||||
|
||||
in vec2 oUV;
|
||||
in vec4 oColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform bool alfa;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main() {
|
||||
vec4 tc = texture(tex, oUV);
|
||||
if (alfa) {
|
||||
FragColor = vec4(oColor.rgb, tc.a * oColor.a);
|
||||
} else {
|
||||
FragColor = tc * oColor;
|
||||
}
|
||||
}
|
||||
)";
|
||||
#else
|
||||
// Need to show error
|
||||
#endif
|
||||
|
||||
GLuint compileShader(const std::string& source, GLenum type) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
const char* src = source.c_str();
|
||||
glShaderSource(shader, 1, &src, nullptr);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
char infoLog[512];
|
||||
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
||||
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint createShaderProgram(const std::string& vertexShaderSource,
|
||||
const std::string& fragmentShaderSource) {
|
||||
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||
GLuint fragmentShader =
|
||||
compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||
|
||||
GLuint shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
glAttachShader(shaderProgram, fragmentShader);
|
||||
glLinkProgram(shaderProgram);
|
||||
|
||||
GLint success;
|
||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
char infoLog[512];
|
||||
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
|
||||
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
|
||||
}
|
||||
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
return shaderProgram;
|
||||
}
|
||||
|
||||
void SetupShaderAttribs(GLuint Shader) {
|
||||
GLint _pos = glGetAttribLocation(Shader, "pos");
|
||||
GLint _uv = glGetAttribLocation(Shader, "uv");
|
||||
GLint _color = glGetAttribLocation(Shader, "color");
|
||||
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Pos));
|
||||
glEnableVertexAttribArray(_pos);
|
||||
|
||||
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, UV));
|
||||
glEnableVertexAttribArray(_uv);
|
||||
|
||||
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||
sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Color));
|
||||
glEnableVertexAttribArray(_color);
|
||||
}
|
||||
|
||||
/** Actual Backend */
|
||||
|
||||
void GfxGL2::Init() {
|
||||
VertexBuffer.resize(4 * 8192);
|
||||
IndexBuffer.resize(6 * 8192);
|
||||
Shader = createShaderProgram(vertex_shader, frag_shader);
|
||||
glUseProgram(Shader);
|
||||
|
||||
#if PD_OPENGL >= 33
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
#endif
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
|
||||
#if PD_OPENGL < 33
|
||||
SetupShaderAttribs(Shader); // GL 2.1
|
||||
#else
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Pos));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, UV));
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Color));
|
||||
#endif
|
||||
glGenBuffers(1, &IBO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
pLocTex = glGetUniformLocation(Shader, "tex");
|
||||
pLocAlfa = glGetUniformLocation(Shader, "alfa");
|
||||
pLocProjection = glGetUniformLocation(Shader, "projection");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
#if PD_OPENGL >= 33
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GfxGL2::Deinit() {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &IBO);
|
||||
#if PD_OPENGL >= 33
|
||||
glDeleteBuffers(1, &VAO);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GfxGL2::NewFrame() {
|
||||
/*
|
||||
glViewport(0, 0, ViewPort.x, ViewPort.y);
|
||||
glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
*/
|
||||
Projection = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, -1.f, 1.f);
|
||||
glUseProgram(Shader);
|
||||
glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data());
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
FrameCounter++;
|
||||
VertexCounter = CurrentVertex;
|
||||
IndexCounter = CurrentIndex;
|
||||
CurrentVertex = 0;
|
||||
CurrentIndex = 0;
|
||||
}
|
||||
|
||||
void GfxGL2::BindTex(PD::Li::TexAddress addr) {
|
||||
// Actually not using the Address as Address
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
|
||||
glUniform1i(pLocTex, 0);
|
||||
GLint fmt = 0;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
||||
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
|
||||
}
|
||||
|
||||
void GfxGL2::RenderDrawData(const Li::CmdPool& Commands) {
|
||||
size_t index = 0;
|
||||
while (index < Commands.Size()) {
|
||||
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
|
||||
if (!Tex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
size_t StartIndex = CurrentIndex;
|
||||
bool ScissorOn = Commands.GetCmd(index)->ScissorOn;
|
||||
ivec4 ScissorRect = Commands.GetCmd(index)->ScissorRect;
|
||||
|
||||
while (index < Commands.Size() && Commands.GetCmd(index)->Tex == Tex &&
|
||||
Commands.GetCmd(index)->ScissorOn == ScissorOn &&
|
||||
Commands.GetCmd(index)->ScissorRect == ScissorRect) {
|
||||
auto c = Commands.GetCmd(index);
|
||||
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
|
||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
|
||||
}
|
||||
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
|
||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (ScissorOn) {
|
||||
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||
ScissorRect.z, ScissorRect.w);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
BindTex(Tex);
|
||||
|
||||
#if PD_OPENGL >= 33
|
||||
glBindVertexArray(VAO);
|
||||
#endif
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
||||
&VertexBuffer[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
#if PD_OPENGL < 33
|
||||
// For some reason we need to set these every frame for every buffer
|
||||
// Found that out when creating My 3d Engine
|
||||
SetupShaderAttribs(Shader);
|
||||
#endif
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
|
||||
&IndexBuffer[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, CurrentIndex - StartIndex, GL_UNSIGNED_SHORT,
|
||||
(void*)(StartIndex * sizeof(PD::u16)));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
BindTex(0);
|
||||
#if PD_OPENGL >= 33
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, PD::Li::Texture::Type type,
|
||||
PD::Li::Texture::Filter filter) {
|
||||
GLuint texID;
|
||||
glGenTextures(1, &texID);
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
|
||||
// Set base format (Always using RGBA as base)
|
||||
GLenum fmt = GL_RGBA;
|
||||
if (type == PD::Li::Texture::Type::RGB24) {
|
||||
fmt = GL_RGB;
|
||||
} else if (type == PD::Li::Texture::Type::A8) {
|
||||
fmt = GL_ALPHA;
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||
pixels.data());
|
||||
if (filter == PD::Li::Texture::Filter::LINEAR) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
|
||||
std::cout << std::format("Texture loaded: {} {}", texID, PD::ivec2(w, h))
|
||||
<< std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
void GfxGL3::Init() {
|
||||
VertexBuffer.resize(4 * 8192);
|
||||
IndexBuffer.resize(6 * 8192);
|
||||
Shader = createShaderProgram(vertex_shader, frag_shader);
|
||||
glUseProgram(Shader);
|
||||
|
||||
#if PD_OPENGL >= 33
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
#endif
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
|
||||
#if PD_OPENGL < 33
|
||||
SetupShaderAttribs(Shader); // GL 2.1
|
||||
#else
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Pos));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, UV));
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Color));
|
||||
#endif
|
||||
glGenBuffers(1, &IBO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
pLocTex = glGetUniformLocation(Shader, "tex");
|
||||
pLocAlfa = glGetUniformLocation(Shader, "alfa");
|
||||
pLocProjection = glGetUniformLocation(Shader, "projection");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
#if PD_OPENGL >= 33
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GfxGL3::Deinit() {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &IBO);
|
||||
#if PD_OPENGL >= 33
|
||||
glDeleteBuffers(1, &VAO);
|
||||
#endif
|
||||
}
|
||||
|
||||
// void NewFrame() {
|
||||
//}
|
||||
|
||||
void GfxGL3::TexBind(PD::Li::TexAddress addr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
|
||||
glUniform1i(pLocTex, 0);
|
||||
GLint fmt = 0;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
||||
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
|
||||
}
|
||||
|
||||
void GfxGL3::Draw(const Li::CmdPool& pool) {
|
||||
size_t index = 0;
|
||||
while (index < pool.Size()) {
|
||||
PD::Li::TexAddress Tex = pool.GetCmd(index)->Tex;
|
||||
if (Tex == 0) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
size_t StartIndex = CurrentIndex;
|
||||
bool ScissorOn = pool.GetCmd(index)->ScissorOn;
|
||||
ivec4 ScissorRect = pool.GetCmd(index)->ScissorRect;
|
||||
|
||||
while (index < pool.Size() && pool.GetCmd(index)->Tex == Tex &&
|
||||
pool.GetCmd(index)->ScissorOn == ScissorOn &&
|
||||
pool.GetCmd(index)->ScissorRect == ScissorRect) {
|
||||
auto c = pool.GetCmd(index);
|
||||
for (size_t i = 0; i < c->IndexBuffer.size(); i++) {
|
||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.at(i);
|
||||
}
|
||||
for (size_t i = 0; i < c->VertexBuffer.size(); i++) {
|
||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.at(i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (ScissorOn) {
|
||||
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||
ScissorRect.z, ScissorRect.w);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
TexBind(Tex);
|
||||
|
||||
#if PD_OPENGL >= 33
|
||||
glBindVertexArray(VAO);
|
||||
#endif
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
||||
&VertexBuffer[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
#if PD_OPENGL < 33
|
||||
// For some reason we need to set these every frame for every buffer
|
||||
// Found that out when creating My 3d Engine
|
||||
SetupShaderAttribs(Shader);
|
||||
#endif
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
|
||||
&IndexBuffer[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, CurrentIndex - StartIndex, GL_UNSIGNED_SHORT,
|
||||
(void*)(StartIndex * sizeof(PD::u16)));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
TexBind(0);
|
||||
#if PD_OPENGL >= 33
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
PD::Li::TexAddress GfxGL3::TexLoad(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, PD::Li::Texture::Type type,
|
||||
PD::Li::Texture::Filter filter) {
|
||||
GLuint texID;
|
||||
glGenTextures(1, &texID);
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
|
||||
// Set base format (Always using RGBA as base)
|
||||
GLenum fmt = GL_RGBA;
|
||||
if (type == PD::Li::Texture::Type::RGB24) {
|
||||
fmt = GL_RGB;
|
||||
} else if (type == PD::Li::Texture::Type::A8) {
|
||||
fmt = GL_ALPHA;
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||
pixels.data());
|
||||
if (filter == PD::Li::Texture::Filter::LINEAR) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return texID;
|
||||
}
|
||||
|
||||
void GfxGL3::TexDelete(PD::Li::TexAddress tex) {
|
||||
GLuint tex_ = tex;
|
||||
glDeleteTextures(1, &tex_);
|
||||
}
|
||||
|
||||
} // namespace PD
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <pd-desktop/bknd-hid.hpp>
|
||||
namespace PD {
|
||||
std::string* HidGLFW::pText = nullptr;
|
||||
GLFWcharfun HidGLFW::pOldTextCB = nullptr;
|
||||
// Default Call back (If no Text input is requsted)
|
||||
void NullTextCB(GLFWwindow* win, unsigned int c) {
|
||||
// Chain
|
||||
if (HidGLFW::pOldTextCB) {
|
||||
HidGLFW::pOldTextCB(win, c);
|
||||
}
|
||||
}
|
||||
// Text callback if requested
|
||||
void TextCB(GLFWwindow* win, unsigned int c) {
|
||||
// Chain
|
||||
if (HidGLFW::pOldTextCB) {
|
||||
HidGLFW::pOldTextCB(win, c);
|
||||
}
|
||||
if (!HidGLFW::pText) {
|
||||
return;
|
||||
}
|
||||
*HidGLFW::pText += (char)c;
|
||||
}
|
||||
HidGLFW::HidGLFW(PDDriverData data) : HidDriver("HidGLFW") {
|
||||
if (!data) {
|
||||
std::cout << "[HidGLFW] Error: Data pointer was null" << std::endl;
|
||||
}
|
||||
Window = reinterpret_cast<GLFWwindow*>(data);
|
||||
HidGLFW::pOldTextCB = glfwSetCharCallback(Window, NullTextCB);
|
||||
Flags |= Flags_HasKeyboard;
|
||||
Flags |= Flags_HasMouse;
|
||||
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
|
||||
/*pBinds[GLFW_KEY_F3] = Kb_3;
|
||||
pBinds[GLFW_KEY_ESCAPE] = Kb_Escape;
|
||||
pBinds[GLFW_KEY_F11] = Kb_F11;
|
||||
pBinds[GLFW_KEY_ESCAPE] = Kb_Escape;
|
||||
pBinds[GLFW_KEY_Q] = Kb_Q;
|
||||
pBinds[GLFW_KEY_W] = Kb_W;
|
||||
pBinds[GLFW_KEY_E] = Kb_E;
|
||||
pBinds[GLFW_KEY_R] = Kb_R;
|
||||
pBinds[GLFW_KEY_T] = Kb_T;
|
||||
pBinds[GLFW_KEY_Z] = Kb_Z;
|
||||
pBinds[GLFW_KEY_U] = Kb_U;
|
||||
pBinds[GLFW_KEY_I] = Kb_I;
|
||||
pBinds[GLFW_KEY_O] = Kb_O;
|
||||
pBinds[GLFW_KEY_P] = Kb_P;
|
||||
pBinds[GLFW_KEY_A] = Kb_A;
|
||||
pBinds[GLFW_KEY_S] = Kb_S;
|
||||
pBinds[GLFW_KEY_D] = Kb_D;
|
||||
pBinds[GLFW_KEY_F] = Kb_F;
|
||||
pBinds[GLFW_KEY_G] = Kb_G;
|
||||
pBinds[GLFW_KEY_H] = Kb_H;
|
||||
pBinds[GLFW_KEY_J] = Kb_J;
|
||||
pBinds[GLFW_KEY_K] = Kb_K;
|
||||
pBinds[GLFW_KEY_L] = Kb_L;
|
||||
pBinds[GLFW_KEY_Y] = Kb_Y;
|
||||
pBinds[GLFW_KEY_X] = Kb_X;
|
||||
pBinds[GLFW_KEY_C] = Kb_C;
|
||||
pBinds[GLFW_KEY_V] = Kb_V;
|
||||
pBinds[GLFW_KEY_B] = Kb_B;
|
||||
pBinds[GLFW_KEY_N] = Kb_N;
|
||||
pBinds[GLFW_KEY_M] = Kb_M;
|
||||
pBinds[GLFW_KEY_LEFT_SHIFT] = Kb_LShift;
|
||||
pBinds[GLFW_KEY_F1] = Kb_F1;
|
||||
pBinds[GLFW_KEY_F2] = Kb_F2;
|
||||
pBinds[GLFW_KEY_F3] = Kb_F3;
|
||||
pBinds[GLFW_KEY_F4] = Kb_F4;
|
||||
pBinds[GLFW_KEY_F5] = Kb_F5;
|
||||
pBinds[GLFW_KEY_F6] = Kb_F6;
|
||||
pBinds[GLFW_KEY_F7] = Kb_F7;
|
||||
pBinds[GLFW_KEY_F8] = Kb_F8;
|
||||
pBinds[GLFW_KEY_F9] = Kb_F9;
|
||||
pBinds[GLFW_KEY_F10] = Kb_F10;
|
||||
pBinds[GLFW_KEY_F11] = Kb_F11;
|
||||
pBinds[GLFW_KEY_F12] = Kb_F12;
|
||||
pBinds[GLFW_KEY_1] = Kb_1;
|
||||
pBinds[GLFW_KEY_2] = Kb_2;
|
||||
pBinds[GLFW_KEY_3] = Kb_3;
|
||||
pBinds[GLFW_KEY_4] = Kb_4;
|
||||
pBinds[GLFW_KEY_5] = Kb_5;
|
||||
pBinds[GLFW_KEY_6] = Kb_6;
|
||||
pBinds[GLFW_KEY_7] = Kb_7;
|
||||
pBinds[GLFW_KEY_8] = Kb_8;
|
||||
pBinds[GLFW_KEY_9] = Kb_9;
|
||||
pBinds[GLFW_KEY_0] = Kb_0;
|
||||
pBinds[GLFW_KEY_BACKSPACE] = Kb_Backspace;
|
||||
pBinds[GLFW_KEY_ENTER] = Kb_Enter;*/
|
||||
}
|
||||
|
||||
void HidGLFW::Update() {
|
||||
// Clear States
|
||||
for (int i = 0; i < 2; i++) {
|
||||
KeyEvents[i][Event_Down] = 0;
|
||||
KeyEvents[i][Event_Held] = 0;
|
||||
KeyEvents[i][Event_Up] = 0;
|
||||
for (auto& it : KbKeyEvents[i]) {
|
||||
it.second = Event_Null;
|
||||
}
|
||||
}
|
||||
// Keyboard Logic
|
||||
/*for (auto& it : pBinds) {
|
||||
int kbstate = glfwGetKey(Window, it.first);
|
||||
if (kbstate == GLFW_PRESS) {
|
||||
if (PrevStates[it.first] == GLFW_RELEASE) {
|
||||
KbKeyEvents[0][it.second] = Event_Down;
|
||||
}
|
||||
KbKeyEvents[0][it.second] = Event_Held;
|
||||
} else if (kbstate == GLFW_RELEASE && PrevStates[it.first] == GLFW_PRESS) {
|
||||
KbKeyEvents[0][it.second] = Event_Up;
|
||||
}
|
||||
PrevStates[it.first] = kbstate;
|
||||
}*/
|
||||
// Mouse Logic (Todo: Support all mouse buttons)
|
||||
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
|
||||
if (state == GLFW_PRESS) {
|
||||
if (PrevState == GLFW_RELEASE) {
|
||||
KeyEvents[0][Event_Down] |= Touch;
|
||||
}
|
||||
KeyEvents[0][Event_Held] |= Touch;
|
||||
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
|
||||
KeyEvents[0][Event_Up] |= Touch;
|
||||
}
|
||||
|
||||
PrevState = state;
|
||||
if (pLocked) {
|
||||
SwapTab();
|
||||
}
|
||||
double x, y;
|
||||
glfwGetCursorPos(Window, &x, &y);
|
||||
pMouse[1] = pMouse[0]; // Cycle pMouse pos
|
||||
pMouse[0] = fvec2(x, y);
|
||||
/*if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
|
||||
pLastUpdate = PD::OS::GetTime();
|
||||
HandleTextOps();
|
||||
}*/
|
||||
}
|
||||
|
||||
void HidGLFW::GetInputStr(std::string& str) {
|
||||
pText = &str;
|
||||
glfwSetCharCallback(Window, TextCB);
|
||||
pInTextMode = true;
|
||||
}
|
||||
|
||||
void HidGLFW::HandleTextOps() {
|
||||
if (!pText) {
|
||||
return;
|
||||
}
|
||||
/*if (pTimedHeld(Kb_Backspace)) {
|
||||
if (!pText->empty()) {
|
||||
pText->pop_back();
|
||||
}
|
||||
} else if (pTimedHeld(Kb_Enter)) {
|
||||
*pText += '\n';
|
||||
}*/
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <palladium>
|
||||
#include <pd-desktop.hpp>
|
||||
|
||||
namespace PD {
|
||||
void Init(void* data) {
|
||||
/*if (!data) {
|
||||
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
|
||||
"reference as data "
|
||||
"input!"
|
||||
<< std::endl;
|
||||
abort();
|
||||
}
|
||||
// Dekstop Init Stage
|
||||
// First use default OS Driver
|
||||
PD::OS::Init();
|
||||
PD::Gfx::Init(PD::GfxGL2::New());
|
||||
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));*/
|
||||
}
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user