Norbert's Game Engine v200
Loading...
Searching...
No Matches
eGraphics Class Reference

#include <Graphics.hpp>

Inheritance diagram for eGraphics:
eBase

Public Member Functions

 eGraphics (HWND window, uint32 width, uint32 height, bool vsync, uint8 msaa, eRenderAPI api)
 
void Frame ()
 
void Printf (uint16 x, uint16 y, uint8 attr, const char *format)
 
void Touch (int &width, int &height, bool vsync, uint8 msaaSetting)
 
void InitDI (GLFWwindow *glfwWin, HWND win, int viewId=1)
 
void ReleaseDI (bool glfwWin=true)
 
void BeginDI (bool glfwWin=true)
 
void EndDI (bool glfwWin=true)
 
void SetEnableDockingDI (bool vl=true)
 
void InitIDB (eLayer *layer, std::vector< eTransformation2D > &transformations, eIDB &idb)
 
void InitIDBAtlas (eLayer *layer, std::vector< eAtlasInstance > &instances, eIDB &idb)
 
void Draw2D (eShader *shader, eLayer *layer, eViewport2D vp, eTransformation2D transformation, eTexture *texture)
 
const int Draw2DInstances (eShader *shader, eLayer *layer, eViewport2D vp, std::vector< eTransformation2D > &transformations, eTexture *texture)
 
void Draw2DInstances (eShader *shader, eLayer *layer, eViewport2D vp, eIDB &idb, eTexture *texture)
 
void Draw2DAtlas (eShader *shader, eLayer *layer, eViewport2D vp, eTransformation2D transformation, eTextureAtlas &atlas, vec2 subImg)
 
const int Draw2DAtlasInstances (eShader *shader, eLayer *layer, eViewport2D vp, std::vector< eTransformation2D > &transformations, eTextureAtlas &atlas, vec2 subImg)
 
const int Draw2DAtlasInstances (eShader *shader, eLayer *layer, eViewport2D vp, std::vector< eAtlasInstance > &instances, eTextureAtlas &atlas)
 
void Draw2DAtlasInstances (eShader *shader, eLayer *layer, eViewport2D vp, eIDB &idb, eTextureAtlas &atlas)
 
void Draw2DAtlasInstances (eShader *shader, eLayer *layer, eViewport2D vp, eIDB &idb, eTextureAtlas &atlas, vec2 subImg)
 
void ResetAtlasShader (eShader *shader)
 
void Draw3D (eShader *shader, eLayer *layer, eTransformation3D transformation, eTexture *texture)
 
void DrawBillboard (eShader *shader, eLayer *layer, eTransformation3D transformation, eTexture *texture)
 
void DrawString (eShader *shader, eLayer *layer, eViewport2D vp, eTransformation2D transformation, eTextAtlas &atlas, eString text, eColor4 color=eColor4(1.0f))
 
bool CompileShader (eString name)
 
const eGPU_INFO * GetGPUInfo ()
 
void ApplyScissor ()
 
void ResetScissor ()
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Static Public Member Functions

static void SetState (uint64 state=0)
 
template<typename var >
static void Destroy (var &handle)
 

Public Attributes

eScissorInfo mScissorInfo
 

Detailed Description

Graphics class

Definition at line 78 of file Graphics.hpp.

Constructor & Destructor Documentation

◆ eGraphics()

eGraphics::eGraphics ( HWND window,
uint32 width,
uint32 height,
bool vsync,
uint8 msaa,
eRenderAPI api )

Definition at line 14 of file Graphics.cpp.

15{
16 mHwnd = window;
17
18 mInit.platformData.nwh = window;
19 mInit.resolution.width = width;
20 mInit.resolution.height = height;
21 if (vsync)
22 mInit.resolution.reset = BGFX_RESET_VSYNC;
23
24 switch (msaa)
25 {
26 case 2: mInit.resolution.reset |= BGFX_RESET_MSAA_X2; break;
27 case 4: mInit.resolution.reset |= BGFX_RESET_MSAA_X4; break;
28 case 8: mInit.resolution.reset |= BGFX_RESET_MSAA_X8; break;
29 case 16: mInit.resolution.reset |= BGFX_RESET_MSAA_X16; break;
30 }
31
32 switch (api)
33 {
34 case eRenderAPI::Direct3D11: mInit.type = bgfx::RendererType::Direct3D11; break;
35 case eRenderAPI::Direct3D12: mInit.type = bgfx::RendererType::Direct3D12; break;
36 case eRenderAPI::Vulkan: mInit.type = bgfx::RendererType::Vulkan; break;
37 }
38
39 if (!bgfx::init(mInit))
40 {
41 eConsole::PrintLog("ERROR::eGraphics", "Failed to initialize bgfx.");
43 return;
44 }
45
46 bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH);
47 bgfx::reset((uint32)width, (uint32)height, (vsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE) | mInit.resolution.reset);
48 bgfx::setViewRect(0, 0, 0, bgfx::BackbufferRatio::Equal);
49
50 //mScissorInfo.mPosition = vec2i(0);
51 //mScissorInfo.mSize = vec2i(width, height);
52 //ApplyScissor();
53
54 Init2D();
55 InitBillboard();
56}
static void WriteToDisk()
Write the console text to a crash file called 'CRASH.log'.
Definition Console.cpp:40
static void PrintLog(eString head, eString msg)
Print a log.
Definition Console.cpp:22

◆ ~eGraphics()

eGraphics::~eGraphics ( )

Definition at line 58 of file Graphics.cpp.

59{
60 Release2D();
61 ReleaseBillboard();
62 bgfx::shutdown();
63}

Member Function Documentation

◆ ApplyScissor()

void eGraphics::ApplyScissor ( )

Definition at line 871 of file Graphics.cpp.

872{
873 if (mScissorInfo.mSize == vec2i(0))
874 {
875 bgfx::setScissor();
876 return;
877 }
878 bgfx::setScissor(mScissorInfo.mPosition.x, mScissorInfo.mPosition.y, mScissorInfo.mSize.x, mScissorInfo.mSize.y);
879}

◆ BeginDI()

void eGraphics::BeginDI ( bool glfwWin = true)

Definition at line 711 of file Graphics.cpp.

712{
713 ImGui_Implbgfx_NewFrame();
714 if (glfwWin)
715 ImGui_ImplGlfw_NewFrame();
716 else
717 ImGui_ImplWin32_NewFrame();
718 ImGui::NewFrame();
719
720 if (bEnableDockingDI)
721 {
722 static ImGuiViewport* viewport = ImGui::GetMainViewport();
723 ImGui::SetNextWindowPos(viewport->Pos);
724 ImGui::SetNextWindowSize(ImVec2(viewport->Size.x - 40.0f, viewport->Size.y));
725 ImGui::SetNextWindowViewport(viewport->ID);
726 ImGui::SetNextWindowBgAlpha(0.0f);
727
728 //ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking
729 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
730 window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
731
732 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
733 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
734
735 ImGuiStyle& style = ImGui::GetStyle();
736 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, style.FramePadding.y * 2 + ImGui::GetFontSize()));
737 bool p_open = true;
738 ImGui::Begin("MAINWINDOW", &p_open, window_flags);
739 ImGui::PopStyleVar(3);
740
741 ImGuiID dockspace_id = ImGui::GetID("MAINWINDOW");
742 ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;
743 ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
744 ImGui::End();
745 }
746}

◆ CompileShader()

bool eGraphics::CompileShader ( eString name)

Definition at line 759 of file Graphics.cpp.

760{
761 if (!EDR::FileExists("shaderc.exe"))
762 {
763 eConsole::PrintLog("Shader Compiler Error", "'shaderc.exe' could not be found!");
764 return false;
765 }
766 return CompileShaderFA(name);
767}

◆ Destroy()

template<typename var >
static void eGraphics::Destroy ( var & handle)
inlinestatic

Definition at line 96 of file Graphics.hpp.

97 {
98 if (bgfx::isValid(handle))
99 {
100 bgfx::destroy(handle);
101 handle.idx = bgfx::kInvalidHandle;
102 }
103 }

◆ Draw2D()

void eGraphics::Draw2D ( eShader * shader,
eLayer * layer,
eViewport2D vp,
eTransformation2D transformation,
eTexture * texture )

Definition at line 136 of file Graphics.cpp.

137{
138 if (texture == nullptr || shader == nullptr || layer == nullptr)
139 return;
140
141 real3 proj[16];
142 bx::mtxOrtho(proj, vp.GetTranslation().x, vp.GetSize().x + vp.GetTranslation().x,
143 vp.GetSize().y + vp.GetTranslation().y, vp.GetTranslation().y, 0.1f, 100.0f, 0.0f, false);
144 bgfx::setViewTransform(layer->GetProperties().mViewId, mView2D, proj);
145
146 real3 posX = (layer->GetProperties().mResolution.x / transformation.mScale.x) / (layer->GetProperties().mResolution.x / transformation.mPosition.x);
147 real3 posY = (layer->GetProperties().mResolution.y / transformation.mScale.y) / (layer->GetProperties().mResolution.y / transformation.mPosition.y);
148
149 vec3 rotPiv = vec3(transformation.mRotationPivot.x, transformation.mRotationPivot.y, 0.0f);
150 mat4 mdl = eMath::scale(mat4(1.0f), vec3(transformation.mScale.x, transformation.mScale.y, 1.0f));
151 mdl = eMath::translate(mdl, vec3(posX, posY, 0.0f) + rotPiv);
152 mdl = eMath::rotate(mdl, glm::radians(transformation.mRotation), vec3(0.0f, 0.0f, 1.0f));
153 mdl = eMath::translate(mdl, -rotPiv);
154
155 bgfx::setTransform(eMath::value_ptr(mdl));
156 SetState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ALPHA);
157 ApplyScissor();
158
159 shader->ApplyVertexBuffer(0, mVbh2D);
160 shader->SetTexture(0, "s_texColor", texture);
161 shader->Submit(layer->GetProperties().mViewId, true);
162}

◆ Draw2DAtlas()

void eGraphics::Draw2DAtlas ( eShader * shader,
eLayer * layer,
eViewport2D vp,
eTransformation2D transformation,
eTextureAtlas & atlas,
vec2 subImg )

Definition at line 273 of file Graphics.cpp.

274{
275 vec4 atinf[2];
276 atinf[0] = vec4(subImg, atlas.mSize);
277 atinf[1] = vec4(atlas.mSubSize, 1.0f, 0.0f);
278 shader->SetUniform("atlasInfo", atinf, 2);
279
280 Draw2D(shader, layer, vp, transformation, atlas.mTexture);
281}

◆ Draw2DAtlasInstances() [1/4]

void eGraphics::Draw2DAtlasInstances ( eShader * shader,
eLayer * layer,
eViewport2D vp,
eIDB & idb,
eTextureAtlas & atlas )

Definition at line 321 of file Graphics.cpp.

322{
323 if (atlas.mTexture == nullptr || shader == nullptr || layer == nullptr) return;
324
325 vec4 atinf[2];
326 atinf[0] = vec4(0.0f, 0.0f, atlas.mSize);
327 atinf[1] = vec4(atlas.mSubSize, 1.0f, 0.0f);
328 shader->SetUniform("atlasInfo", atinf, 2);
329
330 real3 proj[16];
331 bx::mtxOrtho(proj, vp.GetTranslation().x, vp.GetSize().x + vp.GetTranslation().x,
332 vp.GetSize().y + vp.GetTranslation().y, vp.GetTranslation().y, 0.1f, 100.0f, 0.0f, false);
333 bgfx::setViewTransform(layer->GetProperties().mViewId, mView2D, proj);
334
335 SetState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ALPHA);
336 ApplyScissor();
337 shader->ApplyVertexBuffer(0, mVbh2D);
338 bgfx::setInstanceDataBuffer(&idb.mBuffer);
339 shader->SetTexture(0, "s_texColor", atlas.mTexture);
340 shader->Submit(layer->GetProperties().mViewId, true);
341}

◆ Draw2DAtlasInstances() [2/4]

void eGraphics::Draw2DAtlasInstances ( eShader * shader,
eLayer * layer,
eViewport2D vp,
eIDB & idb,
eTextureAtlas & atlas,
vec2 subImg )

Definition at line 343 of file Graphics.cpp.

344{
345 vec4 atinf[2];
346 atinf[0] = vec4(subImg, atlas.mSize);
347 atinf[1] = vec4(atlas.mSubSize, 1.0f, 0.0f);
348 shader->SetUniform("atlasInfo", atinf, 2);
349
350 Draw2DInstances(shader, layer, vp, idb, atlas.mTexture);
351}

◆ Draw2DAtlasInstances() [3/4]

const int eGraphics::Draw2DAtlasInstances ( eShader * shader,
eLayer * layer,
eViewport2D vp,
std::vector< eAtlasInstance > & instances,
eTextureAtlas & atlas )

Definition at line 293 of file Graphics.cpp.

294{
295 if (atlas.mTexture == nullptr || shader == nullptr || layer == nullptr)
296 return -1;
297
298 vec4 atinf[2];
299 atinf[0] = vec4(0.0f, 0.0f, atlas.mSize);
300 atinf[1] = vec4(atlas.mSubSize, 1.0f, 0.0f);
301 shader->SetUniform("atlasInfo", atinf, 2);
302
303 real3 proj[16];
304 bx::mtxOrtho(proj, vp.GetTranslation().x, vp.GetSize().x + vp.GetTranslation().x,
305 vp.GetSize().y + vp.GetTranslation().y, vp.GetTranslation().y, 0.1f, 100.0f, 0.0f, false);
306 bgfx::setViewTransform(layer->GetProperties().mViewId, mView2D, proj);
307
308 bgfx::InstanceDataBuffer idb;
309 const int rtVl = DrawInsBeginAtlas(layer, instances, idb);
310
311 SetState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ALPHA);
312 ApplyScissor();
313 shader->ApplyVertexBuffer(0, mVbh2D);
314 bgfx::setInstanceDataBuffer(&idb);
315 shader->SetTexture(0, "s_texColor", atlas.mTexture);
316 shader->Submit(layer->GetProperties().mViewId, true);
317
318 return rtVl;
319}

◆ Draw2DAtlasInstances() [4/4]

const int eGraphics::Draw2DAtlasInstances ( eShader * shader,
eLayer * layer,
eViewport2D vp,
std::vector< eTransformation2D > & transformations,
eTextureAtlas & atlas,
vec2 subImg )

Definition at line 283 of file Graphics.cpp.

284{
285 vec4 atinf[2];
286 atinf[0] = vec4(subImg, atlas.mSize);
287 atinf[1] = vec4(atlas.mSubSize, 1.0f, 0.0f);
288 shader->SetUniform("atlasInfo", atinf, 2);
289
290 return Draw2DInstances(shader, layer, vp, transformations, atlas.mTexture);
291}

◆ Draw2DInstances() [1/2]

void eGraphics::Draw2DInstances ( eShader * shader,
eLayer * layer,
eViewport2D vp,
eIDB & idb,
eTexture * texture )

Definition at line 187 of file Graphics.cpp.

188{
189 if (texture == nullptr || shader == nullptr || layer == nullptr)
190 return;
191
192 real3 proj[16];
193 bx::mtxOrtho(proj, vp.GetTranslation().x, vp.GetSize().x + vp.GetTranslation().x,
194 vp.GetSize().y + vp.GetTranslation().y, vp.GetTranslation().y, 0.1f, 100.0f, 0.0f, false);
195 bgfx::setViewTransform(layer->GetProperties().mViewId, mView2D, proj);
196
197 SetState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ALPHA);
198 ApplyScissor();
199 shader->ApplyVertexBuffer(0, mVbh2D);
200 bgfx::setInstanceDataBuffer(&idb.mBuffer);
201 shader->SetTexture(0, "s_texColor", texture);
202 shader->Submit(layer->GetProperties().mViewId, true);
203}

◆ Draw2DInstances() [2/2]

const int eGraphics::Draw2DInstances ( eShader * shader,
eLayer * layer,
eViewport2D vp,
std::vector< eTransformation2D > & transformations,
eTexture * texture )

Definition at line 164 of file Graphics.cpp.

165{
166 if (texture == nullptr || shader == nullptr || layer == nullptr)
167 return -1;
168
169 real3 proj[16];
170 bx::mtxOrtho(proj, vp.GetTranslation().x, vp.GetSize().x + vp.GetTranslation().x,
171 vp.GetSize().y + vp.GetTranslation().y, vp.GetTranslation().y, 0.1f, 100.0f, 0.0f, false);
172 bgfx::setViewTransform(layer->GetProperties().mViewId, mView2D, proj);
173
174 bgfx::InstanceDataBuffer idb;
175 const int rtVl = DrawInsBegin(layer, transformations, idb);
176
177 SetState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ALPHA);
178 ApplyScissor();
179 shader->ApplyVertexBuffer(0, mVbh2D);
180 bgfx::setInstanceDataBuffer(&idb);
181 shader->SetTexture(0, "s_texColor", texture);
182 shader->Submit(layer->GetProperties().mViewId, true);
183
184 return rtVl;
185}

◆ Draw3D()

void eGraphics::Draw3D ( eShader * shader,
eLayer * layer,
eTransformation3D transformation,
eTexture * texture )

Definition at line 366 of file Graphics.cpp.

367{
368 if (texture == nullptr || shader == nullptr || layer == nullptr)
369 return;
370
371 mat4 mdl = eTools::Transform(transformation);
372 bgfx::setTransform(eMath::value_ptr(mdl));
373 SetState();
374 ApplyScissor();
375 shader->ApplyVertexBuffer(0, mVbh2D);
376 shader->SetTexture(0, "s_texColor", texture);
377 shader->Submit(layer->GetProperties().mViewId, true);
378}

◆ DrawBillboard()

void eGraphics::DrawBillboard ( eShader * shader,
eLayer * layer,
eTransformation3D transformation,
eTexture * texture )

Definition at line 380 of file Graphics.cpp.

381{
382 if (texture == nullptr || shader == nullptr || layer == nullptr)
383 return;
384
385 mat4 mdl = eTools::Transform(transformation);
386 bgfx::setTransform(eMath::value_ptr(mdl));
387 SetState();
388 ApplyScissor();
389 shader->ApplyVertexBuffer(0, mVbhBillboard);
390 shader->SetTexture(0, "s_texColor", texture);
391 shader->SetUniform("scale", glm::value_ptr(vec4(transformation.mScale.x, transformation.mScale.y, 0.0f, 0.0f)));
392 shader->Submit(layer->GetProperties().mViewId, true);
393}

◆ DrawString()

void eGraphics::DrawString ( eShader * shader,
eLayer * layer,
eViewport2D vp,
eTransformation2D transformation,
eTextAtlas & atlas,
eString text,
eColor4 color = eColor4(1.0f) )

Definition at line 420 of file Graphics.cpp.

422{
423 eTransformation2D trans = transformation;
424 std::vector<eAtlasInstance> instances;
425 strg stext = text.GetStrg();
426 for (auto& it : stext)
427 {
428 bool goDown = false;
429 bool goNear = false;
430 vec2 subImg = vec2(0.0f);
431 switch (it)
432 {
433 case 'b': { subImg.x = 1.0f; }break;
434 case 'c': { subImg.x = 2.0f; }break;
435 case 'd': { subImg.x = 3.0f; }break;
436 case 'e': { subImg.x = 4.0f; }break;
437 case 'f': { goNear = true; subImg.x = 5.0f; }break;
438 case 'g': { goDown = true; subImg.x = 6.0f; }break;
439 case 'h': { subImg.x = 7.0f; }break;
440 case 'i': { goNear = true; subImg.x = 8.0f; }break;
441 case 'j': { goNear = true; goDown = true; subImg.x = 9.0f; }break;
442 case 'k': { subImg.x = 10.0f; }break;
443 case 'l': { goNear = true; subImg.x = 11.0f; }break;
444 case 'm': { subImg.x = 12.0f; }break;
445 case 'n': { subImg.x = 13.0f; }break;
446 case 'o': { subImg.x = 14.0f; }break;
447 case 'p': { goDown = true; subImg.x = 15.0f; }break;
448 case 'q': { goDown = true; subImg.x = 16.0f; }break;
449 case 'r': { goNear = true; subImg.x = 17.0f; }break;
450 case 's': { subImg.x = 18.0f; }break;
451 case 't': { goNear = true; subImg.x = 19.0f; }break;
452 case 'u': { subImg.x = 20.0f; }break;
453 case 'v': { subImg.x = 21.0f; }break;
454 case 'w': { subImg.x = 22.0f; }break;
455 case 'x': { subImg.x = 23.0f; }break;
456 case 'y': { subImg.x = 24.0f; }break;
457 case 'z': { subImg.x = 25.0f; }break;
458 case 'ü': { subImg.x = 26.0f; }break;
459 case 'ä': { subImg.x = 27.0f; }break;
460 case 'ö': { subImg.x = 28.0f; }break;
461 case 'A': { subImg = vec2(0.0f, 1.0f); }break;
462 case 'B': { subImg = vec2(1.0f, 1.0f); }break;
463 case 'C': { subImg = vec2(2.0f, 1.0f); }break;
464 case 'D': { subImg = vec2(3.0f, 1.0f); }break;
465 case 'E': { subImg = vec2(4.0f, 1.0f); }break;
466 case 'F': { subImg = vec2(5.0f, 1.0f); }break;
467 case 'G': { subImg = vec2(6.0f, 1.0f); }break;
468 case 'H': { subImg = vec2(7.0f, 1.0f); }break;
469 case 'I': { goNear = true; subImg = vec2(8.0f, 1.0f); }break;
470 case 'J': { subImg = vec2(9.0f, 1.0f); }break;
471 case 'K': { subImg = vec2(10.0f, 1.0f); }break;
472 case 'L': { subImg = vec2(11.0f, 1.0f); }break;
473 case 'M': { subImg = vec2(12.0f, 1.0f); }break;
474 case 'N': { subImg = vec2(13.0f, 1.0f); }break;
475 case 'O': { subImg = vec2(14.0f, 1.0f); }break;
476 case 'P': { subImg = vec2(15.0f, 1.0f); }break;
477 case 'Q': { subImg = vec2(16.0f, 1.0f); }break;
478 case 'R': { subImg = vec2(17.0f, 1.0f); }break;
479 case 'S': { subImg = vec2(18.0f, 1.0f); }break;
480 case 'T': { subImg = vec2(19.0f, 1.0f); }break;
481 case 'U': { subImg = vec2(20.0f, 1.0f); }break;
482 case 'V': { subImg = vec2(21.0f, 1.0f); }break;
483 case 'W': { subImg = vec2(22.0f, 1.0f); }break;
484 case 'X': { subImg = vec2(23.0f, 1.0f); }break;
485 case 'Y': { subImg = vec2(24.0f, 1.0f); }break;
486 case 'Z': { subImg = vec2(25.0f, 1.0f); }break;
487 case 'Ü': { subImg = vec2(26.0f, 1.0f); }break;
488 case 'Ä': { subImg = vec2(27.0f, 1.0f); }break;
489 case 'Ö': { subImg = vec2(28.0f, 1.0f); }break;
490 case '0': { subImg = vec2(0.0f, 2.0f); }break;
491 case '1': { subImg = vec2(1.0f, 2.0f); }break;
492 case '2': { subImg = vec2(2.0f, 2.0f); }break;
493 case '3': { subImg = vec2(3.0f, 2.0f); }break;
494 case '4': { subImg = vec2(4.0f, 2.0f); }break;
495 case '5': { subImg = vec2(5.0f, 2.0f); }break;
496 case '6': { subImg = vec2(6.0f, 2.0f); }break;
497 case '7': { subImg = vec2(7.0f, 2.0f); }break;
498 case '8': { subImg = vec2(8.0f, 2.0f); }break;
499 case '9': { subImg = vec2(9.0f, 2.0f); }break;
500 case ',': { goNear = true; goDown = true; subImg = vec2(10.0f, 2.0f); }break;
501 case ';': { goNear = true; goDown = true; subImg = vec2(11.0f, 2.0f); }break;
502 case '.': { goNear = true; subImg = vec2(12.0f, 2.0f); }break;
503 case ':': { goNear = true; subImg = vec2(13.0f, 2.0f); }break;
504 case '-': { subImg = vec2(14.0f, 2.0f); }break;
505 case '_': { subImg = vec2(15.0f, 2.0f); }break;
506 case '`': { goNear = true; subImg = vec2(16.0f, 2.0f); }break;
507 case '´': { goNear = true; subImg = vec2(17.0f, 2.0f); }break;
508 case '<': { subImg = vec2(18.0f, 2.0f); }break;
509 case '>': { subImg = vec2(19.0f, 2.0f); }break;
510 case '|': { goNear = true; subImg = vec2(20.0f, 2.0f); }break;
511 case '!': { goNear = true; subImg = vec2(21.0f, 2.0f); }break;
512 case '"': { subImg = vec2(22.0f, 2.0f); }break;
513 case '§': { subImg = vec2(23.0f, 2.0f); }break;
514 case '$': { subImg = vec2(24.0f, 2.0f); }break;
515 case '%': { subImg = vec2(25.0f, 2.0f); }break;
516 case '&': { subImg = vec2(26.0f, 2.0f); }break;
517 case '/': { subImg = vec2(27.0f, 2.0f); }break;
518 case '(': { subImg = vec2(28.0f, 2.0f); }break;
519 case ')': { subImg = vec2(0.0f, 3.0f); }break;
520 case '=': { subImg = vec2(1.0f, 3.0f); }break;
521 case '?': { subImg = vec2(2.0f, 3.0f); }break;
522 case '\\': { subImg = vec2(3.0f, 3.0f); }break;
523 case '}': { subImg = vec2(4.0f, 3.0f); }break;
524 case '{': { subImg = vec2(5.0f, 3.0f); }break;
525 case ']': { subImg = vec2(6.0f, 3.0f); }break;
526 case '[': { subImg = vec2(7.0f, 3.0f); }break;
527 case '€': { subImg = vec2(8.0f, 3.0f); }break;
528 case '@': { subImg = vec2(9.0f, 3.0f); }break;
529 case '#': { subImg = vec2(10.0f, 3.0f); }break;
530 case '\'': { goNear = true; subImg = vec2(11.0f, 3.0f); }break;
531 case '+': { subImg = vec2(12.0f, 3.0f); }break;
532 case '~': { subImg = vec2(13.0f, 3.0f); }break;
533 case '*': { goNear = true; subImg = vec2(14.0f, 3.0f); }break;
534 case '^': { goNear = true; subImg = vec2(15.0f, 3.0f); }break;
535 case '°': { goNear = true; subImg = vec2(16.0f, 3.0f); }break;
536 case ' ': { trans.mPosition.x += trans.mScale.x * atlas.mSpace.x; continue; }break;
537 case '\n':
538 {
539 trans.mPosition.x = transformation.mPosition.x;
540 trans.mPosition.y += trans.mScale.y * atlas.mSpace.y;
541 continue;
542 }break;
543 }
544
545 real3 oldY = trans.mPosition.y;
546 if (goDown)
547 trans.mPosition.y += trans.mScale.y * atlas.mSpace.y * 0.12f;
548
549 eAtlasInstance instance;
550 instance.mSubImg = subImg;
551 instance.mTransformation = trans;
552 instances.push_back(instance);
553
554 if(goNear)
555 trans.mPosition.x += trans.mScale.x * 0.5f * atlas.mSpace.x;
556 else
557 trans.mPosition.x += trans.mScale.x * atlas.mSpace.x;
558
559 trans.mPosition.y = oldY;
560 }
561 shader->SetUniform("color", eMath::value_ptr(eTools::Color4ToVec4(color)));
562 Draw2DAtlasInstances(shader, layer, vp, instances, atlas.mAtlas);
563}
const strg & GetStrg() const
Return text as std::string.
Definition String.cpp:70

◆ EndDI()

void eGraphics::EndDI ( bool glfwWin = true)

Definition at line 748 of file Graphics.cpp.

749{
750 ImGui::Render();
751 ImGui_Implbgfx_RenderDrawLists(ImGui::GetDrawData());
752}

◆ Frame()

void eGraphics::Frame ( )

Definition at line 65 of file Graphics.cpp.

66{
67#if _DEBUG
68 //BGFX_DEBUG_STATS | BGFX_DEBUG_TEXT
69 bgfx::setDebug(BGFX_DEBUG_TEXT);
70#endif
71 bgfx::frame();
72}

◆ GetGPUInfo()

const eGPU_INFO * eGraphics::GetGPUInfo ( )

Definition at line 866 of file Graphics.cpp.

867{
868 return bgfx::getCaps();
869}

◆ InitDI()

void eGraphics::InitDI ( GLFWwindow * glfwWin,
HWND win,
int viewId = 1 )

Definition at line 594 of file Graphics.cpp.

595{
596 IMGUI_CHECKVERSION();
597 ImGui::CreateContext();
598 ImGuiIO& io = ImGui::GetIO(); (void)io;
599 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
600 io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
601 if (bEnableDockingDI)
602 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
603 //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
604 io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
605 io.ConfigWindowsMoveFromTitleBarOnly = true;
606
607 ImGuiStyle& style = ImGui::GetStyle();
608
609 style.Alpha = 1.0f;
610 style.DisabledAlpha = 0.6000000238418579f;
611 style.WindowPadding = ImVec2(8.0f, 8.0f);
612 style.WindowRounding = 10.5f;
613 style.WindowBorderSize = 1.0f;
614 style.WindowMinSize = ImVec2(32.0f, 32.0f);
615 style.WindowTitleAlign = ImVec2(0.5f, 0.4000000059604645f);
616 style.WindowMenuButtonPosition = ImGuiDir_Left;
617 style.ChildRounding = 20.0f;
618 style.ChildBorderSize = 1.0f;
619 style.PopupRounding = 6.5f;
620 style.PopupBorderSize = 1.0f;
621 style.FramePadding = ImVec2(20.0f, 4.800000190734863f);
622 style.FrameRounding = 2.0f;
623 style.FrameBorderSize = 1.0f;
624 style.ItemSpacing = ImVec2(8.0f, 4.0f);
625 style.ItemInnerSpacing = ImVec2(4.0f, 4.0f);
626 style.CellPadding = ImVec2(4.0f, 2.0f);
627 style.IndentSpacing = 21.0f;
628 style.ColumnsMinSpacing = 6.0f;
629 style.ScrollbarSize = 13.0f;
630 style.ScrollbarRounding = 12.0f;
631 style.GrabMinSize = 7.0f;
632 style.GrabRounding = 0.0f;
633 style.TabRounding = 1.0f;
634 style.TabBorderSize = 1.0f;
635 style.TabMinWidthForCloseButton = FLT_MAX;
636 style.ColorButtonPosition = ImGuiDir_Right;
637 style.ButtonTextAlign = ImVec2(0.5f, 0.5f);
638 style.SelectableTextAlign = ImVec2(0.0f, 0.0f);
639
640 style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
641 style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.4980392158031464f, 0.4980392158031464f, 0.4980392158031464f, 1.0f);
642 style.Colors[ImGuiCol_WindowBg] = ImVec4(0.2532188892364502f, 0.2532163560390472f, 0.2532163560390472f, 1.0f);
643 style.Colors[ImGuiCol_ChildBg] = ImVec4(0.2784313857555389f, 0.2784313857555389f, 0.2784313857555389f, 0.0f);
644 style.Colors[ImGuiCol_PopupBg] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3098039329051971f, 1.0f);
645 style.Colors[ImGuiCol_Border] = ImVec4(9.999999974752427e-07f, 9.999899930335232e-07f, 9.999899930335232e-07f, 1.0f);
646 style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
647 style.Colors[ImGuiCol_FrameBg] = ImVec4(0.1568627506494522f, 0.1568627506494522f, 0.1568627506494522f, 1.0f);
648 style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2000000029802322f, 1.0f);
649 style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.2784313857555389f, 0.2784313857555389f, 0.2784313857555389f, 1.0f);
650 style.Colors[ImGuiCol_TitleBg] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1450980454683304f, 1.0f);
651 style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1450980454683304f, 1.0f);
652 style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.1450980454683304f, 0.1450980454683304f, 0.1450980454683304f, 1.0f);
653 style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.1921568661928177f, 0.1921568661928177f, 0.1921568661928177f, 1.0f);
654 style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.1568627506494522f, 0.1568627506494522f, 0.1568627506494522f, 1.0f);
655 style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.2745098173618317f, 0.2745098173618317f, 0.2745098173618317f, 1.0f);
656 style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.2980392277240753f, 0.2980392277240753f, 0.2980392277240753f, 1.0f);
657 style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
658 style.Colors[ImGuiCol_CheckMark] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
659 style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.3882353007793427f, 0.3882353007793427f, 0.3882353007793427f, 1.0f);
660 style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
661 style.Colors[ImGuiCol_Button] = ImVec4(1.0f, 1.0f, 1.0f, 0.0f);
662 style.Colors[ImGuiCol_ButtonHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.1560000032186508f);
663 style.Colors[ImGuiCol_ButtonActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.3910000026226044f);
664 style.Colors[ImGuiCol_Header] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3098039329051971f, 1.0f);
665 style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.4666666686534882f, 0.4666666686534882f, 0.4666666686534882f, 1.0f);
666 style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.4666666686534882f, 0.4666666686534882f, 0.4666666686534882f, 1.0f);
667 style.Colors[ImGuiCol_Separator] = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
668 style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
669 style.Colors[ImGuiCol_SeparatorActive] = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
670 style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.0f, 1.0f, 1.0f, 0.25f);
671 style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.0f, 1.0f, 1.0f, 0.6700000166893005f);
672 style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
673 style.Colors[ImGuiCol_Tab] = ImVec4(0.09411764889955521f, 0.09411764889955521f, 0.09411764889955521f, 1.0f);
674 style.Colors[ImGuiCol_TabHovered] = ImVec4(0.3490196168422699f, 0.3490196168422699f, 0.3490196168422699f, 1.0f);
675 style.Colors[ImGuiCol_TabActive] = ImVec4(0.1921568661928177f, 0.1921568661928177f, 0.1921568661928177f, 1.0f);
676 style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.09411764889955521f, 0.09411764889955521f, 0.09411764889955521f, 1.0f);
677 style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.1921568661928177f, 0.1921568661928177f, 0.1921568661928177f, 1.0f);
678 style.Colors[ImGuiCol_PlotLines] = ImVec4(0.4666666686534882f, 0.4666666686534882f, 0.4666666686534882f, 1.0f);
679 style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
680 style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.5843137502670288f, 0.5843137502670288f, 0.5843137502670288f, 1.0f);
681 style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
682 style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.2000000029802322f, 1.0f);
683 style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3490196168422699f, 1.0f);
684 style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2274509817361832f, 0.2274509817361832f, 0.2470588237047195f, 1.0f);
685 style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
686 style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.05999999865889549f);
687 style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(1.0f, 1.0f, 1.0f, 0.1560000032186508f);
688 style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
689 style.Colors[ImGuiCol_NavHighlight] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
690 style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 0.3882353007793427f, 0.0f, 1.0f);
691 style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.5860000252723694f);
692 style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.5860000252723694f);
693
694 if (glfwWin != nullptr)
695 ImGui_ImplGlfw_InitForOther(glfwWin, true);
696 else
697 ImGui_ImplWin32_Init(win);
698 ImGui_Implbgfx_Init(viewId);
699}

◆ InitIDB()

void eGraphics::InitIDB ( eLayer * layer,
std::vector< eTransformation2D > & transformations,
eIDB & idb )

Definition at line 131 of file Graphics.cpp.

132{
133 idb.mCouldNotDraw = DrawInsBegin(layer, transformations, idb.mBuffer);
134}

◆ InitIDBAtlas()

void eGraphics::InitIDBAtlas ( eLayer * layer,
std::vector< eAtlasInstance > & instances,
eIDB & idb )

Definition at line 361 of file Graphics.cpp.

362{
363 idb.mCouldNotDraw = DrawInsBeginAtlas(layer, instances, idb.mBuffer);
364}

◆ Printf()

void eGraphics::Printf ( uint16 x,
uint16 y,
uint8 attr,
const char * format )

Definition at line 91 of file Graphics.cpp.

92{
93#if _DEBUG
94 bgfx::dbgTextPrintf(x, y, attr, format);
95#endif
96 return;
97}

◆ ReleaseDI()

void eGraphics::ReleaseDI ( bool glfwWin = true)

Definition at line 701 of file Graphics.cpp.

702{
703 ImGui_Implbgfx_Shutdown();
704 if (glfwWin)
705 ImGui_ImplGlfw_Shutdown();
706 else
707 ImGui_ImplWin32_Shutdown();
708 ImGui::DestroyContext();
709}

◆ ResetAtlasShader()

void eGraphics::ResetAtlasShader ( eShader * shader)

Definition at line 353 of file Graphics.cpp.

354{
355 vec4 atinf[2];
356 atinf[0] = vec4(0.0f);
357 atinf[1] = vec4(0.0f);
358 shader->SetUniform("atlasInfo", atinf, 2);
359}

◆ ResetScissor()

void eGraphics::ResetScissor ( )

Definition at line 881 of file Graphics.cpp.

882{
883 bgfx::setScissor();
884 mScissorInfo = { vec2i(0), vec2i(0) };
885}

◆ SetEnableDockingDI()

void eGraphics::SetEnableDockingDI ( bool vl = true)

Definition at line 754 of file Graphics.cpp.

755{
756 bEnableDockingDI = vl;
757}

◆ SetState()

void eGraphics::SetState ( uint64 state = 0)
static

Definition at line 74 of file Graphics.cpp.

75{
76 if (state == 0)
77 bgfx::setState(0
78 BGFX_STATE_DEFAULT
79 | BGFX_STATE_BLEND_ALPHA
80 | BGFX_STATE_WRITE_RGB
81 | BGFX_STATE_WRITE_A
82 | BGFX_STATE_WRITE_Z
83 | BGFX_STATE_DEPTH_TEST_LESS
84 | BGFX_STATE_CULL_CCW
85 | BGFX_STATE_MSAA
86 );
87 else
88 bgfx::setState(0 BGFX_STATE_DEFAULT | state);
89}

◆ Touch()

void eGraphics::Touch ( int & width,
int & height,
bool vsync,
uint8 msaaSetting )

Definition at line 99 of file Graphics.cpp.

100{
101 int oldWidth = width, oldHeight = height;
102
103 RECT wr;
104 GetClientRect(mHwnd, &wr);
105 width = wr.right - wr.left;
106 height = wr.bottom - wr.top;
107
108 if (width != oldWidth || height != oldHeight)
109 {
110 eLayer::mRefreshSize = true;
111 uint32 msaaFlag = BGFX_RESET_NONE;
112 switch (msaaSetting)
113 {
114 case 2: msaaFlag = BGFX_RESET_MSAA_X2; break;
115 case 4: msaaFlag = BGFX_RESET_MSAA_X4; break;
116 case 8: msaaFlag = BGFX_RESET_MSAA_X8; break;
117 case 16: msaaFlag = BGFX_RESET_MSAA_X16; break;
118 }
119 bgfx::reset((uint32)width, (uint32)height, (vsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE) | msaaFlag);
120 bgfx::setViewRect(0, 0, 0, bgfx::BackbufferRatio::Equal);
121 }
122 else
123 eLayer::mRefreshSize = false;
124
125 bgfx::touch(0);
126#if _DEBUG
127 bgfx::dbgTextClear();
128#endif
129}

Member Data Documentation

◆ mScissorInfo

eScissorInfo eGraphics::mScissorInfo

Definition at line 125 of file Graphics.hpp.


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