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.8f,0,0.1f,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 (!GLEW_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 glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
00105 glDepthMask(GL_TRUE);
00106 glStencilMask(GL_TRUE);
00107
00108
00109 GLboolean scissor_on = glIsEnabled(GL_SCISSOR_TEST);
00110 int scissor_box[4] = {0,0,-1,-1};
00111 glGetIntegerv(GL_SCISSOR_BOX, scissor_box);
00112
00113
00114 glScissor(x, y, w, h);
00115 glEnable(GL_SCISSOR_TEST);
00116
00117 switch( clearColorMode() )
00118 {
00119 case CCM_Float: glClearColor( mClearColor.r(), mClearColor.g(), mClearColor.b(), mClearColor.a() ); break;
00120 case CCM_Int: glClearColorIiEXT( mClearColorInt.r(), mClearColorInt.g(), mClearColorInt.b(), mClearColorInt.a() ); break;
00121 case CCM_UInt: glClearColorIuiEXT( mClearColorUInt.r(), mClearColorUInt.g(), mClearColorUInt.b(), mClearColorUInt.a() ); break;
00122 }
00123
00124 glClearDepth( mClearDepth );
00125 glClearStencil( mClearStencil );
00126
00127 glClear(mClearFlags);
00128
00129
00130 if (!scissor_on)
00131 glDisable(GL_SCISSOR_TEST);
00132 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], scissor_box[3]); VL_CHECK_OGL()
00133
00134 VL_CHECK_OGL()
00135 }
00136 }
00137
00138 bool Viewport::isPointInside(int x, int y, int render_target_height) const
00139 {
00140
00141 x -= this->x();
00142 y -= render_target_height - 1 - (this->y() + height() -1);
00143
00144
00145
00146 if (x<0 || y<0 || x>=this->width() || y>=this->height())
00147 return false;
00148 else
00149 return true;
00150 }
00151