Merge pull request #1288 from OpenSpace/feature/openglstatecache

Feature/openglstatecache
This commit is contained in:
Alexander Bock
2020-09-04 16:20:09 +02:00
committed by GitHub
22 changed files with 112 additions and 405 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
'',
''
},
Moon = {
-- Add folders here whose contents will be automatically added to the Moon globe

View File

@@ -35,11 +35,15 @@
#include <openspace/properties/triggerproperty.h>
namespace ghoul {
namespace fontrendering { class Font; }
namespace opengl {
class ProgramObject;
class OpenGLStateCache;
} // namespace opengl
class Dictionary;
class SharedMemory;
} // ghoul
namespace ghoul::fontrendering { class Font; }
namespace ghoul::opengl { class ProgramObject; }
namespace openspace {
@@ -77,6 +81,8 @@ public:
const Renderer& renderer() const;
RendererImplementation rendererImplementation() const;
ghoul::opengl::OpenGLStateCache& openglStateCache();
void updateShaderPrograms();
void updateRenderer();
void updateScreenSpaceRenderables();
@@ -185,6 +191,8 @@ private:
ghoul::Dictionary _resolveData;
ScreenLog* _log = nullptr;
ghoul::opengl::OpenGLStateCache* _openglStateCache;
properties::BoolProperty _showOverlayOnSlaves;
properties::BoolProperty _showLog;
properties::FloatProperty _verticalLogOffset;

View File

@@ -29,6 +29,7 @@
#include <chrono>
#include <mutex>
#include <string_view>
#include <vector>
namespace openspace {

View File

@@ -72,6 +72,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.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>
@@ -851,24 +852,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:
@@ -1214,12 +1198,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().resetBlendState();
}
void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
@@ -1238,7 +1217,7 @@ 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
GLuint calcFBO;
@@ -1264,12 +1243,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

@@ -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 {
@@ -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().resetBlendState();
global::renderEngine.openglStateCache().resetLineState();
}
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().resetBlendState();
global::renderEngine.openglStateCache().resetLineState();
}
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().resetBlendState();
global::renderEngine.openglStateCache().resetLineState();
}
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().resetBlendState();
global::renderEngine.openglStateCache().resetLineState();
}
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().resetBlendState();
global::renderEngine.openglStateCache().resetLineState();
}
} // 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().resetBlendState();
global::renderEngine.openglStateCache().resetLineState();
}
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

@@ -38,6 +38,7 @@
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -797,28 +798,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);
@@ -886,15 +865,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().resetBlendState();
global::renderEngine.openglStateCache().resetDepthState();
}

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>
@@ -401,30 +402,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);
@@ -447,7 +424,7 @@ void RenderableDUMeshes::renderMeshes(const RenderData&,
case Wire:
glLineWidth(_lineWidth);
glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV);
glLineWidth(lineWidth);
global::renderEngine.openglStateCache().resetLineState();
break;
case Point:
glDrawArrays(GL_POINTS, 0, pair.second.numV);
@@ -461,15 +438,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().resetDepthState();
global::renderEngine.openglStateCache().resetBlendState();
}
void RenderableDUMeshes::renderLabels(const RenderData& data,

View File

@@ -36,6 +36,7 @@
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/openglstatecache.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
@@ -546,27 +547,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);
@@ -609,15 +589,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().resetBlendState();
global::renderEngine.openglStateCache().resetDepthState();
}
void RenderablePlanesCloud::renderLabels(const RenderData& data,

View File

@@ -42,6 +42,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.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>
@@ -642,23 +643,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);
@@ -707,14 +691,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().resetBlendState();
global::renderEngine.openglStateCache().resetDepthState();
}
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 <openspace/util/spicemanager.h>
@@ -42,6 +43,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"
@@ -210,9 +212,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);
@@ -233,7 +235,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().resetViewportState();
//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

@@ -41,9 +41,9 @@ namespace {
" %i: %i/%i (%.2f/%.2f kiB)",
i,
occupancies[i],
p.BucketSize,
p._bucketSize,
occupancies[i] / 1024.f,
p.BucketSize / 1024.f
p._bucketSize / 1024.f
);
}
}

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>
@@ -811,23 +812,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;
@@ -929,8 +915,7 @@ void RenderableStars::renderPSFToTexture() {
//glDeleteFramebuffers(1, &convolveFBO);
// Restores OpenGL blending state
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
global::renderEngine.openglStateCache().resetBlendState();
}
void RenderableStars::render(const RenderData& data, RendererTasks&) {

View File

@@ -37,6 +37,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/misc/memorypool.h>
#include <ghoul/misc/templatefactory.h>
namespace {

View File

@@ -41,6 +41,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>
@@ -95,31 +96,7 @@ namespace {
constexpr const char* RenderFragmentShaderPath =
"${SHADERS}/framebuffer/renderframebuffer.frag";
const GLenum ColorAttachment0Array[1] = {
GL_COLOR_ATTACHMENT0
};
const GLenum ColorAttachment1Array[1] = {
GL_COLOR_ATTACHMENT1
};
const GLenum ColorAttachment01Array[2] = {
GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT1
};
const GLenum ColorAttachment03Array[2] = {
GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT3
};
const GLenum ColorAttachment012Array[3] = {
GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT1,
GL_COLOR_ATTACHMENT2
};
const GLenum ColorAttachment0123Array[4] = {
const GLenum ColorAttachmentArray[4] = {
GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT1,
GL_COLOR_ATTACHMENT2,
@@ -475,8 +452,21 @@ 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() {
@@ -1154,22 +1144,14 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac
ZoneScoped
TracyGpuZone("FramebufferRenderer")
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
{
// Set OpenGL default rendering state
ZoneScopedN("Setting OpenGL state")
GLint viewport[4] = { 0 };
global::renderEngine.openglStateCache().viewport(viewport);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
glEnablei(GL_BLEND, 0);
glDisablei(GL_BLEND, 1);
glDisablei(GL_BLEND, 2);
// Reset Render Pipeline State
global::renderEngine.openglStateCache().resetCachedStates();
glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE);
glEnable(GL_DEPTH_TEST);
}
_pingPongIndex = 0;
if (!scene || !camera) {
@@ -1181,10 +1163,11 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac
ZoneScopedN("Deferred G-Buffer")
TracyGpuZone("Deferred G-Buffer")
glViewport(0, 0, _resolution.x, _resolution.y);
GLint vp[4] = {viewport[0], viewport[1], _resolution.x, _resolution.y};
global::renderEngine.openglStateCache().setViewportState(vp);
glBindFramebuffer(GL_FRAMEBUFFER, _gBuffers.framebuffer);
glDrawBuffers(3, ColorAttachment012Array);
glDrawBuffers(3, ColorAttachmentArray);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
Time time = global::timeManager.time();
@@ -1239,12 +1222,12 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac
// render to the same final buffer, multiple
// deferred tasks at same time (e.g. more than 1 ATM being seen at once)
glBindFramebuffer(GL_FRAMEBUFFER, _pingPongBuffers.framebuffer);
glDrawBuffers(1, &ColorAttachment01Array[_pingPongIndex]);
glDrawBuffers(1, &ColorAttachmentArray[_pingPongIndex]);
performDeferredTasks(tasks.deferredcasterTasks);
}
glDrawBuffers(1, &ColorAttachment01Array[_pingPongIndex]);
glDrawBuffers(1, &ColorAttachmentArray[_pingPongIndex]);
glEnablei(GL_BLEND, 0);
{
@@ -1268,11 +1251,9 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac
// Disabling depth test for filtering and hdr
glDisable(GL_DEPTH_TEST);
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
if (_enableFXAA) {
glBindFramebuffer(GL_FRAMEBUFFER, _fxaaBuffers.fxaaFramebuffer);
glDrawBuffers(1, ColorAttachment0Array);
glDrawBuffers(1, ColorAttachmentArray);
glDisable(GL_BLEND);
}
@@ -1308,8 +1289,8 @@ void FramebufferRenderer::performRaycasterTasks(const std::vector<RaycasterTask>
glBindFramebuffer(GL_FRAMEBUFFER, _exitFramebuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
GLint viewport[4] = { 0 };
global::renderEngine.openglStateCache().viewport(viewport);
ghoul::opengl::ProgramObject* exitProgram = _exitPrograms[raycaster].get();
if (exitProgram) {
@@ -1321,12 +1302,14 @@ void FramebufferRenderer::performRaycasterTasks(const std::vector<RaycasterTask>
if (raycaster->downscaleRender() < 1.f) {
glBindFramebuffer(GL_FRAMEBUFFER, _downscaleVolumeRendering.framebuffer);
const float s = raycaster->downscaleRender();
glViewport(
GLint newVP[4] = {
viewport[0],
viewport[1],
static_cast<GLsizei>(viewport[2] * s),
static_cast<GLsizei>(viewport[3] * s)
);
};
global::renderEngine.openglStateCache().setViewportState(newVP);
if (_downscaleVolumeRendering.currentDownscaleFactor != s) {
_downscaleVolumeRendering.currentDownscaleFactor = s;
updateDownscaleTextures();
@@ -1422,7 +1405,7 @@ void FramebufferRenderer::performRaycasterTasks(const std::vector<RaycasterTask>
}
if (raycaster->downscaleRender() < 1.f) {
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
global::renderEngine.openglStateCache().setViewportState(viewport);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _gBuffers.framebuffer);
writeDownscaledVolume();
}
@@ -1450,7 +1433,7 @@ void FramebufferRenderer::performDeferredTasks(
if (deferredcastProgram) {
_pingPongIndex = _pingPongIndex == 0 ? 1 : 0;
int fromIndex = _pingPongIndex == 0 ? 1 : 0;
glDrawBuffers(1, &ColorAttachment01Array[_pingPongIndex]);
glDrawBuffers(1, &ColorAttachmentArray[_pingPongIndex]);
glDisablei(GL_BLEND, 0);
glDisablei(GL_BLEND, 1);

View File

@@ -56,6 +56,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
@@ -950,6 +951,13 @@ RenderEngine::RendererImplementation RenderEngine::rendererImplementation() cons
return _rendererImplementation;
}
ghoul::opengl::OpenGLStateCache& RenderEngine::openglStateCache() {
if (_openglStateCache == nullptr) {
_openglStateCache = ghoul::opengl::OpenGLStateCache::instance();
}
return *_openglStateCache;
}
float RenderEngine::globalBlackOutFactor() {
return _globalBlackOutFactor;
}