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 glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
00105 glDepthMask(GL_TRUE);
00106 glStencilMask(GL_TRUE);
00107
00108
00109 glEnable(GL_SCISSOR_TEST);
00110 glScissor(x, y, w, h);
00111
00112 switch( clearColorMode() )
00113 {
00114 case CCM_Float: glClearColor( mClearColor.r(), mClearColor.g(), mClearColor.b(), mClearColor.a() ); break;
00115 case CCM_Int: glClearColorIiEXT( mClearColorInt.r(), mClearColorInt.g(), mClearColorInt.b(), mClearColorInt.a() ); break;
00116 case CCM_UInt: glClearColorIuiEXT( mClearColorUInt.r(), mClearColorUInt.g(), mClearColorUInt.b(), mClearColorUInt.a() ); break;
00117 }
00118
00119 glClearDepth( mClearDepth );
00120 glClearStencil( mClearStencil );
00121
00122 glClear(mClearFlags);
00123
00124 VL_CHECK_OGL()
00125 }
00126 }
00127
00128 bool Viewport::isPointInside(int x, int y, int framebuffer_height) const
00129 {
00130
00131 x -= this->x();
00132 y -= framebuffer_height - 1 - (this->y() + height() -1);
00133
00134
00135
00136 if (x<0 || y<0 || x>=this->width() || y>=this->height())
00137 return false;
00138 else
00139 return true;
00140 }
00141