Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
opengl_shader_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 
6 
8 {
13  {
14  private:
15  BlamGLSLShaderProgram* active_program = NULL;
16 
17  void GenerateUniformControl(BlamGLSLShaderUniform* uniform)
18  {
19  switch (uniform->GetType())
20  {
22  {
23  BlamShaderUniform1F* uniform_1f = (BlamShaderUniform1F*)uniform;
24  ImGui::DragFloat(uniform->GetName().c_str(), &uniform_1f->x);
25  break;
26  }
27  default:
28  {
29  ImGui::TextColored(ImVec4(1, 0, 0, 1), std::string("unsupported uniform type, cannot modify uniform '" + uniform->GetName() + "'").c_str());
30  break;
31  }
32  }
33  }
34 
35  void GenerateShaderProgramControl(BlamGLSLShaderProgram* program)
36  {
37  if (ImGui::BeginTabBar("shader_editor_tabs"))
38  {
39  if (ImGui::BeginTabItem("shader information"))
40  {
41  std::string shader_id = "id: " + program->GetID();
42  std::string shader_program_id = "gl program id: " + std::to_string(program->GetGLProgramID());
43 
44  ImGui::Text(shader_id.c_str());
45  ImGui::Text(shader_program_id.c_str());
46 
47  ImGui::EndTabItem();
48  }
49 
50  if (ImGui::BeginTabItem("shader settings"))
51  {
52  if (ImGui::Button("update uniforms"))
53  {
54  program->UpdateUniforms();
55  }
56 
57  ImGui::Separator();
58 
59  if (ImGui::CollapsingHeader("uniforms"))
60  {
61  for (int i = 0; i < program->GetUniforms()->size(); i++)
62  {
63  GenerateUniformControl(program->GetUniforms()->at(i));
64  }
65  }
66 
67  if (ImGui::CollapsingHeader("vertex attributes"))
68  {
69  ImGui::Text("not yet implemented");
70  }
71 
72  ImGui::EndTabItem();
73  }
74 
75  ImGui::EndTabBar();
76  }
77  }
78 
79  public:
80  void Draw()
81  {
82  if (show)
83  {
84  if (ImGui::Begin("Shader Editor", &show))
85  {
86  ImGui::Columns(2);
87 
88  ImGui::SetColumnWidth(0, (200.0f * *Blam::Globals::GetGlobalAsFloat("ui_scale_factor")));
89 
90  if (ImGui::ListBoxHeader("", ImVec2(ImGui::GetColumnWidth() - 15, -1)))
91  {
92  std::map<std::string, BlamGLSLShaderProgram*>* programs = Blam::Rendering::OpenGL::GetShaderPrograms();
93  std::map<std::string, BlamGLSLShaderProgram*>::iterator it;
94 
95  for (it = programs->begin(); it != programs->end(); it++)
96  {
97  bool is_active_item = false;
98 
99  if (it->second == active_program)
100  {
101  is_active_item = true;
102  }
103 
104  if (ImGui::Selectable(it->second->GetID().c_str(), is_active_item))
105  {
106  active_program = it->second;
107  }
108 
109  if (ImGui::IsItemHovered())
110  {
111  ImGui::BeginTooltip();
112  ImGui::PushTextWrapPos(450.0f);
113  ImGui::Text("shader information");
114  ImGui::Separator();
115 
116  std::string shader_id = "id: " + it->second->GetID();
117  std::string shader_program_id = "gl program id: " + std::to_string(it->second->GetGLProgramID());
118 
119  ImGui::Text(shader_id.c_str());
120  ImGui::Text(shader_program_id.c_str());
121 
122  ImGui::PopTextWrapPos();
123  ImGui::EndTooltip();
124  }
125  }
126 
127  ImGui::ListBoxFooter();
128  }
129 
130  ImGui::NextColumn();
131 
132  if (!active_program)
133  {
134  ImGui::Text("select a shader to modify");
135  }
136  else
137  {
138  GenerateShaderProgramControl(active_program);
139  }
140  }
141  ImGui::End();
142  }
143  }
144  };
145 }
BlamGLSLShaderUniform
Definition: uniforms.h:26
BlamGLSLShaderProgram
Definition: shaders.h:47
BlamGLSLShaderProgram::UpdateUniforms
void UpdateUniforms()
Definition: BlamGLSLShaderProgram.cpp:106
BlamShaderUniform1F
Definition: uniforms.h:48
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:400
Blam::Rendering::OpenGL::GetShaderPrograms
BLAM std::map< std::string, BlamGLSLShaderProgram * > * GetShaderPrograms()
Definition: shaders.cpp:145
BlamShaderUniformType::U_Float1
@ U_Float1
Blam::DebugUI::Windows::GLShaderEditor
Class for the OpenGL shader editor.
Definition: opengl_shader_editor.hpp:12
shaders.h
BlamGLSLShaderProgram::GetUniforms
std::vector< BlamGLSLShaderUniform * > * GetUniforms()
Definition: BlamGLSLShaderProgram.cpp:154
Blam::DebugUI::ImGUIDrawingGroup::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: debug_ui.h:362
BlamGLSLShaderUniform::GetName
std::string GetName()
Definition: BlamGLSLShaderUniform.cpp:45
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
BlamShaderUniform1F::x
float x
Definition: uniforms.h:51
BlamGLSLShaderProgram::GetGLProgramID
GLuint GetGLProgramID()
Definition: BlamGLSLShaderProgram.cpp:114
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434
BlamGLSLShaderProgram::GetID
std::string GetID()
Definition: BlamGLSLShaderProgram.cpp:41
BlamGLSLShaderUniform::GetType
BlamShaderUniformType GetType()
Definition: BlamGLSLShaderUniform.cpp:13
Text
@ Text
Master text object that wraps around both BitmapText and DWText.
Definition: render_stack.h:73
Blam::DebugUI::Windows::GLShaderEditor::Draw
void Draw()
Draws the contents of the group.
Definition: opengl_shader_editor.hpp:80