43 #include <ACG/GL/acg_glew.hh> 44 #include "ClassicDepthPeeling.hh" 46 #include <ACG/GL/GLError.hh> 63 GLint DualPeelIntFmt[] = {GL_RG32F, GL_RG32F,
68 for (
int i = 0; i < 7; ++i)
72 if (i >= 2) fmt = GL_RGBA;
73 if (i == 6) fmt = GL_RGB;
77 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
78 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);
80 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
81 glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
83 glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, DualPeelIntFmt[i], p->
glWidth_, p->
glHeight_, 0, fmt, GL_FLOAT, 0);
103 for (
int i = 0; i < 6; ++i)
105 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i,
110 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT6, GL_TEXTURE_RECTANGLE_EXT,
119 const char* ShaderFiles[] = {
"Blending/dual_peeling_init_vertex.glsl",
120 "Blending/dual_peeling_init_fragment.glsl",
121 "Blending/dual_peeling_blend_vertex.glsl",
122 "Blending/dual_peeling_blend_fragment.glsl",
123 "Blending/dual_peeling_final_vertex.glsl",
124 "Blending/dual_peeling_final_fragment.glsl"};
126 for (
int i = 0; i < 6; ++i)
128 QString shaderFile = OpenFlipper::Options::shaderDirStr() + QDir::separator() + QString(ShaderFiles[i]);
137 if (!blendShaders_[i]) {
138 log(
LOGERR, QString(ShaderFiles[i]) + QString(
" could not be loaded and compiled"));
147 for (
int i = 0; i < 4; ++i)
193 for (
int i = 0; i < 4; ++i)
215 std::map<int, ViewerResources>::iterator resIt = viewerRes_.begin();
216 for (; resIt != viewerRes_.end(); ++resIt)
224 glPushAttrib(GL_ALL_ATTRIB_BITS);
228 int viewerId = _properties.
viewerId();
248 ACG::GLState::lockDepthFunc();
256 GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0_EXT,
257 GL_COLOR_ATTACHMENT1_EXT,
258 GL_COLOR_ATTACHMENT2_EXT,
259 GL_COLOR_ATTACHMENT3_EXT,
260 GL_COLOR_ATTACHMENT4_EXT,
261 GL_COLOR_ATTACHMENT5_EXT,
262 GL_COLOR_ATTACHMENT6_EXT};
265 const float maxDepth = 1.0f;
298 GLint old_viewport[4];
299 glGetIntegerv(GL_VIEWPORT, old_viewport);
302 for (
int i = 0; i < 6; ++i)
319 glClearColor(0, 0, 0, 0);
320 glClear(GL_COLOR_BUFFER_BIT);
324 glClearColor(-maxDepth, -maxDepth, 0, 0);
325 glClear(GL_COLOR_BUFFER_BIT);
348 glClear(GL_COLOR_BUFFER_BIT);
351 GLuint sampleCount = 1;
352 for (
int pass = 1; sampleCount; ++pass)
355 int prevId = 1 - currId;
356 int bufId = currId * 3;
359 glClearColor(0, 0, 0, 0);
360 glClear(GL_COLOR_BUFFER_BIT);
363 glClearColor(-maxDepth, -maxDepth, 0, 0);
364 glClear(GL_COLOR_BUFFER_BIT);
387 drawScenePeelPass(_glState, _properties.
drawMode(), sceneGraphRoot, pass);
410 glEndQuery(GL_SAMPLES_PASSED_ARB);
411 glGetQueryObjectuiv(
blendQueryID_, GL_QUERY_RESULT_ARB, &sampleCount);
451 glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
463 ACG::GLState::unlockDepthFunc();
GLSL::PtrVertexShader loadVertexShader(const char *name, const GLSL::StringList *macros, bool verbose)
Loads, compiles and installs a new vertex shader.
static void lockProgram()
lock the program
static void unlockShadeModel()
unlock shade model
GLSL::Program * blendDualPeelProg_[4]
depth peeling programs
void destroyResources()
free all gl resources
GLuint blendQueryID_
fragment query
static void blendEquation(GLenum _mode)
replaces glBlendEquation, supports locking
void updatePeelingShaderSet()
regenerates peeling shaders based on light nodes in scenegraph
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
static void unlockBlendEquation()
unlock blend equation
GLuint blendDualPeelFbo_
depth peeling fbo
unsigned int rtWidth_
render target width
GLuint blendDualPeelTexID_[7]
render target textures: {depth0, depth1, front_blend0, front_blend1, back_temp0, back_temp1, back_blend}
GLSL::Shader * blendShaders_[8]
shader resources
int viewport_width() const
get viewport width
static GLuint getFramebufferDraw()
get current draw framebuffer of a target
static void lockBlendEquation()
lock blend equation
void drawScenePass(ACG::GLState *_glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, BaseNode *_sceneGraphRoot)
draw the current scene
const Vec4f & clear_color() const
get background color
void disable()
Resets to standard rendering pipeline.
static void lockState(GLenum _cap)
locks a specific cap state, such that enable() or disable() has no effect
static void drawBuffers(GLsizei _n, const GLenum *_bufs)
replaces glDrawBuffers, supports locking
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)
static void bindFramebuffer(GLenum _target, GLuint _framebuffer)
replaces glBindFramebuffer, supports locking
ACG::GLState * glStateTmp_
current glState ptr for hiddenline rendering
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
static void lockShadeModel()
lock shade model
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
unsigned int rtHeight_
render target height
static void drawBuffer(GLenum _mode)
replaces glDrawBuffer, supports locking
void attach(PtrConstShader _shader)
Attaches a shader object to the program object.
static void syncFromGL()
synchronize this class with the OpenGL state machine
void link()
Links the shader objects to the program.
int viewport_height() const
get viewport height
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
static void unlockProgram()
unlock the program
unsigned int glHeight_
viewer window height
GLSL::Shader * peelShaders_[PEEL_NUM_COMBINATIONS *3]
generated shader set
void reloadResources(int _viewerId)
reload gl resources
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
GLSL::PtrFragmentShader loadFragmentShader(const char *name, const GLSL::StringList *macros, bool verbose)
Loads, compiles and installs a new vertex shader.
GLSL::Program * peelProgs_[PEEL_NUM_COMBINATIONS]
generates shader programs
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static void unlockState(GLenum _cap)
unlocks a specific cap state
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
void use()
Enables the program object for using.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
unsigned int glWidth_
viewer window width
int viewerId()
Get the id of the viewer this viewerproperties belongs to.
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking