KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::KarmaGuiOpenGLHandler Class Reference

The chief class for KarmaGui's OpenGL based backend renderer. More...

#include <KarmaGuiOpenGLHandler.h>

Static Public Member Functions

static bool KarmaGui_ImplOpenGL3_Init (const char *glsl_version=NULL)
 Initializing OpenGL backend renderer.
 
static void KarmaGui_ImplOpenGL3_InitPlatformInterface ()
 KarmaGuiPlatformIO 's instance's member, platform_io.Renderer_RenderWindow, is set to KarmaGui_ImplOpenGL3_RenderWindow.
 
static void KarmaGui_ImplOpenGL3_ShutdownPlatformInterface ()
 Destroy window(s) opened in viewport(s) and clear the data.
 
static void KarmaGui_ImplOpenGL3_Shutdown ()
 Function called when KarmaGui layer shuts down (happens when LayerStack is destroyed). Call stack is like so: KarmaGuiLayer::OnDetach() -> KarmaGuiRenderer::OnKarmaGuiLayerDetach() -> KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_Shutdown().
 
static void KarmaGui_ImplOpenGL3_NewFrame ()
 Function called in the begining of each KarmaGui's render loop.
 
static void KarmaGui_ImplOpenGL3_RenderDrawData (KGDrawData *draw_data)
 The routine for rendering the Karma's UI using OpenGL3 API.
 
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 appearance of partial or full transparency) enabled, no face culling, no depth testing, scissor enabled, polygon fill, setup viewport. Bind vertex/index buffers and setup attributes for KGDrawVert.
 
static bool CheckShader (GLuint handle, const char *desc)
 A check for success of shader (within KarmaGuiOpenGLHandler context) compilation.
 
static bool CheckProgram (GLuint handle, const char *desc)
 A check for the success of shader (within KarmaGuiOpenGLHandler context) linking.
 
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_ImplOpenGL3_RenderDrawData.
 
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 openglMesaDecalDataList for use.
 
static bool KarmaGui_ImplOpenGL3_CreateFontsTexture ()
 A function to generate texture for OpenGL fonts The following steps are taken:
 
static void KarmaGui_ImplOpenGL3_DestroyFontsTexture ()
 Clear up the resources occupied by the fonts and decals, all the textures in this context.
 
static bool KarmaGui_ImplOpenGL3_CreateDeviceObjects ()
 Creates and generates shaders and buffers to be used along with the necessary uniforms.
 
static void KarmaGui_ImplOpenGL3_DestroyDeviceObjects ()
 Clears up all the resources (shaders, buffers, and uniforms) allocated in KarmaGui_ImplOpenGL3_CreateDeviceObjects()
 

Detailed Description

The chief class for KarmaGui's OpenGL based backend renderer.

Since
Karma 1.0.0

Member Function Documentation

◆ CheckProgram()

bool Karma::KarmaGuiOpenGLHandler::CheckProgram ( GLuint handle,
const char * desc )
static

A check for the success of shader (within KarmaGuiOpenGLHandler context) linking.

The following log message is printed on the occurance of the linking error detected by the check

[03:36:56][error] KARMA: KarmaGuiOpenGLHandler::CheckProgram: failed to link shader program! With GLSL:#version 410
[03:36:56][error] KARMA: ERROR: One or more attached shaders not successfully compiled
static bool CheckProgram(GLuint handle, const char *desc)
A check for the success of shader (within KarmaGuiOpenGLHandler context) linking.
Definition KarmaGuiOpenGLHandler.cpp:515
Parameters
handleThe GL program (for shader object) object being queried
descThe category name of the program object. For instance "shader program" (only)
Since
Karma 1.0.0

◆ CheckShader()

bool Karma::KarmaGuiOpenGLHandler::CheckShader ( GLuint handle,
const char * desc )
static

A check for success of shader (within KarmaGuiOpenGLHandler context) compilation.

The following log message is printed on the occurance of compilation error detected by the check

[03:06:44][error] KARMA: KarmaGuiOpenGLHandler::CheckShader: failed to compile vertex shader! With GLSL:#version 410
[03:06:49][error] KARMA: ERROR: 0:3: 'layout' : syntax error: syntax error
static bool CheckShader(GLuint handle, const char *desc)
A check for success of shader (within KarmaGuiOpenGLHandler context) compilation.
Definition KarmaGuiOpenGLHandler.cpp:493
Parameters
handleThe shader object being queried
descThe category name of the shader object. For instance "vertex shader" or "fragment shader"
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_CreateDeviceObjects()

bool Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_CreateDeviceObjects ( )
static

Creates and generates shaders and buffers to be used along with the necessary uniforms.

Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_CreateFontsTexture()

bool Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_CreateFontsTexture ( )
static

A function to generate texture for OpenGL fonts The following steps are taken:

  1. Texture atlas is built from KGFontAtlas. This is done by first loading the font atlas in the form RGBA 32-bit (with 75% wastage). Then the creation of a 2D texture (GL_TEXTURE_2D), with appropriate name(s), by glGenTextures -> glBindTexture -> glTexImage2D -> target texture (or atlas)
  2. Finally the target texture is stored like so; io.Fonts->SetTexID
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_CreateTexture()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_CreateTexture ( char const * fileName,
const std::string & label = "" )
static

A helper function to generate texture, in appropriate format, and add to the list openglMesaDecalDataList for use.

Parameters
fileNameThe path to the file containing texture
labelThe name of the texture for identification purpose
See also
OpenGLImageBuffer::SetUpImageBuffer
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_DestroyDeviceObjects()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_DestroyDeviceObjects ( )
static

Clears up all the resources (shaders, buffers, and uniforms) allocated in KarmaGui_ImplOpenGL3_CreateDeviceObjects()

Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_DestroyFontsTexture()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_DestroyFontsTexture ( )
static

Clear up the resources occupied by the fonts and decals, all the textures in this context.

Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_Init()

bool Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_Init ( const char * glsl_version = NULL)
static

Initializing OpenGL backend renderer.

The following steps are taken:

  1. KarmaGuiContext's members, chiefly BackendRendererUserData and flags, are set
  2. Based on KGGuiConfigFlags_ViewportsEnable, drag and drop feature is set up by calling KarmaGui_ImplOpenGL3_InitPlatformInterface()
Parameters
glsl_versionThe version of OpenGL driver being used
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_InitPlatformInterface()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_InitPlatformInterface ( )
static

KarmaGuiPlatformIO 's instance's member, platform_io.Renderer_RenderWindow, is set to KarmaGui_ImplOpenGL3_RenderWindow.

Note
There is one global instance of KarmaGuiPlatformIO, in this context, which can be retrieved by KarmaGui::GetPlatformIO (basically GKarmaGui->PlatformIO)
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_NewFrame()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_NewFrame ( )
static

Function called in the begining of each KarmaGui's render loop.

In minor detail, the sequence is like so

  1. Application::Run
  2. m_KarmaGuiLayer->Begin() -> KarmaGuiRenderer::OnKarmaGuiLayerBegin() -> KarmaGui_ImplOpenGL3_NewFrame()
  3. each layer->KarmaGuiRender(deltaTime);
  4. m_KarmaGuiLayer->End();
Note
Should be called after ImGui_ImplOpenGL3_Init() because BackendRendererUserData (io.BackendRendererUserData) must be already instantiated and initialized.
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_RenderDrawData()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_RenderDrawData ( KGDrawData * draw_data)
static

The routine for rendering the Karma's UI using OpenGL3 API.

Basically all that is drawn for Karma's UI (and inside the UI, including text, textures, and all that) is nothing but the set of triangles (KGDrawList). The relevant information is written in KGDrawData instance by the call Karma::KarmaGui::Render()

Parameters
draw_dataThe data to render a KarmaGui frame
Note
We use ocornut's callback technique https://github.com/ocornut/imgui/issues/475#issuecomment-169953139 to render 3d scene inside KarmaGui's UI element
See also
KarmaGui_ImplOpenGL3_SetupRenderState()
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_RenderWindow()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_RenderWindow ( KarmaGuiViewport * viewport,
void * render_arg )
static

Prepares the context for OpenGl's rendering of KarmaGui's primitives and calls the function KarmaGui_ImplOpenGL3_RenderDrawData.

Note
This function is supplied to KarmaGuiPlatformIO's Renderer_RenderWindow member and then KarmaGuiRenderer (via call in KarmaGuiRenderer::OnKarmaGuiLayerEnd()) takes care of the rest of rendering sequence. This is done for incorporating even the helper modular design.
Parameters
viewportThe only single platform window since we are not working with multi-viewport
render_argIs the value passed to KarmaGui::RenderPlatformWindowsDefault() by KarmaGuiRenderer::OnKarmaGuiLayerEnd(), usually NULL
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_SetupRenderState()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_SetupRenderState ( KGDrawData * draw_data,
int fb_width,
int fb_height,
GLuint vertex_array_object )
static

Setup render state: alpha-blending (process of combining one image with a background to create the appearance of partial or full transparency) enabled, no face culling, no depth testing, scissor enabled, polygon fill, setup viewport. Bind vertex/index buffers and setup attributes for KGDrawVert.

Parameters
draw_dataThe collection of variables composing the draw data to render a KarmaGui frame
fb_widthThe width of the KarmaGui's rendering scope (draw_data->DisplaySize.x * draw_data->FramebufferScale.x), for glViewport's use.
fb_heightThe height of the KarmaGui's rendering scope (draw_data->DisplaySize.y * draw_data->FramebufferScale.y), for glViewport's use.
vertex_array_objectThe name of the OpenGl vertexarray object
Todo
An amature work: try using math GLM's projection matrix for orthographic view
Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_Shutdown()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_Shutdown ( )
static

Function called when KarmaGui layer shuts down (happens when LayerStack is destroyed). Call stack is like so: KarmaGuiLayer::OnDetach() -> KarmaGuiRenderer::OnKarmaGuiLayerDetach() -> KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_Shutdown().

Since
Karma 1.0.0

◆ KarmaGui_ImplOpenGL3_ShutdownPlatformInterface()

void Karma::KarmaGuiOpenGLHandler::KarmaGui_ImplOpenGL3_ShutdownPlatformInterface ( )
static

Destroy window(s) opened in viewport(s) and clear the data.

Note
The job of backend here is to clear the data (that may have got stored in e.g. PlatformUserData, RendererUserData) by self before KarmaGui clears in a systematic way
Todo
KarmaGuiOpenGLHandler seems to be not doing the right form of cleaning of resources because Renderer_Destroy_Window is not set like that in KarmaGuiVulkanHandler. Try to find a way.
Since
Karma 1.0.0

The documentation for this class was generated from the following files: