mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
Tech ENABLE_GL_IMGUI_SHADERS - Render imgui using shaders
(cherry picked from commit prusa3d/PrusaSlicer@d0d89a4d5b)
This commit is contained in:
parent
8dc82e7a8d
commit
15bad7fc19
6 changed files with 140 additions and 41 deletions
11
resources/shaders/imgui.fs
Normal file
11
resources/shaders/imgui.fs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#version 110
|
||||||
|
|
||||||
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
|
varying vec2 Frag_UV;
|
||||||
|
varying vec4 Frag_Color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);
|
||||||
|
}
|
17
resources/shaders/imgui.vs
Normal file
17
resources/shaders/imgui.vs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#version 110
|
||||||
|
|
||||||
|
uniform mat4 ProjMtx;
|
||||||
|
|
||||||
|
attribute vec2 Position;
|
||||||
|
attribute vec2 UV;
|
||||||
|
attribute vec4 Color;
|
||||||
|
|
||||||
|
varying vec2 Frag_UV;
|
||||||
|
varying vec4 Frag_Color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Frag_UV = UV;
|
||||||
|
Frag_Color = Color;
|
||||||
|
gl_Position = ProjMtx * vec4(Position.xy, 0.0, 1.0);
|
||||||
|
}
|
|
@ -122,8 +122,7 @@ bool GLShaderProgram::init_from_texts(const std::string& name, const ShaderSourc
|
||||||
|
|
||||||
for (size_t i = 0; i < static_cast<size_t>(EShaderType::Count); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(EShaderType::Count); ++i) {
|
||||||
const std::string& source = sources[i];
|
const std::string& source = sources[i];
|
||||||
if (!source.empty())
|
if (!source.empty()) {
|
||||||
{
|
|
||||||
EShaderType type = static_cast<EShaderType>(i);
|
EShaderType type = static_cast<EShaderType>(i);
|
||||||
auto [result, id] = create_shader(type);
|
auto [result, id] = create_shader(type);
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -301,6 +300,17 @@ void GLShaderProgram::set_uniform(int id, const Matrix3d& value) const
|
||||||
set_uniform(id, (Matrix3f)value.cast<float>());
|
set_uniform(id, (Matrix3f)value.cast<float>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLShaderProgram::set_uniform(int id, const Matrix4f& value) const
|
||||||
|
{
|
||||||
|
if (id >= 0)
|
||||||
|
glsafe(::glUniformMatrix4fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data())));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLShaderProgram::set_uniform(int id, const Matrix4d& value) const
|
||||||
|
{
|
||||||
|
set_uniform(id, (Matrix4f)value.cast<float>());
|
||||||
|
}
|
||||||
|
|
||||||
void GLShaderProgram::set_uniform(int id, const Vec3f& value) const
|
void GLShaderProgram::set_uniform(int id, const Vec3f& value) const
|
||||||
{
|
{
|
||||||
if (id >= 0)
|
if (id >= 0)
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Slic3r {
|
||||||
|
|
||||||
class ColorRGB;
|
class ColorRGB;
|
||||||
class ColorRGBA;
|
class ColorRGBA;
|
||||||
|
|
||||||
class GLShaderProgram
|
class GLShaderProgram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -61,6 +62,8 @@ public:
|
||||||
void set_uniform(const char* name, const Transform3d& value) const { set_uniform(get_uniform_location(name), value); }
|
void set_uniform(const char* name, const Transform3d& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
void set_uniform(const char* name, const Matrix3f& value) const { set_uniform(get_uniform_location(name), value); }
|
void set_uniform(const char* name, const Matrix3f& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
void set_uniform(const char* name, const Matrix3d& value) const { set_uniform(get_uniform_location(name), value); }
|
void set_uniform(const char* name, const Matrix3d& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
|
void set_uniform(const char* name, const Matrix4f& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
|
void set_uniform(const char* name, const Matrix4d& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); }
|
void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); }
|
void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
void set_uniform(const char* name, const ColorRGB& value) const { set_uniform(get_uniform_location(name), value); }
|
void set_uniform(const char* name, const ColorRGB& value) const { set_uniform(get_uniform_location(name), value); }
|
||||||
|
@ -81,6 +84,8 @@ public:
|
||||||
void set_uniform(int id, const Transform3d& value) const;
|
void set_uniform(int id, const Transform3d& value) const;
|
||||||
void set_uniform(int id, const Matrix3f& value) const;
|
void set_uniform(int id, const Matrix3f& value) const;
|
||||||
void set_uniform(int id, const Matrix3d& value) const;
|
void set_uniform(int id, const Matrix3d& value) const;
|
||||||
|
void set_uniform(int id, const Matrix4f& value) const;
|
||||||
|
void set_uniform(int id, const Matrix4d& value) const;
|
||||||
void set_uniform(int id, const Vec3f& value) const;
|
void set_uniform(int id, const Vec3f& value) const;
|
||||||
void set_uniform(int id, const Vec3d& value) const;
|
void set_uniform(int id, const Vec3d& value) const;
|
||||||
void set_uniform(int id, const ColorRGB& value) const;
|
void set_uniform(int id, const ColorRGB& value) const;
|
||||||
|
|
|
@ -33,6 +33,8 @@ std::pair<bool, std::string> GLShadersManager::init()
|
||||||
|
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
|
|
||||||
|
// imgui shader
|
||||||
|
valid &= append_shader("imgui", { "imgui.vs", "imgui.fs" });
|
||||||
// basic shader, used to render all what was previously rendered using the immediate mode
|
// basic shader, used to render all what was previously rendered using the immediate mode
|
||||||
valid &= append_shader("flat_attr", { "flat_attr.vs", "flat.fs" });
|
valid &= append_shader("flat_attr", { "flat_attr.vs", "flat.fs" });
|
||||||
// basic shader for textures, used to render textures
|
// basic shader for textures, used to render textures
|
||||||
|
|
|
@ -29,13 +29,16 @@
|
||||||
#include "libslic3r/Utils.hpp"
|
#include "libslic3r/Utils.hpp"
|
||||||
#include "libslic3r/Color.hpp"
|
#include "libslic3r/Color.hpp"
|
||||||
#include "libslic3r/Shape/TextShape.hpp"
|
#include "libslic3r/Shape/TextShape.hpp"
|
||||||
|
|
||||||
#include "3DScene.hpp"
|
#include "3DScene.hpp"
|
||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
#include "Search.hpp"
|
#include "Search.hpp"
|
||||||
#include "BitmapCache.hpp"
|
#include "BitmapCache.hpp"
|
||||||
|
#include "GUI_App.hpp"
|
||||||
|
|
||||||
#include "../Utils/MacDarkMode.hpp"
|
#include "../Utils/MacDarkMode.hpp"
|
||||||
|
|
||||||
#include "nanosvg/nanosvg.h"
|
#include "nanosvg/nanosvg.h"
|
||||||
#include "nanosvg/nanosvgrast.h"
|
#include "nanosvg/nanosvgrast.h"
|
||||||
#include "OpenGLManager.hpp"
|
#include "OpenGLManager.hpp"
|
||||||
|
@ -2386,13 +2389,25 @@ void ImGuiWrapper::init_style()
|
||||||
|
|
||||||
void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
|
void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
|
||||||
{
|
{
|
||||||
|
if (draw_data == nullptr || draw_data->CmdListsCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GLShaderProgram* shader = wxGetApp().get_shader("imgui");
|
||||||
|
if (shader == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
const int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x);
|
const int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x);
|
||||||
const int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y);
|
const int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y);
|
||||||
if (fb_width == 0 || fb_height == 0)
|
if (fb_width == 0 || fb_height == 0)
|
||||||
return;
|
return;
|
||||||
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
|
||||||
|
GLShaderProgram* curr_shader = wxGetApp().get_current_shader();
|
||||||
|
if (curr_shader != nullptr)
|
||||||
|
curr_shader->stop_using();
|
||||||
|
|
||||||
|
shader->start_using();
|
||||||
|
|
||||||
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
|
||||||
|
@ -2400,45 +2415,72 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
|
||||||
GLint last_polygon_mode[2]; glsafe(::glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode));
|
GLint last_polygon_mode[2]; glsafe(::glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode));
|
||||||
GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport));
|
GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport));
|
||||||
GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box));
|
GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box));
|
||||||
|
GLint last_texture_env_mode; glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_texture_env_mode));
|
||||||
glsafe(::glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT));
|
glsafe(::glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT));
|
||||||
glsafe(::glEnable(GL_BLEND));
|
glsafe(::glEnable(GL_BLEND));
|
||||||
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||||
glsafe(::glDisable(GL_CULL_FACE));
|
glsafe(::glDisable(GL_CULL_FACE));
|
||||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||||
glsafe(::glDisable(GL_LIGHTING));
|
|
||||||
glsafe(::glDisable(GL_COLOR_MATERIAL));
|
|
||||||
glsafe(::glEnable(GL_SCISSOR_TEST));
|
glsafe(::glEnable(GL_SCISSOR_TEST));
|
||||||
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
|
|
||||||
glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY));
|
|
||||||
glsafe(::glEnableClientState(GL_COLOR_ARRAY));
|
|
||||||
glsafe(::glEnable(GL_TEXTURE_2D));
|
glsafe(::glEnable(GL_TEXTURE_2D));
|
||||||
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
|
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
|
||||||
glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE));
|
glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE));
|
||||||
GLint texture_env_mode = GL_MODULATE;
|
|
||||||
glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texture_env_mode));
|
|
||||||
glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE));
|
|
||||||
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound
|
|
||||||
|
|
||||||
// Setup viewport, orthographic projection matrix
|
// Setup viewport, orthographic projection matrix
|
||||||
// Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps.
|
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
||||||
glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
|
glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
|
||||||
glsafe(::glMatrixMode(GL_PROJECTION));
|
const float L = draw_data->DisplayPos.x;
|
||||||
glsafe(::glPushMatrix());
|
const float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||||
glsafe(::glLoadIdentity());
|
const float T = draw_data->DisplayPos.y;
|
||||||
glsafe(::glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f));
|
const float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
||||||
glsafe(::glMatrixMode(GL_MODELVIEW));
|
|
||||||
glsafe(::glPushMatrix());
|
Matrix4f ortho_projection;
|
||||||
glsafe(::glLoadIdentity());
|
ortho_projection <<
|
||||||
|
2.0f / (R - L), 0.0f, 0.0f, (R + L) / (L - R),
|
||||||
|
0.0f, 2.0f / (T - B), 0.0f, (T + B) / (B - T),
|
||||||
|
0.0f, 0.0f, -1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f;
|
||||||
|
|
||||||
|
shader->set_uniform("Texture", 0);
|
||||||
|
shader->set_uniform("ProjMtx", ortho_projection);
|
||||||
|
|
||||||
|
// Will project scissor/clipping rectangles into framebuffer space
|
||||||
|
const ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
||||||
|
const ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
||||||
|
|
||||||
// Render command lists
|
// Render command lists
|
||||||
ImVec2 pos = draw_data->DisplayPos;
|
|
||||||
for (int n = 0; n < draw_data->CmdListsCount; ++n) {
|
for (int n = 0; n < draw_data->CmdListsCount; ++n) {
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
||||||
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
||||||
glsafe(::glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos))));
|
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
|
||||||
glsafe(::glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv))));
|
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
|
||||||
glsafe(::glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col))));
|
|
||||||
|
GLuint vbo_id;
|
||||||
|
glsafe(::glGenBuffers(1, &vbo_id));
|
||||||
|
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id));
|
||||||
|
glsafe(::glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, vtx_buffer, GL_STATIC_DRAW));
|
||||||
|
|
||||||
|
GLuint ibo_id;
|
||||||
|
glsafe(::glGenBuffers(1, &ibo_id));
|
||||||
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id));
|
||||||
|
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, idx_buffer, GL_STATIC_DRAW));
|
||||||
|
|
||||||
|
const int position_id = shader->get_attrib_location("Position");
|
||||||
|
if (position_id != -1) {
|
||||||
|
glsafe(::glVertexAttribPointer(position_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)));
|
||||||
|
glsafe(::glEnableVertexAttribArray(position_id));
|
||||||
|
}
|
||||||
|
const int uv_id = shader->get_attrib_location("UV");
|
||||||
|
if (uv_id != -1) {
|
||||||
|
glsafe(::glVertexAttribPointer(uv_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)));
|
||||||
|
glsafe(::glEnableVertexAttribArray(uv_id));
|
||||||
|
}
|
||||||
|
const int color_id = shader->get_attrib_location("Color");
|
||||||
|
if (color_id != -1) {
|
||||||
|
glsafe(::glVertexAttribPointer(color_id, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)));
|
||||||
|
glsafe(::glEnableVertexAttribArray(color_id));
|
||||||
|
}
|
||||||
|
|
||||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; ++cmd_i) {
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; ++cmd_i) {
|
||||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||||
|
@ -2446,34 +2488,46 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
|
||||||
// User callback (registered via ImDrawList::AddCallback)
|
// User callback (registered via ImDrawList::AddCallback)
|
||||||
pcmd->UserCallback(cmd_list, pcmd);
|
pcmd->UserCallback(cmd_list, pcmd);
|
||||||
else {
|
else {
|
||||||
ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y);
|
// Project scissor/clipping rectangles into framebuffer space
|
||||||
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) {
|
const ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||||
// Apply scissor/clipping rectangle
|
const ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
||||||
glsafe(::glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y)));
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Bind texture, Draw
|
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId));
|
glsafe(::glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
|
||||||
glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer));
|
|
||||||
}
|
// Bind texture, Draw
|
||||||
|
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
|
||||||
|
glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))));
|
||||||
}
|
}
|
||||||
idx_buffer += pcmd->ElemCount;
|
idx_buffer += pcmd->ElemCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (position_id != -1)
|
||||||
|
glsafe(::glDisableVertexAttribArray(position_id));
|
||||||
|
if (uv_id != -1)
|
||||||
|
glsafe(::glDisableVertexAttribArray(uv_id));
|
||||||
|
if (color_id != -1)
|
||||||
|
glsafe(::glDisableVertexAttribArray(color_id));
|
||||||
|
|
||||||
|
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
|
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||||
|
|
||||||
|
glsafe(::glDeleteBuffers(1, &ibo_id));
|
||||||
|
glsafe(::glDeleteBuffers(1, &vbo_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore modified state
|
// Restore modified state
|
||||||
glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_env_mode));
|
glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_texture_env_mode));
|
||||||
glsafe(::glDisableClientState(GL_COLOR_ARRAY));
|
|
||||||
glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY));
|
|
||||||
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
|
|
||||||
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture));
|
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture));
|
||||||
glsafe(::glMatrixMode(GL_MODELVIEW));
|
|
||||||
glsafe(::glPopMatrix());
|
|
||||||
glsafe(::glMatrixMode(GL_PROJECTION));
|
|
||||||
glsafe(::glPopMatrix());
|
|
||||||
glsafe(::glPopAttrib());
|
glsafe(::glPopAttrib());
|
||||||
glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]));
|
glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]));
|
||||||
glsafe(::glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]));
|
glsafe(::glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]));
|
||||||
glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]));
|
glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]));
|
||||||
|
|
||||||
|
if (curr_shader != nullptr)
|
||||||
|
curr_shader->start_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGuiWrapper::display_initialized() const
|
bool ImGuiWrapper::display_initialized() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue