mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
VizFwk: Add scissoring to cvf::Rendering
This commit is contained in:
@@ -97,6 +97,7 @@ cvfUniformSet.h
|
||||
cvfVertexAttribute.h
|
||||
cvfVertexBundle.h
|
||||
cvfViewport.h
|
||||
cvfRenderingScissor.h
|
||||
)
|
||||
|
||||
set(CEE_SOURCE_FILES
|
||||
@@ -172,6 +173,7 @@ cvfUniformSet.cpp
|
||||
cvfVertexAttribute.cpp
|
||||
cvfVertexBundle.cpp
|
||||
cvfViewport.cpp
|
||||
cvfRenderingScissor.cpp
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} ${CEE_HEADER_FILES} ${CEE_SOURCE_FILES})
|
||||
|
179
Fwk/VizFwk/LibRender/cvfRenderingScissor.cpp
Normal file
179
Fwk/VizFwk/LibRender/cvfRenderingScissor.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#include "cvfRenderingScissor.h"
|
||||
#include "cvfOpenGL.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::RenderingScissor
|
||||
/// \ingroup Render
|
||||
///
|
||||
/// An OpenGL Scissor.
|
||||
///
|
||||
/// Stores scissoring settings that are applied to the OpenGl state when calling applyOpenGL()
|
||||
/// unApplyOpenGL will restore the scissoring settings to what they where before the call to applyOpenGl()
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RenderingScissor::RenderingScissor()
|
||||
: m_x(0),
|
||||
m_y(0),
|
||||
m_width(0),
|
||||
m_height(0),
|
||||
m_scissorEnabledStateToRestore(false)
|
||||
{
|
||||
m_scissorBoxToRestore[0] = 0;
|
||||
m_scissorBoxToRestore[1] = 0;
|
||||
m_scissorBoxToRestore[2] = -1;
|
||||
m_scissorBoxToRestore[3] = -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RenderingScissor::setScissorRectangle(int x, int y, uint width, uint height)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RenderingScissor::x() const
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RenderingScissor::y() const
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint RenderingScissor::width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint RenderingScissor::height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RenderingScissor::applyOpenGL(OpenGLContext* oglContext, Viewport::ClearMode clearMode, const Color4f& clearColor)
|
||||
{
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
|
||||
m_scissorEnabledStateToRestore = glIsEnabled(GL_SCISSOR_TEST);
|
||||
glGetIntegerv(GL_SCISSOR_BOX, m_scissorBoxToRestore);
|
||||
|
||||
glScissor(static_cast<GLsizei>(m_x),
|
||||
static_cast<GLsizei>(m_y),
|
||||
static_cast<GLsizei>(m_width),
|
||||
static_cast<GLsizei>(m_height));
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
GLbitfield clearFlags = Viewport::clearFlagsOpenGL(clearMode);
|
||||
|
||||
if (clearFlags != 0)
|
||||
{
|
||||
if ( clearFlags & GL_COLOR_BUFFER_BIT )
|
||||
{
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glClearColor(clearColor.r(), clearColor.g(), clearColor.b(), clearColor.a());
|
||||
}
|
||||
|
||||
if ( clearFlags & GL_DEPTH_BUFFER_BIT )
|
||||
{
|
||||
glDepthMask(GL_TRUE);
|
||||
#ifndef CVF_OPENGL_ES
|
||||
glClearDepth(1.0f);
|
||||
#endif // CVF_OPENGL_ES
|
||||
}
|
||||
|
||||
if ( clearFlags & GL_STENCIL_BUFFER_BIT )
|
||||
{
|
||||
glStencilMask(0xffffffff);
|
||||
glClearStencil(0);
|
||||
}
|
||||
|
||||
glClear(clearFlags);
|
||||
}
|
||||
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RenderingScissor::unApplyOpenGL(OpenGLContext* oglContext)
|
||||
{
|
||||
if ( m_scissorEnabledStateToRestore )
|
||||
{
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
glScissor(m_scissorBoxToRestore[0],
|
||||
m_scissorBoxToRestore[1],
|
||||
m_scissorBoxToRestore[2],
|
||||
m_scissorBoxToRestore[3]);
|
||||
}
|
||||
|
||||
}
|
81
Fwk/VizFwk/LibRender/cvfRenderingScissor.h
Normal file
81
Fwk/VizFwk/LibRender/cvfRenderingScissor.h
Normal file
@@ -0,0 +1,81 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfViewport.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
class OpenGLContext;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// OpenGL Scissoring
|
||||
//
|
||||
//==================================================================================================
|
||||
class RenderingScissor : public Object
|
||||
{
|
||||
public:
|
||||
RenderingScissor();
|
||||
~RenderingScissor(){}
|
||||
|
||||
void setScissorRectangle(int x, int y, uint width, uint height);
|
||||
|
||||
int x() const;
|
||||
int y() const;
|
||||
uint width() const;
|
||||
uint height() const;
|
||||
|
||||
void applyOpenGL(OpenGLContext* oglContext, Viewport::ClearMode clearMode, const Color4f& clearColor);
|
||||
void unApplyOpenGL(OpenGLContext* oglContext);
|
||||
|
||||
private:
|
||||
|
||||
int m_x;
|
||||
int m_y;
|
||||
uint m_width;
|
||||
uint m_height;
|
||||
|
||||
int m_scissorBoxToRestore[4];
|
||||
bool m_scissorEnabledStateToRestore;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ namespace cvf {
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Viewport::Viewport()
|
||||
: m_x(0),
|
||||
: m_x(0),
|
||||
m_y(0),
|
||||
m_width(0),
|
||||
m_height(0),
|
||||
@@ -206,9 +206,9 @@ void Viewport::applyOpenGL(OpenGLContext* oglContext, ClearMode clearMode)
|
||||
if (clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glDepthMask(GL_TRUE);
|
||||
#ifndef CVF_OPENGL_ES
|
||||
#ifndef CVF_OPENGL_ES
|
||||
glClearDepth(m_clearDepth);
|
||||
#endif // CVF_OPENGL_ES
|
||||
#endif // CVF_OPENGL_ES
|
||||
}
|
||||
|
||||
if (clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
@@ -227,32 +227,32 @@ void Viewport::applyOpenGL(OpenGLContext* oglContext, ClearMode clearMode)
|
||||
// Do the actual clear
|
||||
glClear(clearFlags);
|
||||
|
||||
// {
|
||||
// // Code to draw a full screen quad into color buffer using FF
|
||||
// // Experimented with this code when seeing problems with rendering to texture on ATI Catalys 11.3 where
|
||||
// // it seemed that lazy clearing of color buffer was causing problems with depth peeling and glGenerateMipmap()
|
||||
// glMatrixMode(GL_PROJECTION);
|
||||
// glLoadIdentity();
|
||||
// glMatrixMode(GL_MODELVIEW);
|
||||
// glLoadIdentity();
|
||||
//
|
||||
// glDisable(GL_DEPTH_TEST);
|
||||
// glDepthMask(GL_FALSE);
|
||||
// glDisable(GL_LIGHTING);
|
||||
// glColor3f(0, 1, 0);
|
||||
//
|
||||
// glBegin(GL_QUADS);
|
||||
// {
|
||||
// glVertex2f(-1.0, -1.0);
|
||||
// glVertex2f( 1.0, -1.0);
|
||||
// glVertex2f( 1.0, 1.0);
|
||||
// glVertex2f(-1.0, 1.0);
|
||||
// }
|
||||
// glEnd();
|
||||
//
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
// glDepthMask(GL_TRUE);
|
||||
// }
|
||||
// {
|
||||
// // Code to draw a full screen quad into color buffer using FF
|
||||
// // Experimented with this code when seeing problems with rendering to texture on ATI Catalys 11.3 where
|
||||
// // it seemed that lazy clearing of color buffer was causing problems with depth peeling and glGenerateMipmap()
|
||||
// glMatrixMode(GL_PROJECTION);
|
||||
// glLoadIdentity();
|
||||
// glMatrixMode(GL_MODELVIEW);
|
||||
// glLoadIdentity();
|
||||
//
|
||||
// glDisable(GL_DEPTH_TEST);
|
||||
// glDepthMask(GL_FALSE);
|
||||
// glDisable(GL_LIGHTING);
|
||||
// glColor3f(0, 1, 0);
|
||||
//
|
||||
// glBegin(GL_QUADS);
|
||||
// {
|
||||
// glVertex2f(-1.0, -1.0);
|
||||
// glVertex2f( 1.0, -1.0);
|
||||
// glVertex2f( 1.0, 1.0);
|
||||
// glVertex2f(-1.0, 1.0);
|
||||
// }
|
||||
// glEnd();
|
||||
//
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
// glDepthMask(GL_TRUE);
|
||||
// }
|
||||
|
||||
// Restore scissor settings
|
||||
if (!scissorWasOn) glDisable(GL_SCISSOR_TEST);
|
||||
|
@@ -85,8 +85,7 @@ public:
|
||||
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
cvfGLbitfield clearFlagsOpenGL(ClearMode clearMode);
|
||||
static cvfGLbitfield clearFlagsOpenGL(ClearMode clearMode);
|
||||
|
||||
private:
|
||||
int m_x;
|
||||
|
@@ -57,6 +57,7 @@
|
||||
#include "cvfRayIntersectSpec.h"
|
||||
#include "cvfHitItemCollection.h"
|
||||
#include "cvfLogManager.h"
|
||||
#include "cvfRenderingScissor.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
@@ -214,7 +215,17 @@ void Rendering::render(OpenGLContext* oglContext)
|
||||
|
||||
// Setup camera and view
|
||||
// -------------------------------------------------------------------------
|
||||
m_camera->viewport()->applyOpenGL(oglContext, m_clearMode);
|
||||
|
||||
if (m_renderingScissor.notNull())
|
||||
{
|
||||
m_camera->viewport()->applyOpenGL(oglContext, Viewport::DO_NOT_CLEAR);
|
||||
m_renderingScissor->applyOpenGL(oglContext, m_clearMode, m_camera->viewport()->clearColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_camera->viewport()->applyOpenGL(oglContext, m_clearMode);
|
||||
}
|
||||
|
||||
m_camera->applyOpenGL();
|
||||
|
||||
// Update dynamic uniforms and dynamic uniform sets
|
||||
@@ -261,6 +272,11 @@ void Rendering::render(OpenGLContext* oglContext)
|
||||
size_t numPartsToDraw = std::min(m_maxNumPartsToDraw, renderQueue.count());
|
||||
m_renderEngine.render(oglContext, &renderQueue, numPartsToDraw, *m_camera, globalUniformSet);
|
||||
|
||||
if (m_renderingScissor.notNull())
|
||||
{
|
||||
m_renderingScissor->unApplyOpenGL(oglContext);
|
||||
}
|
||||
|
||||
if (renderTimer.notNull())
|
||||
{
|
||||
m_performanceInfo.renderEngineTime = renderTimer->lapTime();
|
||||
@@ -662,6 +678,14 @@ Viewport::ClearMode Rendering::clearMode() const
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rendering::setRenderingScissor(RenderingScissor* scissor)
|
||||
{
|
||||
m_renderingScissor = scissor;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@@ -61,7 +61,7 @@ class UniformSet;
|
||||
class RayIntersectSpec;
|
||||
class HitItemCollection;
|
||||
class OpenGLContext;
|
||||
|
||||
class RenderingScissor;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
@@ -106,6 +106,7 @@ public:
|
||||
|
||||
void setClearMode(Viewport::ClearMode clearMode);
|
||||
Viewport::ClearMode clearMode() const;
|
||||
void setRenderingScissor(RenderingScissor* scissor);
|
||||
|
||||
void setEffectOverride(Effect* effect);
|
||||
Effect* effectOverride();
|
||||
@@ -160,7 +161,8 @@ private:
|
||||
uint m_enableMask; // Mask will be compared against the contained scene's models and the model's parts when determining visible parts
|
||||
Viewport::ClearMode m_clearMode;
|
||||
ref<Effect> m_effectOverride; // Can hold an overriding effect. All parts drawn by this rendering will use this effect
|
||||
|
||||
ref<RenderingScissor> m_renderingScissor; // Can hold a scissor used on the rendered scene. Will not affect overly items
|
||||
|
||||
Collection<DynamicUniformSet> m_dynamicUniformSets; // Collection of user added dynamic uniform sets
|
||||
Collection<DynamicUniformSet> m_globalDynamicUniformSets; // Collection of global user added dynamic uniform sets
|
||||
ref<UniformSet> m_combinedGlobalUniformSet; // Global uniform set, this is the combination of the uniform sets from all the dynamic uniform sets
|
||||
|
Reference in New Issue
Block a user