# Changes
3ds Backend: - switch to shaderProgramUse Desktop Backend - Add Pre Alpha Text Input and Keyboard Support - Move Shader Attrib Setup into a function and callit every time we need a set up vbo - Move to Mat4 api Core: - Add fquat support - Add LoadFile2Str - Move Mat4 Lib from Project n73 to Palladium - Add full supprot for vec cross types - Add Normalize, Distance and Dot to all - Add Cross to vec3 Drivers: - Add a SetViewPort func to GFX - Add Keyboard keys and Flasg to Hid Image: - Add Vertical Flipping - Add Horizontal flipping UI7: - Fix Critical Bug in IO Viewport handler - Fix library list (error on MinGW for some reason) Lazyvec: - Split into multiple source files - Generate new functions (see core updates)
This commit is contained in:
		| @@ -37,9 +37,36 @@ class HidGLFW : public HidDriver { | ||||
|   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 (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] = PD::OS::GetTime(); | ||||
|       return true; | ||||
|     } | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   /** Data section */ | ||||
|   GLFWwindow* Window; | ||||
|   int PrevState; | ||||
|   std::unordered_map<int, int> PrevStates; | ||||
|   static std::string* pText; | ||||
|   bool pInTextMode = false; | ||||
|   PD::u64 pLastUpdate = 0; | ||||
|   std::unordered_map<KbKey, u64> pTimings; | ||||
| }; | ||||
| }  // namespace PD | ||||
| @@ -36,7 +36,7 @@ const char* vertex_shader = R"( | ||||
|   varying vec2 oUV; | ||||
|   varying vec4 oColor; | ||||
|    | ||||
|   // Probably forgot about this matric and | ||||
|   // Probably forgot about this matrix and | ||||
|   // searched hours for why the rendering isn't working :/ | ||||
|   uniform mat4 projection; | ||||
|    | ||||
| @@ -103,17 +103,7 @@ GLuint createShaderProgram(const std::string& vertexShaderSource, | ||||
|   return shaderProgram; | ||||
| } | ||||
|  | ||||
| /** Actual Backend */ | ||||
|  | ||||
| void GfxGL2::Init() { | ||||
|   VertexBuffer.Resize(4 * 8192); | ||||
|   IndexBuffer.Resize(6 * 8192); | ||||
|   Shader = createShaderProgram(vertex_shader, frag_shader); | ||||
|   glUseProgram(Shader); | ||||
|  | ||||
|   glGenBuffers(1, &VBO); | ||||
|   glBindBuffer(GL_ARRAY_BUFFER, VBO); | ||||
|  | ||||
| void SetupShaderAttribs(GLuint Shader) { | ||||
|   GLint _pos = glGetAttribLocation(Shader, "pos"); | ||||
|   GLint _uv = glGetAttribLocation(Shader, "uv"); | ||||
|   GLint _color = glGetAttribLocation(Shader, "color"); | ||||
| @@ -129,6 +119,21 @@ void GfxGL2::Init() { | ||||
|                         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); | ||||
|  | ||||
|   glGenBuffers(1, &VBO); | ||||
|   glBindBuffer(GL_ARRAY_BUFFER, VBO); | ||||
|  | ||||
|   // Attribs Setup | ||||
|   SetupShaderAttribs(Shader); | ||||
|  | ||||
|   glGenBuffers(1, &IBO); | ||||
|   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); | ||||
| @@ -146,11 +151,14 @@ void GfxGL2::Deinit() { | ||||
| } | ||||
|  | ||||
| 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.Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, -1.f, 1.f); | ||||
|   glUniformMatrix4fv(pLocProjection, 1, GL_TRUE, Projection.m); | ||||
|   */ | ||||
|   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); | ||||
|   CurrentIndex = 0; | ||||
| @@ -170,7 +178,6 @@ void GfxGL2::BindTex(PD::Li::TexAddress addr) { | ||||
| } | ||||
|  | ||||
| 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; | ||||
| @@ -207,6 +214,9 @@ void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) { | ||||
|     glBindBuffer(GL_ARRAY_BUFFER, VBO); | ||||
|     glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex), | ||||
|                  &VertexBuffer[0], GL_DYNAMIC_DRAW); | ||||
|     // For some reason we need to set these every frame for every buffer | ||||
|     // Found that out when creating My 3d Engine | ||||
|     SetupShaderAttribs(Shader); | ||||
|  | ||||
|     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); | ||||
|     glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16), | ||||
|   | ||||
| @@ -23,19 +23,104 @@ SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| #include <pd-desktop/bknd-hid.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| std::string* HidGLFW::pText; | ||||
| // Default Call back (If no Text input is requsted) | ||||
| void NullTextCB(GLFWwindow* win, unsigned int c) {} | ||||
| // Text callback if requested | ||||
| void TextCB(GLFWwindow* win, unsigned int c) { | ||||
|   if (!HidGLFW::pText) { | ||||
|     return; | ||||
|   } | ||||
|   *HidGLFW::pText += (char)c; | ||||
| } | ||||
| HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") { | ||||
|   Window = win; | ||||
|   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) { | ||||
| @@ -54,5 +139,28 @@ void HidGLFW::Update() { | ||||
|   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 | ||||
		Reference in New Issue
	
	Block a user