nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "GLDeviceObjects.h" 00024 #include "IOpenGLRectangleTexture.h" 00025 00026 namespace nux 00027 { 00028 00029 NUX_IMPLEMENT_OBJECT_TYPE (IOpenGLRectangleTexture); 00030 00031 IOpenGLRectangleTexture::IOpenGLRectangleTexture ( 00032 unsigned int Width 00033 , unsigned int Height 00034 , unsigned int Levels 00035 , BitmapFormat PixelFormat, bool Dummy, NUX_FILE_LINE_DECL) 00036 : IOpenGLBaseTexture (RTTEXTURERECTANGLE, Width, Height, 1, Levels, PixelFormat, NUX_FILE_LINE_PARAM) 00037 { 00038 if (Dummy == false) 00039 { 00040 glGenTextures (1, &_OpenGLID); 00041 CHECKGL ( glBindTexture (GL_TEXTURE_RECTANGLE_ARB, _OpenGLID) ); 00042 } 00043 00044 //_SurfaceArray.Empty(Levels); 00045 for (unsigned int l = 0; l < Levels; l++) 00046 { 00047 IOpenGLSurface *surface = new IOpenGLSurface (this, _OpenGLID, GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_RECTANGLE_ARB, l, 0, NUX_TRACKER_LOCATION); 00048 00049 if (Dummy == false) surface->InitializeLevel(); 00050 00051 _SurfaceArray.push_back (ObjectPtr<IOpenGLSurface> (surface)); 00052 surface->UnReference (); 00053 } 00054 00055 SetFiltering (GL_NEAREST, GL_NEAREST); 00056 SetWrap (GL_CLAMP, GL_CLAMP, GL_CLAMP); 00057 SetRenderStates(); 00058 GRunTimeStats.Register (this); 00059 } 00060 00061 IOpenGLRectangleTexture::~IOpenGLRectangleTexture() 00062 { 00063 for (int l = 0; l < _NumMipLevel; l++) 00064 { 00065 _SurfaceArray[l] = ObjectPtr<IOpenGLSurface> (0);; 00066 } 00067 00068 _SurfaceArray.clear(); 00069 CHECKGL ( glDeleteTextures (1, &_OpenGLID) ); 00070 _OpenGLID = 0; 00071 GRunTimeStats.UnRegister (this); 00072 } 00073 00074 ObjectPtr<IOpenGLSurface> IOpenGLRectangleTexture::GetSurfaceLevel (int Level) 00075 { 00076 if (Level < _NumMipLevel) 00077 { 00078 return _SurfaceArray[Level]; 00079 } 00080 else 00081 { 00082 nuxAssertMsg (0, TEXT ("[IOpenGLRectangleTexture::GetSurfaceLevel] Invalid surface level") ); 00083 } 00084 00085 return ObjectPtr<IOpenGLSurface> (0); 00086 } 00087 00088 void IOpenGLRectangleTexture::GetSurfaceLevel (int Level, ObjectPtr<IOpenGLSurface>& surface) 00089 { 00090 surface = GetSurfaceLevel (Level); 00091 } 00092 00093 int IOpenGLRectangleTexture::LockRect ( 00094 int Level, 00095 SURFACE_LOCKED_RECT *pLockedRect, 00096 const SURFACE_RECT *pRect) 00097 { 00098 nuxAssertMsg (pLockedRect, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid parameter 'pLockedRect'.") ); 00099 nuxAssertMsg (Level >= 0, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level.") ); 00100 nuxAssertMsg (Level < _NumMipLevel, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level.") ); 00101 00102 00103 if (Level < _NumMipLevel) 00104 { 00105 ObjectPtr<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level]; 00106 return pSurfaceLevel->LockRect (pLockedRect, pRect); 00107 } 00108 else 00109 { 00110 pLockedRect->pBits = 0; 00111 pLockedRect->Pitch = 0; 00112 return OGL_INVALID_SURFACE_LEVEL; 00113 } 00114 00115 return OGL_OK; 00116 } 00117 00118 int IOpenGLRectangleTexture::UnlockRect ( 00119 int Level 00120 ) 00121 { 00122 nuxAssertMsg (Level >= 0, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level.") ); 00123 nuxAssertMsg (Level < _NumMipLevel, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level.") ); 00124 00125 if (Level < _NumMipLevel) 00126 { 00127 ObjectPtr<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level]; 00128 return pSurfaceLevel->UnlockRect(); 00129 } 00130 else 00131 { 00132 return OGL_INVALID_SURFACE_LEVEL; 00133 } 00134 00135 return OGL_OK; 00136 } 00137 00138 unsigned int IOpenGLRectangleTexture::EnableGammaCorrection (bool b) 00139 { 00140 nuxAssert (_OpenGLID); 00141 return OGL_OK; 00142 } 00143 00144 void* IOpenGLRectangleTexture::GetSurfaceData (int level, int &width, int &height, int &format) 00145 { 00146 nuxAssertMsg (level >= 0, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level.") ); 00147 nuxAssertMsg (level < _NumMipLevel, TEXT ("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level.") ); 00148 00149 if (level < _NumMipLevel) 00150 { 00151 ObjectPtr<IOpenGLSurface> pSurfaceLevel = _SurfaceArray [level]; 00152 return pSurfaceLevel->GetSurfaceData (width, height, format); 00153 } 00154 else 00155 { 00156 width = 0; 00157 height = 0; 00158 format = BITFMT_UNKNOWN; 00159 return 0; 00160 } 00161 } 00162 }