nux-1.14.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 "IOpenGLVolumeTexture.h" 00025 00026 namespace nux 00027 { 00028 00029 NUX_IMPLEMENT_OBJECT_TYPE (IOpenGLVolumeTexture); 00030 00031 IOpenGLVolumeTexture::IOpenGLVolumeTexture ( 00032 int Width 00033 , int Height 00034 , int Depth 00035 , int Levels 00036 , BitmapFormat PixelFormat) 00037 : IOpenGLBaseTexture (RTVOLUMETEXTURE, Width, Height, Depth, Levels, PixelFormat) 00038 { 00039 CHECKGL ( glGenTextures (1, &_OpenGLID) ); 00040 CHECKGL ( glBindTexture (GL_TEXTURE_3D, _OpenGLID) ); 00041 00042 _VolumeSurfaceArray = new std::vector< ObjectPtr<IOpenGLSurface> >[_NumMipLevel]; 00043 00044 for (t_s32 mip = 0; mip < _NumMipLevel; mip++) 00045 { 00046 for (t_s32 slice = 0; slice < ImageSurface::GetLevelDim (_PixelFormat, _Depth, mip); slice++) 00047 { 00048 //IOpenGLSurface* surface = new IOpenGLSurface(this, _OpenGLID, GL_TEXTURE_3D, GL_TEXTURE_3D, mip, slice); 00049 //surface->InitializeLevel(); 00050 IOpenGLSurface* surface = new IOpenGLSurface (this, _OpenGLID, GL_TEXTURE_3D, GL_TEXTURE_3D, mip, slice); 00051 _VolumeSurfaceArray[mip].push_back (ObjectPtr<IOpenGLSurface> (surface)); 00052 surface->UnReference (); 00053 } 00054 } 00055 00056 for (int mip = 0; mip < _NumMipLevel; mip++) 00057 { 00058 IOpenGLVolume *volume = new IOpenGLVolume (this, _OpenGLID, GL_TEXTURE_3D, GL_TEXTURE_3D, mip); 00059 volume->InitializeLevel(); 00060 _VolumeArray.push_back (ObjectPtr<IOpenGLVolume> (volume)); 00061 } 00062 00063 CHECKGL ( glBindTexture (GL_TEXTURE_3D, _OpenGLID) ); 00064 SetFiltering (GL_NEAREST, GL_NEAREST); 00065 SetWrap (GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); 00066 SetRenderStates(); 00067 GRunTimeStats.Register (this); 00068 } 00069 00070 IOpenGLVolumeTexture::~IOpenGLVolumeTexture() 00071 { 00072 00073 for (t_s32 mip = 0; mip < _NumMipLevel; mip++) 00074 { 00075 for (t_s32 slice = 0; slice < ImageSurface::GetLevelDim (_PixelFormat, _Depth, mip); slice++) 00076 { 00077 // destroying a surface 00078 _VolumeSurfaceArray[mip][slice] = ObjectPtr<IOpenGLSurface> (0); 00079 } 00080 00081 _VolumeSurfaceArray[mip].clear(); 00082 } 00083 00084 NUX_SAFE_DELETE_ARRAY (_VolumeSurfaceArray); 00085 00086 00087 for (int mip = 0; mip < _NumMipLevel; mip++) 00088 { 00089 // destroying a IOpenGLVolume 00090 _VolumeArray[mip] = ObjectPtr<IOpenGLVolume> (0); 00091 } 00092 00093 CHECKGL ( glDeleteTextures (1, &_OpenGLID) ); 00094 _OpenGLID = 0; 00095 GRunTimeStats.UnRegister (this); 00096 } 00097 00098 int IOpenGLVolumeTexture::LockRect ( 00099 int Slice, 00100 int Level, 00101 SURFACE_LOCKED_RECT *pLockedRect, 00102 const SURFACE_RECT *pRect) 00103 { 00104 nuxAssertMsg (pLockedRect, TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid parameter 'pLockedRect'.") ); 00105 nuxAssertMsg (Level >= 0, TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level.") ); 00106 nuxAssertMsg (Level < _NumMipLevel, TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level.") ); 00107 nuxAssertMsg (Slice >= 0, TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid slice index.") ); 00108 nuxAssertMsg (Slice < ImageSurface::GetLevelDim (_PixelFormat, _Depth, Level), TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid slice index.") ); 00109 00110 if (Slice < 0) 00111 Slice = 0; 00112 00113 if (Slice >= _Depth) 00114 Slice = _Depth - 1; 00115 00116 if (Level < _NumMipLevel) 00117 { 00118 ObjectPtr<IOpenGLSurface> pVolumeSurfaceLevel = _VolumeSurfaceArray[Level][Slice]; 00119 return pVolumeSurfaceLevel->LockRect (pLockedRect, pRect); 00120 } 00121 else 00122 { 00123 pLockedRect->pBits = 0; 00124 pLockedRect->Pitch = 0; 00125 return OGL_INVALID_SURFACE_LEVEL; 00126 } 00127 00128 return OGL_OK; 00129 } 00130 00131 int IOpenGLVolumeTexture::UnlockRect ( 00132 int Slice, 00133 int Level 00134 ) 00135 { 00136 nuxAssertMsg (Level >= 0, TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level.") ); 00137 nuxAssertMsg (Level < _NumMipLevel, TEXT ("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level.") ); 00138 00139 if (Level < _NumMipLevel) 00140 { 00141 ObjectPtr<IOpenGLSurface> pVolumeSurfaceLevel = _VolumeSurfaceArray[Level][Slice]; 00142 return pVolumeSurfaceLevel->UnlockRect(); 00143 } 00144 else 00145 { 00146 return OGL_INVALID_SURFACE_LEVEL; 00147 } 00148 00149 return OGL_OK; 00150 } 00151 00152 int IOpenGLVolumeTexture::LockBox (int Level, 00153 VOLUME_LOCKED_BOX *pLockedVolume, 00154 const VOLUME_BOX *pBox) 00155 { 00156 nuxAssertMsg (pLockedVolume, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid parameter 'pLockedRect'.") ); 00157 nuxAssertMsg (Level >= 0, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level.") ); 00158 nuxAssertMsg (Level < _NumMipLevel, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level.") ); 00159 00160 if (pBox) 00161 { 00162 nuxAssertMsg (pBox->Front >= 0, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid slice index.") ); 00163 nuxAssertMsg (pBox->Front < pBox->Back, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid slice index.") ); 00164 nuxAssertMsg (pBox->Back <= ImageSurface::GetLevelDim (_PixelFormat, _Depth, Level), 00165 TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid slice index.") ); 00166 } 00167 00168 return _VolumeArray[Level]->LockBox (pLockedVolume, pBox); 00169 } 00170 00171 int IOpenGLVolumeTexture::UnlockBox (int Level) 00172 { 00173 nuxAssertMsg (Level >= 0, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level.") ); 00174 nuxAssertMsg (Level < _NumMipLevel, TEXT ("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level.") ); 00175 00176 return _VolumeArray[Level]->UnlockBox(); 00177 } 00178 00179 }