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

@@ -31,7 +31,7 @@ local vrt_folders = {
-- We recommend using this folder for HiRISE
openspace.absPath('${BASE}/../OpenSpaceData/Mars/HiRISE'),
-- if not and you have a custom path for HiRISE layers, enter it below
'',
'/media/jccosta/Big SSD Data/Pessoal/Work/OpenSpaceData/Mars-Gale-Crater/CTX',
},
Moon = {
-- Add folders here whose contents will be automatically added to the Moon globe

View File

@@ -6,6 +6,8 @@ asset.request('./planets/venus/atmosphere')
asset.request('./planets/earth/earth')
asset.request('./planets/earth/atmosphere')
asset.request('./planets/earth/markers')
asset.request('./planets/earth/nycmodel/upperMan.asset')
asset.request('./planets/earth/nycmodel/lowerMan.asset')
asset.request('./planets/earth/moon/moon')
asset.request('./planets/mars/mars')

View File

@@ -39,7 +39,7 @@ namespace ghoul {
class SharedMemory;
} // ghoul
namespace ghoul::fontrendering { class Font; }
namespace ghoul::opengl { class ProgramObject; }
namespace ghoul::opengl { class ProgramObject; class OpenGLStateCache; }
namespace openspace {
@@ -77,6 +77,8 @@ public:
const Renderer& renderer() const;
RendererImplementation rendererImplementation() const;
ghoul::opengl::OpenGLStateCache& openglStateCache();
void updateShaderPrograms();
void updateRenderer();
void updateScreenSpaceRenderables();
@@ -187,6 +189,8 @@ private:
ghoul::Dictionary _resolveData;
ScreenLog* _log = nullptr;
ghoul::opengl::OpenGLStateCache* _openglStateCache;
properties::BoolProperty _showOverlayOnSlaves;
properties::BoolProperty _showLog;
properties::FloatProperty _verticalLogOffset;

View File

@@ -72,6 +72,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -836,24 +837,7 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
ghoul::opengl::TextureUnit deltaSMieTableTextureUnit;
ghoul::opengl::TextureUnit deltaJTableTextureUnit;
// Saving current OpenGL state
GLboolean blendEnabled = glIsEnabled(GL_BLEND);
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
GLenum blendDestAlpha;
GLenum blendDestRGB;
GLenum blendSrcAlpha;
GLenum blendSrcRGB;
if (blendEnabled) {
glDisable(GL_BLEND);
}
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);
glDisable(GL_BLEND);
// ===========================================================
// See Precomputed Atmosphere Scattering from Bruneton et al. paper, algorithm 4.1:
@@ -1199,12 +1183,7 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
}
// Restores OpenGL blending state
if (blendEnabled) {
glEnable(GL_BLEND);
}
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
global::renderEngine.openglStateCache().setBlendState();
}
void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
@@ -1223,9 +1202,9 @@ void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
global::renderEngine.openglStateCache().viewPort(m_viewport);
// Creates the FBO for the calculations
// Creates the FBO for the cFglGetalculations
GLuint calcFBO;
glGenFramebuffers(1, &calcFBO);
glBindFramebuffer(GL_FRAMEBUFFER, calcFBO);
@@ -1249,12 +1228,7 @@ void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
// Restores system state
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glViewport(
m_viewport[0],
m_viewport[1],
m_viewport[2],
m_viewport[3]
);
global::renderEngine.openglStateCache().setViewPortState(m_viewport);
glDeleteBuffers(1, &quadCalcVBO);
glDeleteVertexArrays(1, &quadCalcVAO);
glDeleteFramebuffers(1, &calcFBO);

View File

@@ -32,6 +32,7 @@
#include <openspace/util/updatestructures.h>
#include <openspace/documentation/verifier.h>
#include <ghoul/glm.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/opengl/programobject.h>
@@ -189,25 +190,6 @@ void RenderableBoxGrid::render(const RenderData& data, RendererTasks&){
_gridProgram->setUniform("gridColor", _gridColor);
// Saves current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
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);
// Changes GL state:
glLineWidth(_lineWidth);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -221,17 +203,8 @@ void RenderableBoxGrid::render(const RenderData& data, RendererTasks&){
_gridProgram->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();
}
void RenderableBoxGrid::update(const UpdateData&) {

View File

@@ -33,6 +33,7 @@
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/glm.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
namespace {
@@ -205,25 +206,6 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){
_gridProgram->setUniform("gridColor", _gridColor);
// Saves current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
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);
// Changes GL state:
glLineWidth(_lineWidth);
glEnablei(GL_BLEND, 0);
@@ -237,17 +219,8 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){
_gridProgram->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();
}
void RenderableGrid::update(const UpdateData&) {

View File

@@ -33,6 +33,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 {
@@ -266,25 +267,6 @@ void RenderableRadialGrid::render(const RenderData& data, RendererTasks&) {
adjustedLineWidth = _lineWidth;
#endif
// Saves current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
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);
// Changes GL state:
glLineWidth(adjustedLineWidth);
glEnablei(GL_BLEND, 0);
@@ -300,17 +282,8 @@ void RenderableRadialGrid::render(const RenderData& data, RendererTasks&) {
_gridProgram->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();
}
void RenderableRadialGrid::update(const UpdateData&) {

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 {
@@ -209,25 +210,6 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){
adjustedLineWidth = _lineWidth;
#endif
// Saves current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
GLenum currentDepthFunction;
glGetIntegerv(GL_DEPTH_FUNC, &currentDepthFunction);
glDepthFunc(GL_LEQUAL);
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:
glLineWidth(adjustedLineWidth);
glEnablei(GL_BLEND, 0);
@@ -242,19 +224,8 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){
_gridProgram->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);
}
glDepthFunc(currentDepthFunction);
global::renderEngine.openglStateCache().setBlendState();
global::renderEngine.openglStateCache().setLineState();
}
void RenderableSphericalGrid::update(const UpdateData&) {

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

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() {

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/windowdelegate.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/opengl/framebufferobject.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/textureunit.h>
namespace {
@@ -111,13 +112,16 @@ void ScreenSpaceFramebuffer::render() {
if (!_renderFunctions.empty()) {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
//glGetIntegerv(GL_VIEWPORT, viewport);
global::renderEngine.openglStateCache().viewPort(viewport);
glViewport(
static_cast<GLint>(-size.x * xratio),
static_cast<GLint>(-size.y * yratio),
static_cast<GLsizei>(resolution.x * xratio),
static_cast<GLsizei>(resolution.y * yratio)
);
global::renderEngine.openglStateCache().setViewPortState(viewport);
GLint defaultFBO = _framebuffer->getActiveObject();
_framebuffer->activate();

View File

@@ -37,6 +37,7 @@
#include <ghoul/misc/templatefactory.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -779,28 +780,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
float fadeInVariable)
{
glDepthMask(false);
glEnable(GL_DEPTH_TEST);
// Saving current OpenGL state
GLboolean blendEnabled = glIsEnabledi(GL_BLEND, 0);
GLenum blendEquationRGB;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
GLenum blendEquationAlpha;
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
GLenum blendDestAlpha;
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
GLenum blendDestRGB;
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
GLenum blendSrcAlpha;
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
GLenum blendSrcRGB;
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
glEnablei(GL_BLEND, 0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
@@ -868,15 +847,8 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
glBindVertexArray(0);
_program->deactivate();
// Restores blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
if (!blendEnabled) {
glDisablei(GL_BLEND, 0);
}
glDepthMask(true);
global::renderEngine.openglStateCache().setBlendState();
global::renderEngine.openglStateCache().setDepthState();
}

View File

@@ -38,6 +38,7 @@
#include <ghoul/misc/templatefactory.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -448,30 +449,6 @@ void RenderableDUMeshes::renderMeshes(const RenderData&,
const glm::dmat4& modelViewMatrix,
const glm::dmat4& projectionMatrix)
{
// Saving current OpenGL state
GLfloat lineWidth = 1.0f;
glGetFloatv(GL_LINE_WIDTH, &lineWidth);
GLboolean blendEnabled = glIsEnabledi(GL_BLEND, 0);
GLenum blendEquationRGB;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
GLenum blendEquationAlpha;
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
GLenum blendDestAlpha;
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
GLenum blendDestRGB;
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
GLenum blendSrcAlpha;
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
GLenum blendSrcRGB;
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
glEnablei(GL_BLEND, 0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -495,7 +472,7 @@ void RenderableDUMeshes::renderMeshes(const RenderData&,
case Wire:
glLineWidth(_lineWidth);
glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV);
glLineWidth(lineWidth);
global::renderEngine.openglStateCache().setLineState();
break;
case Point:
glDrawArrays(GL_POINTS, 0, pair.second.numV);
@@ -509,15 +486,9 @@ void RenderableDUMeshes::renderMeshes(const RenderData&,
glBindVertexArray(0);
_program->deactivate();
// Restores blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
glDepthMask(true);
if (!blendEnabled) {
glDisablei(GL_BLEND, 0);
}
// Restores GL State
global::renderEngine.openglStateCache().setDepthState();
global::renderEngine.openglStateCache().setBlendState();
}
void RenderableDUMeshes::renderLabels(const RenderData& data,

View File

@@ -35,6 +35,7 @@
#include <ghoul/font/fontrenderer.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -547,27 +548,6 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
const glm::dmat4& projectionMatrix,
const float fadeInVariable)
{
// Saving current OpenGL state
GLboolean blendEnabled = glIsEnabledi(GL_BLEND, 0);
GLenum blendEquationRGB;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
GLenum blendEquationAlpha;
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
GLenum blendDestAlpha;
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
GLenum blendDestRGB;
glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB);
GLenum blendSrcAlpha;
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha);
GLenum blendSrcRGB;
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
glEnablei(GL_BLEND, 0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -610,15 +590,9 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
glBindVertexArray(0);
_program->deactivate();
// Restores blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
glDepthMask(true);
if (!blendEnabled) {
glDisablei(GL_BLEND, 0);
}
// Restores OpenGL Rendering State
global::renderEngine.openglStateCache().setBlendState();
global::renderEngine.openglStateCache().setDepthState();
}
void RenderablePlanesCloud::renderLabels(const RenderData& data,

View File

@@ -41,6 +41,7 @@
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -632,23 +633,6 @@ void RenderableGalaxy::renderPoints(const RenderData& data) {
if (!_pointsProgram) {
return;
}
// Saving current OpenGL state
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
GLenum blendDestAlpha;
GLenum blendDestRGB;
GLenum blendSrcAlpha;
GLenum blendSrcRGB;
GLboolean depthMask;
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);
glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDepthMask(false);
@@ -697,14 +681,9 @@ void RenderableGalaxy::renderPoints(const RenderData& data) {
_pointsProgram->deactivate();
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Restores OpenGL blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
glDepthMask(depthMask);
// Restores OpenGL Rendering State
global::renderEngine.openglStateCache().setBlendState();
global::renderEngine.openglStateCache().setDepthState();
}
void RenderableGalaxy::renderBillboards(const RenderData& data) {

View File

@@ -32,6 +32,7 @@
#include <modules/globebrowsing/src/rawtiledatareader.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/timemanager.h>
#include <ghoul/filesystem/file.h>
@@ -41,6 +42,7 @@
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/openglstatecache.h>
#include <fstream>
#include "cpl_minixml.h"
@@ -209,9 +211,9 @@ Tile tile(TextTileProvider& t, const TileIndex& tileIndex) {
// Keep track of defaultFBO and viewport to be able to reset state when done
GLint defaultFBO;
GLint viewport[4];
//GLint viewport[4];
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
glGetIntegerv(GL_VIEWPORT, viewport);
//glGetIntegerv(GL_VIEWPORT, viewport);
// Render to texture
glBindFramebuffer(GL_FRAMEBUFFER, t.fbo);
@@ -232,7 +234,8 @@ Tile tile(TextTileProvider& t, const TileIndex& tileIndex) {
t.fontRenderer->render(*t.font, t.textPosition, t.text, t.textColor);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
global::renderEngine.openglStateCache().setViewPortState();
//glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
tile = Tile{ texture, std::nullopt, Tile::Status::OK };
t.tileCache->put(key, t.initData.hashKey, tile);

View File

@@ -36,6 +36,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/templatefactory.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -823,23 +824,8 @@ void RenderableStars::renderPSFToTexture() {
GLint defaultFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
// Saving current OpenGL state
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);
// GLint m_viewport[4];
// global::renderEngine.openglStateCache().viewPort(m_viewport);
// Creates the FBO for the calculations
GLuint psfFBO;
@@ -941,8 +927,7 @@ void RenderableStars::renderPSFToTexture() {
//glDeleteFramebuffers(1, &convolveFBO);
// Restores OpenGL blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
global::renderEngine.openglStateCache().setBlendState();
}
void RenderableStars::render(const RenderData& data, RendererTasks&) {

View File

@@ -43,6 +43,7 @@
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/textureunit.h>
#include <fstream>
#include <string>
@@ -474,8 +475,22 @@ void FramebufferRenderer::initialize() {
global::raycasterManager.addListener(*this);
global::deferredcasterManager.addListener(*this);
// Set Default Rendering OpenGL State
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
glEnablei(GL_BLEND, 0);
glDisablei(GL_BLEND, 1);
glDisablei(GL_BLEND, 2);
glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE);
glEnable(GL_DEPTH_TEST);
// Default GL State for Blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Save State in Cache
global::renderEngine.openglStateCache().loadCurrentGLState();
}
void FramebufferRenderer::deinitialize() {
@@ -1159,22 +1174,14 @@ void FramebufferRenderer::updateDownscaledVolume() {
void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFactor) {
ZoneScoped
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
global::renderEngine.openglStateCache().viewPort(viewport);
{
// Set OpenGL default rendering state
ZoneScopedN("Setting OpenGL state")
// Set Render Pipeline State
global::renderEngine.openglStateCache().setCachedStates();
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
glEnablei(GL_BLEND, 0);
glDisablei(GL_BLEND, 1);
glDisablei(GL_BLEND, 2);
glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE);
glEnable(GL_DEPTH_TEST);
}
_pingPongIndex = 0;
// Measurements cache variable
@@ -1531,6 +1538,9 @@ void FramebufferRenderer::performDeferredTasks(
void FramebufferRenderer::setResolution(glm::ivec2 res) {
_resolution = std::move(res);
_dirtyResolution = true;
GLint newViewPortCoors[4];
glGetIntegerv(GL_VIEWPORT, newViewPortCoors);
global::renderEngine.openglStateCache().setViewPortState(newViewPortCoors);
}
void FramebufferRenderer::setDisableHDR(bool disable) {

View File

@@ -57,6 +57,7 @@
#include <ghoul/misc/profiling.h>
#include <ghoul/misc/stringconversion.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
#ifdef GHOUL_USE_DEVIL
@@ -944,6 +945,13 @@ RenderEngine::RendererImplementation RenderEngine::rendererImplementation() cons
return _rendererImplementation;
}
ghoul::opengl::OpenGLStateCache& RenderEngine::openglStateCache() {
if (_openglStateCache == nullptr) {
_openglStateCache = ghoul::opengl::OpenGLStateCache::getInstance();
}
return *_openglStateCache;
}
float RenderEngine::globalBlackOutFactor() {
return _globalBlackOutFactor;
}