50 #include <ACG/GL/acg_glew.hh>
51 #include "ClassicDepthPeeling.hh"
53 #include <ACG/GL/GLError.hh>
70 GLint DualPeelIntFmt[] = {GL_RG32F, GL_RG32F,
75 for (
int i = 0; i < 7; ++i)
79 if (i >= 2) fmt = GL_RGBA;
80 if (i == 6) fmt = GL_RGB;
84 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
85 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);
87 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
88 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
90 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, DualPeelIntFmt[i], p->
glWidth_, p->
glHeight_, 0, fmt, GL_FLOAT, 0);
110 for (
int i = 0; i < 6; ++i)
112 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i,
117 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT6, GL_TEXTURE_RECTANGLE_EXT,
126 const char* ShaderFiles[] = {
"Blending/dual_peeling_init_vertex.glsl",
127 "Blending/dual_peeling_init_fragment.glsl",
128 "Blending/dual_peeling_blend_vertex.glsl",
129 "Blending/dual_peeling_blend_fragment.glsl",
130 "Blending/dual_peeling_final_vertex.glsl",
131 "Blending/dual_peeling_final_fragment.glsl"};
133 for (
int i = 0; i < 6; ++i)
135 QString shaderFile = OpenFlipper::Options::shaderDirStr() + QDir::separator() + QString(ShaderFiles[i]);
144 if (!blendShaders_[i]) {
145 log(
LOGERR, QString(ShaderFiles[i]) + QString(
" could not be loaded and compiled"));
154 for (
int i = 0; i < 4; ++i)
200 for (
int i = 0; i < 4; ++i)
222 std::map<int, ViewerResources>::iterator resIt = viewerRes_.begin();
223 for (; resIt != viewerRes_.end(); ++resIt)
231 glPushAttrib(GL_ALL_ATTRIB_BITS);
235 int viewerId = _properties.
viewerId();
237 ViewerResources* pViewer = &viewerRes_[viewerId];
241 if (pViewer->glWidth_ != pViewer->rtWidth_ || pViewer->glHeight_ != pViewer->rtHeight_)
255 ACG::GLState::lockDepthFunc();
263 GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0_EXT,
264 GL_COLOR_ATTACHMENT1_EXT,
265 GL_COLOR_ATTACHMENT2_EXT,
266 GL_COLOR_ATTACHMENT3_EXT,
267 GL_COLOR_ATTACHMENT4_EXT,
268 GL_COLOR_ATTACHMENT5_EXT,
269 GL_COLOR_ATTACHMENT6_EXT};
272 const float maxDepth = 1.0f;
305 GLint old_viewport[4];
306 glGetIntegerv(GL_VIEWPORT, old_viewport);
307 glViewport(0, 0, pViewer->glWidth_, pViewer->glHeight_);
309 for (
int i = 0; i < 6; ++i)
326 glClearColor(0, 0, 0, 0);
327 glClear(GL_COLOR_BUFFER_BIT);
331 glClearColor(-maxDepth, -maxDepth, 0, 0);
332 glClear(GL_COLOR_BUFFER_BIT);
355 glClear(GL_COLOR_BUFFER_BIT);
358 GLuint sampleCount = 1;
359 for (
int pass = 1; sampleCount; ++pass)
362 int prevId = 1 - currId;
363 int bufId = currId * 3;
366 glClearColor(0, 0, 0, 0);
367 glClear(GL_COLOR_BUFFER_BIT);
370 glClearColor(-maxDepth, -maxDepth, 0, 0);
371 glClear(GL_COLOR_BUFFER_BIT);
394 drawScenePeelPass(_glState, _properties.
drawMode(), sceneGraphRoot, pass);
417 glEndQuery(GL_SAMPLES_PASSED_ARB);
418 glGetQueryObjectuiv(
blendQueryID_, GL_QUERY_RESULT_ARB, &sampleCount);
455 glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
467 ACG::GLState::unlockDepthFunc();
static void bindFramebuffer(GLenum _target, GLuint _framebuffer)
replaces glBindFramebuffer, supports locking
unsigned int rtWidth_
render target width
static void enable(GLenum _cap)
replaces glEnable, but supports locking
static void drawBuffers(GLsizei _n, const GLenum *_bufs)
replaces glDrawBuffers, supports locking
static void lockBlendEquation()
lock blend equation
static void unlockState(GLenum _cap)
unlocks a specific cap state
const Vec4f & clear_color() const
get background color
GLSL::PtrVertexShader loadVertexShader(const char *name, const GLSL::StringList *macros, bool verbose)
Loads, compiles and installs a new vertex shader.
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
ACG::GLState * glStateTmp_
current glState ptr for hiddenline rendering
void drawScenePass(ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, BaseNode *_sceneGraphRoot)
draw the current scene
static void lockState(GLenum _cap)
locks a specific cap state, such that enable() or disable() has no effect
GLuint blendQueryID_
fragment query
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
static void lockShadeModel()
lock shade model
static void syncFromGL()
synchronize this class with the OpenGL state machine
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
GLSL::PtrFragmentShader loadFragmentShader(const char *name, const GLSL::StringList *macros, bool verbose)
Loads, compiles and installs a new vertex shader.
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
static void drawBuffer(GLenum _mode)
replaces glDrawBuffer, supports locking
GLuint blendDualPeelFbo_
depth peeling fbo
GLuint blendDualPeelTexID_[7]
render target textures: {depth0, depth1, front_blend0, front_blend1, back_temp0, back_temp1, back_blend}
void use()
Enables the program object for using.
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
int viewport_width() const
get viewport width
void reloadResources(int _viewerId)
reload gl resources
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
static void unlockProgram()
unlock the program
int viewerId()
Get the id of the viewer this viewerproperties belongs to.
static void blendEquation(GLenum _mode)
replaces glBlendEquation, supports locking
void destroyResources()
free all gl resources
GLSL::Program * peelProgs_[PEEL_NUM_COMBINATIONS]
generates shader programs
unsigned int rtHeight_
render target height
void link()
Links the shader objects to the program.
static void unlockShadeModel()
unlock shade model
unsigned int glWidth_
viewer window width
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
static void disable(GLenum _cap)
replaces glDisable, but supports locking
static void lockProgram()
lock the program
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void updatePeelingShaderSet()
regenerates peeling shaders based on light nodes in scenegraph
GLSL::Shader * blendShaders_[8]
shader resources
void disable()
Resets to standard rendering pipeline.
unsigned int glHeight_
viewer window height
void drawQuadProj(float _x0=-1.0f, float _y0=1.0f, float _w=2.0f, float _h=2.0f)
draw a quad in projection space (only positions)
GLSL::Shader * peelShaders_[PEEL_NUM_COMBINATIONS *3]
generated shader set
void attach(PtrConstShader _shader)
Attaches a shader object to the program object.
static void unlockBlendEquation()
unlock blend equation
static GLuint getFramebufferDraw()
get current draw framebuffer of a target
int viewport_height() const
get viewport height
GLSL::Program * blendDualPeelProg_[4]
depth peeling programs