2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
23
#include "GLDeviceObjects.h"
24
#include "IOpenGLTexture2D.h"
28
IMPLEMENT_OBJECT_TYPE(IOpenGLTexture2D);
29
IOpenGLTexture2D::IOpenGLTexture2D(unsigned int Width
32
, BitmapFormat PixelFormat, bool Dummy)
33
: IOpenGLBaseTexture(RTTEXTURE, Width, Height, 1, Levels, PixelFormat)
37
glGenTextures(1, &_OpenGLID);
38
CHECKGL( glBindTexture(GL_TEXTURE_2D, _OpenGLID) );
40
//_SurfaceArray.Empty(Levels);
41
for(unsigned int l = 0; l < Levels; l++)
43
IOpenGLSurface* surface = new IOpenGLSurface(this, _OpenGLID, GL_TEXTURE_2D, GL_TEXTURE_2D, l);
44
if(Dummy == false) surface->InitializeLevel();
45
_SurfaceArray.push_back( surface );
48
SetFiltering(GL_NEAREST, GL_NEAREST);
49
SetWrap(GL_REPEAT, GL_REPEAT, GL_REPEAT);
52
GRunTimeStats.Register(this);
55
IOpenGLTexture2D::~IOpenGLTexture2D()
57
for(int l = 0; l < _NumMipLevel; l++)
61
_SurfaceArray.clear();
63
CHECKGL( glDeleteTextures(1, &_OpenGLID) );
64
GRunTimeStats.UnRegister(this);
69
TRefGL<IOpenGLSurface> IOpenGLTexture2D::GetSurfaceLevel(int Level)
71
if((Level >= 0) && (Level < _NumMipLevel))
73
return _SurfaceArray[Level];
77
nuxAssertMsg(0, TEXT("[IOpenGLTexture2D::GetSurfaceLevel] Invalid surface level"));
79
return TRefGL<IOpenGLSurface>(0);
82
void IOpenGLTexture2D::GetSurfaceLevel(int Level, TRefGL<IOpenGLSurface>& surface)
85
surface = GetSurfaceLevel(Level);
88
int IOpenGLTexture2D::LockRect(
90
SURFACE_LOCKED_RECT * pLockedRect,
91
const SURFACE_RECT * pRect)
93
nuxAssertMsg(pLockedRect, TEXT("[IOpenGLTexture2D::LockRect] Invalid parameter 'pLockedRect'."));
94
nuxAssertMsg(Level >= 0, TEXT("[IOpenGLTexture2D::LockRect] Invalid mipmap level."));
95
nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLTexture2D::LockRect] Invalid mipmap level."));
97
if(Level < _NumMipLevel)
99
TRefGL<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level];
100
return pSurfaceLevel->LockRect(pLockedRect, pRect);
104
pLockedRect->pBits = 0;
105
pLockedRect->Pitch = 0;
106
return OGL_INVALID_SURFACE_LEVEL;
111
int IOpenGLTexture2D::UnlockRect(
114
nuxAssertMsg(Level >= 0, TEXT("[IOpenGLTexture2D::LockRect] Invalid mipmap level."));
115
nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLTexture2D::LockRect] Invalid mipmap level."));
117
if(Level < _NumMipLevel)
119
TRefGL<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level];
120
return pSurfaceLevel->UnlockRect();
124
return OGL_INVALID_SURFACE_LEVEL;
129
unsigned int IOpenGLTexture2D::EnableGammaCorrection(bool b)
131
nuxAssert(_OpenGLID);