Elaztek Developer Hub
Blamite Game Engine - blam!  00346.12.11.21.0529.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 
48  }
49 
50  if (ImGui::BeginTabItem("shader settings"))
51  {
52  if (ImGui::Button("update uniforms"))
53  {
54  program->UpdateUniforms();
55  }
56 
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 
73  }
74 
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 
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  {
112  ImGui::PushTextWrapPos(450.0f);
113  ImGui::Text("shader information");
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 
124  }
125  }
126 
128  }
129 
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
ImGui::BeginTooltip
IMGUI_API void BeginTooltip()
Definition: imgui.cpp:7362
ImGui::ListBoxFooter
IMGUI_API void ListBoxFooter()
Definition: imgui_widgets.cpp:5668
ImVec4
Definition: imgui.h:192
BlamGLSLShaderProgram::UpdateUniforms
void UpdateUniforms()
Definition: BlamGLSLShaderProgram.cpp:106
ImGui::NextColumn
IMGUI_API void NextColumn()
Definition: imgui_widgets.cpp:7445
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:407
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
ImGui::SetColumnWidth
IMGUI_API void SetColumnWidth(int column_index, float width)
Definition: imgui_widgets.cpp:7297
ImGui::EndTabItem
IMGUI_API void EndTabItem()
Definition: imgui_widgets.cpp:6851
Blam::Rendering::OpenGL::GetShaderPrograms
BLAM std::map< std::string, BlamGLSLShaderProgram * > * GetShaderPrograms()
Definition: shaders.cpp:145
ImVec2
Definition: imgui.h:179
ImGui::IsItemHovered
IMGUI_API bool IsItemHovered(ImGuiHoveredFlags flags=0)
Definition: imgui.cpp:3061
BlamShaderUniformType::U_Float1
@ U_Float1
ImGui::DragFloat
IMGUI_API bool DragFloat(const char *label, float *v, float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2164
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
Blam::DebugUI::Windows::GLShaderEditor
Class for the OpenGL shader editor.
Definition: opengl_shader_editor.hpp:12
ImGui::GetColumnWidth
IMGUI_API float GetColumnWidth(int column_index=-1)
Definition: imgui_widgets.cpp:7262
NULL
Add a fourth parameter to bake specific font ranges NULL
Definition: README.txt:57
ImGui::BeginTabBar
IMGUI_API bool BeginTabBar(const char *str_id, ImGuiTabBarFlags flags=0)
Definition: imgui_widgets.cpp:6366
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
ImGui::PopTextWrapPos
IMGUI_API void PopTextWrapPos()
Definition: imgui.cpp:6313
shaders.h
BlamGLSLShaderProgram::GetUniforms
std::vector< BlamGLSLShaderUniform * > * GetUniforms()
Definition: BlamGLSLShaderProgram.cpp:154
ImGui::EndTooltip
IMGUI_API void EndTooltip()
Definition: imgui.cpp:7402
ImGui::Selectable
IMGUI_API bool Selectable(const char *label, bool selected=false, ImGuiSelectableFlags flags=0, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:5469
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
ImGui::Columns
IMGUI_API void Columns(int count=1, const char *id=NULL, bool border=true)
Definition: imgui_widgets.cpp:7572
BlamShaderUniform1F::x
float x
Definition: uniforms.h:51
ImGui::EndTabBar
IMGUI_API void EndTabBar()
Definition: imgui_widgets.cpp:6432
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
BlamGLSLShaderProgram::GetGLProgramID
GLuint GetGLProgramID()
Definition: BlamGLSLShaderProgram.cpp:114
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: ui.h:14
BlamGLSLShaderProgram::GetID
std::string GetID()
Definition: BlamGLSLShaderProgram.cpp:41
BlamGLSLShaderUniform::GetType
BlamShaderUniformType GetType()
Definition: BlamGLSLShaderUniform.cpp:13
ImGui::PushTextWrapPos
IMGUI_API void PushTextWrapPos(float wrap_local_pos_x=0.0f)
Definition: imgui.cpp:6306
ImGui::TextColored
IMGUI_API void TextColored(const ImVec4 &col, const char *fmt,...) IM_FMTARGS(2)
Definition: imgui_widgets.cpp:257
ImGui::BeginTabItem
IMGUI_API bool BeginTabItem(const char *label, bool *p_open=NULL, ImGuiTabItemFlags flags=0)
Definition: imgui_widgets.cpp:6829
ImGui::ListBoxHeader
IMGUI_API bool ListBoxHeader(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:5614
ImGui::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:644
Blam::DebugUI::Windows::GLShaderEditor::Draw
void Draw()
Draws the contents of the group.
Definition: opengl_shader_editor.hpp:80