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/Viewport.hpp>
00033 #include <vlGraphics/OpenGL.hpp>
00034 #include <vlCore/Log.hpp>
00035 #include <vlCore/Say.hpp>
00036
00037 using namespace vl;
00038
00039
00040
00041
00042 Viewport::Viewport()
00043 {
00044 VL_DEBUG_SET_OBJECT_NAME()
00045 mX = 0;
00046 mY = 0;
00047 mWidth = 0;
00048 mHeight = 0;
00049 mClearColor = fvec4(0,0,0,1);
00050 mClearDepth = 1.0f;
00051 mClearStencil = 0;
00052 mClearFlags = CF_CLEAR_COLOR_DEPTH;
00053 mClearColorMode = CCM_Float;
00054 }
00055
00056 Viewport::Viewport(int x, int y, int w, int h)
00057 {
00058 VL_DEBUG_SET_OBJECT_NAME()
00059 mX = x;
00060 mY = y;
00061 mWidth = w;
00062 mHeight = h;
00063 mClearColor = fvec4(0.8f,0,0.1f,1);
00064 mClearDepth = 1.0f;
00065 mClearStencil = 0;
00066 mClearFlags = CF_CLEAR_COLOR_DEPTH;
00067 mClearColorMode = CCM_Float;
00068 }
00069
00070 void Viewport::activate() const
00071 {
00072 VL_CHECK_OGL()
00073
00074
00075 int x = mX;
00076 int y = mY;
00077 int w = mWidth;
00078 int h = mHeight;
00079
00080 if (w < 1) w = 1;
00081 if (h < 1) h = 1;
00082
00083 glViewport(x, y, w, h);
00084
00085
00086 if (mClearFlags)
00087 {
00088 #ifndef NDEBUG
00089 if (!Has_GL_EXT_texture_integer)
00090 {
00091 switch( clearColorMode() )
00092 {
00093 case CCM_Int:
00094 case CCM_UInt:
00095 Log::bug("Viewport::activate(): GL_EXT_texture_integer not supported.\n");
00096 break;
00097 default:
00098 break;
00099 }
00100 }
00101 #endif
00102
00103
00104 GLboolean color_write_mask[4] = {0,0,0,0};
00105 glGetBooleanv(GL_COLOR_WRITEMASK, color_write_mask);
00106
00107 GLboolean depth_write_mask = 0;
00108 glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_write_mask );
00109
00110 GLboolean stencil_write_mask = 0;
00111 glGetBooleanv(GL_STENCIL_WRITEMASK, &stencil_write_mask );
00112
00113
00114 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
00115 glDepthMask(GL_TRUE);
00116 glStencilMask(GL_TRUE);
00117
00118
00119 glEnable(GL_SCISSOR_TEST);
00120 glScissor(x, y, w, h);
00121
00122 switch( clearColorMode() )
00123 {
00124 case CCM_Float: glClearColor( mClearColor.r(), mClearColor.g(), mClearColor.b(), mClearColor.a() ); break;
00125 case CCM_Int: glClearColorIiEXT( mClearColorInt.r(), mClearColorInt.g(), mClearColorInt.b(), mClearColorInt.a() ); break;
00126 case CCM_UInt: glClearColorIuiEXT( mClearColorUInt.r(), mClearColorUInt.g(), mClearColorUInt.b(), mClearColorUInt.a() ); break;
00127 }
00128
00129 glClearDepth( mClearDepth );
00130
00131 glClearStencil( mClearStencil );
00132
00133 glClear(mClearFlags);
00134
00135
00136 glColorMask(color_write_mask[0], color_write_mask[1], color_write_mask[2], color_write_mask[3]);
00137 glDepthMask(depth_write_mask);
00138 glStencilMask(stencil_write_mask);
00139
00140 VL_CHECK_OGL()
00141 }
00142 }
00143
00144 bool Viewport::isPointInside(int x, int y, int framebuffer_height) const
00145 {
00146
00147 x -= this->x();
00148 y -= framebuffer_height - 1 - (this->y() + height() -1);
00149
00150
00151
00152 if (x<0 || y<0 || x>=this->width() || y>=this->height())
00153 return false;
00154 else
00155 return true;
00156 }
00157