Karma Engine
Loading...
Searching...
No Matches
KarmaGuiOpenGLHandler.h
1// Major and heavy modifications of the original Dear ImGUI's take on OpenGL3 implementation
2// https://github.com/ravimohan1991/imgui/blob/07334fa9c67e6c7c827cc76c2ac4de419a1658c1/backends/imgui_impl_opengl3.h
3
4#pragma once
5#include "KarmaGui.h" // IMGUI_IMPL_API
6#include "Karma/Renderer/Scene.h"
7
8#define KGGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
9
10//#include "glad/glad.h"
11
12#ifdef _WIN64
13typedef signed long long int khronos_ssize_t;
14#else
15typedef signed long int khronos_ssize_t;
16#endif
17
18typedef unsigned int GLuint;
19typedef int GLint;
20
21typedef khronos_ssize_t GLsizeiptr;
22
23
24namespace Karma
25{
26 // Decal data
28 {
29 GLuint DecalRef;
30 KGTextureID DecalID;
31 int width, height;
32 };
33
34 // OpenGL Data
36 {
37 GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
38 char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings.
39 GLuint FontTexture;
40 // Images data
41 std::vector<MesaDecalData> openglMesaDecalDataList;
42 GLuint ShaderHandle;
43 GLint AttribLocationTex; // Uniforms location
44 GLint AttribLocationProjMtx;
45 GLuint AttribLocationVtxPos; // Vertex attributes location
46 GLuint AttribLocationVtxUV;
47 GLuint AttribLocationVtxColor;
48 unsigned int VboHandle, ElementsHandle;
49 GLsizeiptr VertexBufferSize;
50 GLsizeiptr IndexBufferSize;
51 bool HasClipOrigin;
52 bool UseBufferSubData;
53 //KarmaGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
54 };
55
56 // OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
57#ifndef KGGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
58 struct ImGui_ImplOpenGL3_VtxAttribState
59 {
60 GLint Enabled, Size, Type, Normalized, Stride;
61 GLvoid* Ptr;
62
63 void GetState(GLint index)
64 {
65 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
66 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
67 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
68 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
69 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
70 glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
71 }
72 void SetState(GLint index)
73 {
74 glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
75 if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
76 }
77 };
78#endif
79
80 class KARMA_API KarmaGuiOpenGLHandler
81 {
82 public:
83 // Backend API
84 static bool KarmaGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
85 static void KarmaGui_ImplOpenGL3_Shutdown();
86 static void KarmaGui_ImplOpenGL3_NewFrame();
87 static void KarmaGui_ImplOpenGL3_RenderDrawData(KGDrawData* draw_data);
88 /*
89 inline static KarmaGui_ImplOpenGL3_Data* KarmaGui_ImplOpenGL3_GetBackendData()
90 {
91 return KarmaGui::GetCurrentContext() ? (KarmaGui_ImplOpenGL3_Data*)KarmaGui::GetIO().BackendRendererUserData : NULL;
92 }*/
93
94 static void KarmaGui_ImplOpenGL3_SetupRenderState(KGDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object);
95 static void KarmaGui_ImpOpenGL3_SetupRenderStateFor3DRendering(Scene* sceneToDraw, KGDrawData* drawData);
96 static bool CheckShader(GLuint handle, const char* desc);
97 static bool CheckProgram(GLuint handle, const char* desc);
98 static void KarmaGui_ImplOpenGL3_RenderWindow(KarmaGuiViewport* viewport, void*);
99 static void KarmaGui_ImplOpenGL3_InitPlatformInterface();
100 static void KarmaGui_ImplOpenGL3_ShutdownPlatformInterface();
101 static void KarmaGui_ImplOpenGL3_CreateTexture(char const* fileName, const std::string& label = "");
102
103 // (Optional) Called by Init/NewFrame/Shutdown
104 static bool KarmaGui_ImplOpenGL3_CreateFontsTexture();
105 static void KarmaGui_ImplOpenGL3_DestroyFontsTexture();
106 static bool KarmaGui_ImplOpenGL3_CreateDeviceObjects();
107 static void KarmaGui_ImplOpenGL3_DestroyDeviceObjects();
108 };
109}
Definition KarmaGuiOpenGLHandler.h:81
Definition Scene.h:11
Definition KarmaGui.h:2647
Definition KarmaGui.h:2948
Definition KarmaGuiOpenGLHandler.h:36
Definition KarmaGuiOpenGLHandler.h:28