KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
KarmaGuiOpenGLHandler.h
Go to the documentation of this file.
1
10// Dear ImGui (1.89.2) is Copyright (c) 2014-2023 Omar Cornut.
11
12// Major and heavy modifications of the original Dear ImGUI's take on OpenGL3 implementation
13// https://github.com/ravimohan1991/imgui/blob/07334fa9c67e6c7c827cc76c2ac4de419a1658c1/backends/imgui_impl_opengl3.h
14// Disclaimer:
15// Most of the member variables and function naming in the herein is credited to the author(s) of Dear ImGUI. I take no responsibility
16// of damage caused by short names herein.
17
18#pragma once
19#include "KarmaGui.h"
21
22#define KGGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
23
24#ifdef _WIN64
25typedef signed long long int khronos_ssize_t;
26#else
27typedef signed long int khronos_ssize_t;
28#endif
29
30typedef unsigned int GLuint;
31typedef int GLint;
32
33typedef khronos_ssize_t GLsizeiptr;
34
35namespace Karma
36{
45 {
53 GLuint DecalRef;
54
62 KGTextureID DecalID;
63
69 int width;
70
76 int height;
77 };
78
86 {
93 GLuint GlVersion;
94
101
111
118 std::vector<MesaDecalData> openglMesaDecalDataList;
119
126
133
140
147
154
161
168 unsigned int VboHandle;
169
176 unsigned int ElementsHandle;
177
184
190 GLsizeiptr IndexBufferSize;
191
192 // Detect extensions we support
201
208
215 {
216 //memset((void*)this, 0, sizeof(*this));
218 }
219 };
220
221 // OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only)
222#ifndef KGGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
229 struct ImGui_ImplOpenGL3_VtxAttribState
230 {
231 GLint Enabled, Size, Type, Normalized, Stride;
232 GLvoid* Ptr;
233
234 void GetState(GLint index)
235 {
236 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled);
237 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size);
238 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type);
239 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized);
240 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride);
241 glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr);
242 }
243 void SetState(GLint index)
244 {
245 glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr);
246 if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index);
247 }
248 };
249#endif
250
257 {
258 public:
260 // Backend API
262
272 static bool KarmaGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
273
281
290
296 static void KarmaGui_ImplOpenGL3_Shutdown();
297
310 static void KarmaGui_ImplOpenGL3_NewFrame();
311
323 static void KarmaGui_ImplOpenGL3_RenderDrawData(KGDrawData* draw_data);
324 /*
325 inline static KarmaGui_ImplOpenGL3_Data* KarmaGui_ImplOpenGL3_GetBackendData()
326 {
327 return KarmaGui::GetCurrentContext() ? (KarmaGui_ImplOpenGL3_Data*)KarmaGui::GetIO().BackendRendererUserData : NULL;
328 }*/
329
341 static void KarmaGui_ImplOpenGL3_SetupRenderState(KGDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object);
342
357 static bool CheckShader(GLuint handle, const char* desc);
358
372 static bool CheckProgram(GLuint handle, const char* desc);
373
383 static void KarmaGui_ImplOpenGL3_RenderWindow(KarmaGuiViewport* viewport, void* render_arg);
384
394 static void KarmaGui_ImplOpenGL3_CreateTexture(char const* fileName, const std::string& label = "");
395
396 // (Optional) Called by Init/NewFrame/Shutdown
407
414
421
428 };
429}
#define KARMA_API
Defining Karma's API macro for storage class information.
Definition Core.h:41
This file constains KarmaGui class. The chief class for our UI needs..
This file contains the class Scene.
The chief class for KarmaGui's OpenGL based backend renderer.
Definition KarmaGuiOpenGLHandler.h:257
static void KarmaGui_ImplOpenGL3_CreateTexture(char const *fileName, const std::string &label="")
A helper function to generate texture, in appropriate format, and add to the list openglMesaDecalData...
Definition KarmaGuiOpenGLHandler.cpp:755
static void KarmaGui_ImplOpenGL3_RenderWindow(KarmaGuiViewport *viewport, void *render_arg)
Prepares the context for OpenGl's rendering of KarmaGui's primitives and calls the function KarmaGui_...
Definition KarmaGuiOpenGLHandler.cpp:733
static bool KarmaGui_ImplOpenGL3_Init(const char *glsl_version=NULL)
Initializing OpenGL backend renderer.
Definition KarmaGuiOpenGLHandler.cpp:23
static bool KarmaGui_ImplOpenGL3_CreateDeviceObjects()
Creates and generates shaders and buffers to be used along with the necessary uniforms.
Definition KarmaGuiOpenGLHandler.cpp:535
static void KarmaGui_ImplOpenGL3_RenderDrawData(KGDrawData *draw_data)
The routine for rendering the Karma's UI using OpenGL3 API.
Definition KarmaGuiOpenGLHandler.cpp:228
static bool CheckShader(GLuint handle, const char *desc)
A check for success of shader (within KarmaGuiOpenGLHandler context) compilation.
Definition KarmaGuiOpenGLHandler.cpp:493
static void KarmaGui_ImplOpenGL3_ShutdownPlatformInterface()
Destroy window(s) opened in viewport(s) and clear the data.
Definition KarmaGuiOpenGLHandler.cpp:750
static void KarmaGui_ImplOpenGL3_NewFrame()
Function called in the begining of each KarmaGui's render loop.
Definition KarmaGuiOpenGLHandler.cpp:136
static bool CheckProgram(GLuint handle, const char *desc)
A check for the success of shader (within KarmaGuiOpenGLHandler context) linking.
Definition KarmaGuiOpenGLHandler.cpp:515
static void KarmaGui_ImplOpenGL3_DestroyFontsTexture()
Clear up the resources occupied by the fonts and decals, all the textures in this context.
Definition KarmaGuiOpenGLHandler.cpp:474
static void KarmaGui_ImplOpenGL3_DestroyDeviceObjects()
Clears up all the resources (shaders, buffers, and uniforms) allocated in KarmaGui_ImplOpenGL3_Create...
Definition KarmaGuiOpenGLHandler.cpp:724
static void KarmaGui_ImplOpenGL3_InitPlatformInterface()
KarmaGuiPlatformIO 's instance's member, platform_io.Renderer_RenderWindow, is set to KarmaGui_ImplOp...
Definition KarmaGuiOpenGLHandler.cpp:744
static void KarmaGui_ImplOpenGL3_SetupRenderState(KGDrawData *draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
Setup render state: alpha-blending (process of combining one image with a background to create the ap...
Definition KarmaGuiOpenGLHandler.cpp:147
static void KarmaGui_ImplOpenGL3_Shutdown()
Function called when KarmaGui layer shuts down (happens when LayerStack is destroyed)....
Definition KarmaGuiOpenGLHandler.cpp:123
static bool KarmaGui_ImplOpenGL3_CreateFontsTexture()
A function to generate texture for OpenGL fonts The following steps are taken:
Definition KarmaGuiOpenGLHandler.cpp:429
Definition KarmaGui.h:2697
GLint AttribLocationProjMtx
An integer that represents the location of a projection matrix uniform variable within a program obje...
Definition KarmaGuiOpenGLHandler.h:139
GLsizeiptr IndexBufferSize
The size of total sum of indices in int units of sizeof(KGDrawVert) to be utilized by KarmaGui using ...
Definition KarmaGuiOpenGLHandler.h:190
char GlslVersionString[32]
Specified by user or detected based on compile time GL settings.
Definition KarmaGuiOpenGLHandler.h:100
unsigned int VboHandle
The handle for vertex buffer (GL_ARRAY_BUFFER) object meant for KarmaGui using OpenGL api.
Definition KarmaGuiOpenGLHandler.h:168
GLsizeiptr VertexBufferSize
The size of total sum of vertices in int units of sizeof(KGDrawVert) to be utilized by KarmaGui using...
Definition KarmaGuiOpenGLHandler.h:183
bool HasClipOrigin
If extension GL_ARB_clip_control is supported and macro IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS is defi...
Definition KarmaGuiOpenGLHandler.h:200
GLint AttribLocationTex
An integer that represents the location of a texture uniform variable within a program object.
Definition KarmaGuiOpenGLHandler.h:132
GLuint AttribLocationVtxUV
An integer that represents the location of a UV uniform variable within a program object.
Definition KarmaGuiOpenGLHandler.h:153
unsigned int ElementsHandle
The handle for index buffer (GL_ELEMENT_ARRAY_BUFFER) object meant for KarmaGui using OpenGL api.
Definition KarmaGuiOpenGLHandler.h:176
GLuint GlVersion
The OpenGL version in use.
Definition KarmaGuiOpenGLHandler.h:93
GLuint ShaderHandle
The handle for KarmaGui's shader program.
Definition KarmaGuiOpenGLHandler.h:125
std::vector< MesaDecalData > openglMesaDecalDataList
The list of all the images' data to be used in KarmaGui with OpenGL api.
Definition KarmaGuiOpenGLHandler.h:118
KarmaGui_ImplOpenGL3_Data()
A constructor.
Definition KarmaGuiOpenGLHandler.h:214
bool UseBufferSubData
True when the processor vendor is Intel and we are on Windows platform. When true glBufferSubData (in...
Definition KarmaGuiOpenGLHandler.h:207
GLuint AttribLocationVtxColor
An integer that represents the location of a vertex colo(u)r uniform variable within a program object...
Definition KarmaGuiOpenGLHandler.h:160
GLuint AttribLocationVtxPos
An integer that represents the location of a vertex position (model transform?) uniform variable with...
Definition KarmaGuiOpenGLHandler.h:146
GLuint FontTexture
Array ID for OpenGL's font texture.
Definition KarmaGuiOpenGLHandler.h:110
A data structure for holding information about Mesa texture. For instance, file and folder icons of C...
Definition KarmaGuiOpenGLHandler.h:45
int width
2D width of the decal
Definition KarmaGuiOpenGLHandler.h:69
int height
2D height of the decal
Definition KarmaGuiOpenGLHandler.h:76
GLuint DecalRef
An array in which the generated texture names, for decals, are stored.
Definition KarmaGuiOpenGLHandler.h:53
KGTextureID DecalID
A typecasted version of DecalRef The DecalID is used in KarmaGui::ImageButton.
Definition KarmaGuiOpenGLHandler.h:62
A Platform Window (always 1 unless multi-viewport are enabled. One per platform window to output to)....
Definition KarmaGui.h:3005