Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <vlGraphics/Clear.hpp>
00033 #include <vlGraphics/Camera.hpp>
00034 #include <vlCore/Vector4.hpp>
00035 #include <vlCore/Log.hpp>
00036
00037 using namespace vl;
00038
00039
00040 Clear::Clear(): mClearColorMode(CCM_Float), mClearDepthValue(1.0f), mClearStencilValue(0),
00041 mClearColorBuffer(false), mClearDepthBuffer(false), mClearStencilBuffer(false)
00042 {
00043 VL_DEBUG_SET_OBJECT_NAME()
00044
00045 mScissorBox[0] = 0;
00046 mScissorBox[1] = 0;
00047 mScissorBox[2] = -1;
00048 mScissorBox[3] = -1;
00049 }
00050
00051 void Clear::render_Implementation(const Actor*, const Shader*, const Camera* camera, OpenGLContext*) const
00052 {
00053
00054 GLbitfield mask = 0;
00055 mask = mask | (mClearColorBuffer ? GL_COLOR_BUFFER_BIT : 0);
00056 mask = mask | (mClearDepthBuffer ? GL_DEPTH_BUFFER_BIT : 0);
00057 mask = mask | (mClearStencilBuffer ? GL_STENCIL_BUFFER_BIT : 0);
00058
00059
00060 if ( (clearColorMode() == CCM_Int || clearColorMode() == CCM_UInt) && !Has_GL_EXT_texture_integer)
00061 {
00062 Log::error("Clear::render(): glClearColorIiEXT and glClearColorIuiEXT not supported.\n");
00063 return;
00064 }
00065
00066 if (mask)
00067 {
00068 int viewport[] = { camera->viewport()->x(), camera->viewport()->y(), camera->viewport()->width(), camera->viewport()->height() };
00069
00070
00071 GLboolean scissor_on = glIsEnabled(GL_SCISSOR_TEST);
00072 int scissor_box_save[4] = {0,0,-1,-1};
00073 glGetIntegerv(GL_SCISSOR_BOX, scissor_box_save);
00074
00075 int scissor_box[4] = {0,0,-1,-1};
00076
00077
00078 if (mScissorBox[2] == -1 || mScissorBox[3] == -1)
00079 {
00080 scissor_box[0] = viewport[0];
00081 scissor_box[1] = viewport[1];
00082 scissor_box[2] = viewport[2];
00083 scissor_box[3] = viewport[3];
00084 }
00085 else
00086
00087 {
00088 scissor_box[0] = mScissorBox[0] + viewport[0];
00089 scissor_box[1] = mScissorBox[1] + viewport[1];
00090 scissor_box[2] = mScissorBox[2];
00091 scissor_box[3] = mScissorBox[3];
00092 }
00093
00094
00095 viewport[2] = viewport[0] + viewport[2] -1;
00096 viewport[3] = viewport[1] + viewport[3] -1;
00097
00098 scissor_box[2] = scissor_box[0] + scissor_box[2] -1;
00099 scissor_box[3] = scissor_box[1] + scissor_box[3] -1;
00100
00101 if (scissor_box[0] < viewport[0]) scissor_box[0] = viewport[0];
00102 if (scissor_box[1] < viewport[1]) scissor_box[1] = viewport[1];
00103 if (scissor_box[2] > viewport[2]) scissor_box[2] = viewport[2];
00104 if (scissor_box[3] > viewport[3]) scissor_box[3] = viewport[3];
00105
00106 if (scissor_box[0] > scissor_box[2])
00107 return;
00108 if (scissor_box[1] > scissor_box[3])
00109 return;
00110
00111 scissor_box[2] = scissor_box[2] -scissor_box[0] +1;
00112 scissor_box[3] = scissor_box[3] -scissor_box[1] +1;
00113
00114
00115 glEnable(GL_SCISSOR_TEST);
00116 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], scissor_box[3]); VL_CHECK_OGL()
00117
00118
00119 if (mClearColorBuffer)
00120 {
00121 switch(clearColorMode())
00122 {
00123 case CCM_Float: glClearColor( mClearColorValue.r(), mClearColorValue.g(), mClearColorValue.b(), mClearColorValue.a()); break;
00124 case CCM_Int: glClearColorIiEXT( mClearColorValueInt.r(), mClearColorValueInt.g(), mClearColorValueInt.b(), mClearColorValueInt.a()); break;
00125 case CCM_UInt: glClearColorIuiEXT(mClearColorValueUInt.r(), mClearColorValueUInt.g(), mClearColorValueUInt.b(), mClearColorValueUInt.a()); break;
00126 }
00127 }
00128 if (mClearDepthBuffer)
00129 glClearDepth(mClearDepthValue);
00130 if (mClearStencilBuffer)
00131 glClearStencil(mClearStencilValue);
00132
00133
00134 glClear(mask);
00135
00136
00137 if (!scissor_on)
00138 glDisable(GL_SCISSOR_TEST);
00139 glScissor(scissor_box_save[0], scissor_box_save[1], scissor_box_save[2], scissor_box_save[3]); VL_CHECK_OGL()
00140 }
00141 }
00142