# 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:
114
backends/desktop/source/li_backend_gl2.cpp → backends/desktop/source/bknd-gfx.cpp
Normal file → Executable file
114
backends/desktop/source/li_backend_gl2.cpp → backends/desktop/source/bknd-gfx.cpp
Normal file → Executable file
@ -1,5 +1,31 @@
|
||||
#include <li_backend_gl2.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-desktop/bknd-gfx.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
const char* vertex_shader = R"(
|
||||
#version 120
|
||||
|
||||
@ -35,8 +61,7 @@ const char* frag_shader = R"(
|
||||
}
|
||||
)";
|
||||
|
||||
GLuint compileShader(const std::string& source,
|
||||
GLenum type) {
|
||||
GLuint compileShader(const std::string& source, GLenum type) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
const char* src = source.c_str();
|
||||
glShaderSource(shader, 1, &src, nullptr);
|
||||
@ -53,9 +78,8 @@ GLuint compileShader(const std::string& source,
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint
|
||||
createShaderProgram(const std::string& vertexShaderSource,
|
||||
const std::string& fragmentShaderSource) {
|
||||
GLuint createShaderProgram(const std::string& vertexShaderSource,
|
||||
const std::string& fragmentShaderSource) {
|
||||
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||
GLuint fragmentShader =
|
||||
compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||
@ -79,9 +103,9 @@ createShaderProgram(const std::string& vertexShaderSource,
|
||||
return shaderProgram;
|
||||
}
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::Init() {
|
||||
/** Actual Backend */
|
||||
|
||||
void GfxGL2::Init() {
|
||||
VertexBuffer.Resize(4 * 8192);
|
||||
IndexBuffer.Resize(6 * 8192);
|
||||
Shader = createShaderProgram(vertex_shader, frag_shader);
|
||||
@ -93,17 +117,17 @@ PD_BKND_DESKTOP_API void Backend_GL2::Init() {
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, Color));
|
||||
glEnableVertexAttribArray(_color);
|
||||
|
||||
glGenBuffers(1, &IBO);
|
||||
@ -116,12 +140,12 @@ PD_BKND_DESKTOP_API void Backend_GL2::Init() {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::Deinit() {
|
||||
void GfxGL2::Deinit() {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &IBO);
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::NewFrame() {
|
||||
void GfxGL2::NewFrame() {
|
||||
glViewport(0, 0, ViewPort.x, ViewPort.y);
|
||||
glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
@ -132,57 +156,56 @@ PD_BKND_DESKTOP_API void Backend_GL2::NewFrame() {
|
||||
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;
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::BindTexture(PD::LI::TexAddress addr) {
|
||||
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);
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData(
|
||||
const PD::Vec<PD::LI::Command::Ref>& Commands) {
|
||||
void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
||||
glUseProgram(Shader);
|
||||
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;
|
||||
}
|
||||
size_t StartIndex = CurrentIndex;
|
||||
bool ScissorEnabled = Commands[index]->ScissorEnabled;
|
||||
bool ScissorOn = Commands[index]->ScissorOn;
|
||||
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
||||
|
||||
while (index < Commands.Size() && Commands[index]->Tex == Tex &&
|
||||
Commands[index]->ScissorEnabled == ScissorEnabled &&
|
||||
while (index < Commands.size() && Commands[index]->Tex == Tex &&
|
||||
Commands[index]->ScissorOn == ScissorOn &&
|
||||
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++;
|
||||
}
|
||||
if (ScissorEnabled) {
|
||||
if (ScissorOn) {
|
||||
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
||||
ScissorRect.z, ScissorRect.w);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
} else {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
BindTexture(Tex->Address);
|
||||
BindTex(Tex->Address);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::LI::Vertex),
|
||||
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
||||
&VertexBuffer[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
@ -194,37 +217,36 @@ PD_BKND_DESKTOP_API void Backend_GL2::RenderDrawData(
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
BindTexture(0);
|
||||
BindTex(0);
|
||||
}
|
||||
}
|
||||
|
||||
PD_BKND_DESKTOP_API PD::LI::Texture::Ref Backend_GL2::LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h, PD::LI::Texture::Type type,
|
||||
PD::LI::Texture::Filter filter) {
|
||||
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) {
|
||||
if (type == PD::Li::Texture::Type::RGB24) {
|
||||
fmt = GL_RGB;
|
||||
} else if (type == PD::LI::Texture::Type::A8) {
|
||||
} 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) {
|
||||
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) {
|
||||
} 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));
|
||||
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace LI
|
||||
} // namespace Li
|
||||
} // namespace PD
|
58
backends/desktop/source/bknd-hid.cpp
Executable file
58
backends/desktop/source/bknd-hid.cpp
Executable file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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-desktop/bknd-hid.hpp>
|
||||
|
||||
namespace PD {
|
||||
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
|
||||
Window = win;
|
||||
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
|
||||
}
|
||||
|
||||
void HidGLFW::Update() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
KeyEvents[i][Event_Down] = 0;
|
||||
KeyEvents[i][Event_Held] = 0;
|
||||
KeyEvents[i][Event_Up] = 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
} // namespace PD
|
43
backends/desktop/source/pd-desktop.cpp
Executable file
43
backends/desktop/source/pd-desktop.cpp
Executable file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
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-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::Li::Gfx::Init(PD::Li::GfxGL2::New());
|
||||
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
|
||||
}
|
||||
} // namespace PD
|
@ -1,33 +0,0 @@
|
||||
#include <pd_hid_glfw.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_BKND_DESKTOP_API HidGLFW::HidGLFW(GLFWwindow* win) : Hid("GLFW") {
|
||||
Window = win;
|
||||
binds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
|
||||
}
|
||||
PD_BKND_DESKTOP_API void HidGLFW::Update() {
|
||||
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;
|
||||
}
|
||||
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
|
||||
if (state == GLFW_PRESS) {
|
||||
if (PrevState == GLFW_RELEASE) {
|
||||
key_events[0][Event_Down] |= Touch;
|
||||
}
|
||||
key_events[0][Event_Held] |= Touch;
|
||||
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
|
||||
key_events[0][Event_Up] |= Touch;
|
||||
}
|
||||
|
||||
PrevState = state;
|
||||
if (locked) {
|
||||
SwappyTable();
|
||||
}
|
||||
double x, y;
|
||||
glfwGetCursorPos(Window, &x, &y);
|
||||
touch[1] = touch[0]; // Cycle touch pos
|
||||
touch[0] = fvec2(x, y);
|
||||
}
|
||||
} // namespace PD
|
Reference in New Issue
Block a user