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 "GpuDevice.h"
24
#include "GLDeviceObjects.h"
25
#include "IOpenGLAnimatedTexture.h"
31
NUX_IMPLEMENT_OBJECT_TYPE (IOpenGLAnimatedTexture);
33
IOpenGLAnimatedTexture::IOpenGLAnimatedTexture (
37
, BitmapFormat PixelFormat)
38
: IOpenGLBaseTexture (RTANIMATEDTEXTURE, Width, Height, Depth, 1, PixelFormat)
41
for (int i = 0; i < Depth; i++)
43
IntrusiveSP<IOpenGLBaseTexture> Texture = GetThreadGLDeviceFactory()->CreateSystemCapableDeviceTexture (Width, Height, 1, PixelFormat);
44
_FrameTextureArray.push_back (Texture);
45
_FrameTimeArray.push_back (41); // 41 ms = 24 frames/second
48
_OpenGLID = _FrameTextureArray[0]->GetOpenGLID();
50
SetFiltering (GL_NEAREST, GL_NEAREST);
51
SetWrap (GL_CLAMP, GL_CLAMP, GL_CLAMP);
55
IOpenGLAnimatedTexture::~IOpenGLAnimatedTexture()
57
for (int i = 0; i < _Depth; i++)
59
_FrameTextureArray[i].Release();
62
_FrameTextureArray.clear();
63
_FrameTimeArray.clear();
67
IntrusiveSP<IOpenGLSurface> IOpenGLAnimatedTexture::GetSurfaceFrame (int Frame)
69
nuxAssert (Frame >= 0);
70
nuxAssert (Frame < _Depth);
72
if ( (Frame >= 0) && (Frame < _Depth) )
74
return _FrameTextureArray[Frame]->GetSurfaceLevel (0);
78
nuxAssertMsg (0, TEXT ("[IOpenGLAnimatedTexture::GetSurfaceFrame] Invalid surface level") );
81
return IntrusiveSP<IOpenGLSurface> (0);
84
void IOpenGLAnimatedTexture::GetSurfaceFrame (int Frame, IntrusiveSP<IOpenGLSurface>& surface)
86
surface = IntrusiveSP<IOpenGLSurface> (0);
87
surface = GetSurfaceFrame (Frame);
90
int IOpenGLAnimatedTexture::LockRect (
92
SURFACE_LOCKED_RECT *pLockedRect,
93
const SURFACE_RECT *pRect)
95
return _FrameTextureArray[Frame]->LockRect (0, pLockedRect, pRect);
98
int IOpenGLAnimatedTexture::UnlockRect (
101
return _FrameTextureArray[Frame]->UnlockRect (0);
104
void IOpenGLAnimatedTexture::PresentFirstFrame()
107
_OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID();
110
void IOpenGLAnimatedTexture::PresentNextFrame()
114
if (_CurrentFrame >= _Depth)
117
_OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID();
120
void IOpenGLAnimatedTexture::PresentLastFrame()
122
_CurrentFrame = _Depth - 1;
123
_OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID();
126
void IOpenGLAnimatedTexture::SetFrameTime (int Frame, int time_ms)
128
nuxAssert (_CurrentFrame < (int) _FrameTimeArray.size() );
129
_FrameTimeArray[Frame] = time_ms;
132
int IOpenGLAnimatedTexture::GetFrameTime()
134
nuxAssert (_CurrentFrame < (int) _FrameTimeArray.size() );
135
return _FrameTimeArray[_CurrentFrame];
138
t_u32 IOpenGLAnimatedTexture::GetNumFrame()