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

@@ -32,6 +32,7 @@
#include <openspace/documentation/verifier.h>
#include <ghoul/glm.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
namespace {
@@ -233,21 +234,6 @@ void RenderableCartesianAxes::render(const RenderData& data, RendererTasks&){
_program->setUniform("yColor", _yColor);
_program->setUniform("zColor", _zColor);
// Saves current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLenum blendEquationRGB, blendEquationAlpha, blendDestAlpha,
blendDestRGB, blendSrcAlpha, 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);
// Changes GL state:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnablei(GL_BLEND, 0);
@@ -261,15 +247,8 @@ void RenderableCartesianAxes::render(const RenderData& data, RendererTasks&){
_program->deactivate();
// Restores GL State
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();
}
} // namespace openspace