OpenGL State Caching.

This commit is contained in:
Jonathas Costa
2020-07-31 15:59:28 -04:00
parent 11f537e2e2
commit 393fbdca3d
20 changed files with 95 additions and 365 deletions

View File

@@ -35,6 +35,7 @@
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
namespace {
@@ -290,25 +291,6 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
_program->setUniform("projectionTransform", data.camera.projectionMatrix());
_program->setUniform("color", glm::vec4(_lineColor.value(), _opacity));
// Save current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
GLenum blendDestAlpha;
GLenum blendDestRGB;
GLenum blendSrcAlpha;
GLenum blendSrcRGB;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
// Change GL state:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnablei(GL_BLEND, 0);
@@ -322,15 +304,8 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
// Restore GL State
unbindGL();
_program->deactivate();
glLineWidth(currentLineWidth);
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
if (!isBlendEnabled) {
glDisablei(GL_BLEND, 0);
}
if (!isLineSmoothEnabled) {
glDisable(GL_LINE_SMOOTH);
}
global::renderEngine.openglStateCache().setBlendState();
global::renderEngine.openglStateCache().setLineState();
}
void RenderableNodeLine::validateNodes() {