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 "IOpenGLRectangleTexture.h"
28
IMPLEMENT_OBJECT_TYPE(IOpenGLRectangleTexture);
30
IOpenGLRectangleTexture::IOpenGLRectangleTexture(
34
, BitmapFormat PixelFormat, bool Dummy)
35
: IOpenGLBaseTexture(RTTEXTURERECTANGLE, Width, Height, 1, Levels, PixelFormat)
39
glGenTextures(1, &_OpenGLID);
40
CHECKGL( glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _OpenGLID) );
43
//_SurfaceArray.Empty(Levels);
44
for(unsigned int l = 0; l < Levels; l++)
46
IOpenGLSurface* surface = new IOpenGLSurface(this, _OpenGLID, GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_RECTANGLE_ARB, l);
47
if(Dummy == false) surface->InitializeLevel();
48
_SurfaceArray.push_back( surface );
51
SetFiltering(GL_NEAREST, GL_NEAREST);
52
SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
54
GRunTimeStats.Register(this);
57
IOpenGLRectangleTexture::~IOpenGLRectangleTexture()
59
for(int l = 0; l < _NumMipLevel; l++)
63
_SurfaceArray.clear();
64
CHECKGL( glDeleteTextures(1, &_OpenGLID) );
66
GRunTimeStats.UnRegister(this);
69
TRefGL<IOpenGLSurface> IOpenGLRectangleTexture::GetSurfaceLevel(int Level)
71
if(Level < _NumMipLevel)
73
return _SurfaceArray[Level];
77
nuxAssertMsg(0, TEXT("[IOpenGLRectangleTexture::GetSurfaceLevel] Invalid surface level"));
79
return TRefGL<IOpenGLSurface>(0);
82
void IOpenGLRectangleTexture::GetSurfaceLevel(int Level, TRefGL<IOpenGLSurface>& surface)
85
surface = GetSurfaceLevel(Level);
88
int IOpenGLRectangleTexture::LockRect(
90
SURFACE_LOCKED_RECT * pLockedRect,
91
const SURFACE_RECT * pRect)
93
nuxAssertMsg(pLockedRect, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid parameter 'pLockedRect'."));
94
nuxAssertMsg(Level >= 0, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level."));
95
nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level."));
98
if(Level < _NumMipLevel)
100
TRefGL<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level];
101
return pSurfaceLevel->LockRect(pLockedRect, pRect);
105
pLockedRect->pBits = 0;
106
pLockedRect->Pitch = 0;
107
return OGL_INVALID_SURFACE_LEVEL;
112
int IOpenGLRectangleTexture::UnlockRect(
116
nuxAssertMsg(Level >= 0, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level."));
117
nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level."));
119
if(Level < _NumMipLevel)
121
TRefGL<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level];
122
return pSurfaceLevel->UnlockRect();
126
return OGL_INVALID_SURFACE_LEVEL;
131
unsigned int IOpenGLRectangleTexture::EnableGammaCorrection(bool b)
133
nuxAssert(_OpenGLID);