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 #include "GLResource.h" 00023 #include "GraphicsDisplay.h" 00024 #include "GpuDevice.h" 00025 #include "GLDeviceObjects.h" 00026 #include "IOpenGLAnimatedTexture.h" 00027 00028 00029 namespace nux 00030 { 00031 00032 NUX_IMPLEMENT_OBJECT_TYPE (IOpenGLAnimatedTexture); 00033 00034 IOpenGLAnimatedTexture::IOpenGLAnimatedTexture ( 00035 int Width 00036 , int Height 00037 , int Depth 00038 , BitmapFormat PixelFormat) 00039 : IOpenGLBaseTexture (RTANIMATEDTEXTURE, Width, Height, Depth, 1, PixelFormat) 00040 , _CurrentFrame (0) 00041 { 00042 for (int i = 0; i < Depth; i++) 00043 { 00044 ObjectPtr<IOpenGLBaseTexture> Texture = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture (Width, Height, 1, PixelFormat); 00045 _FrameTextureArray.push_back (Texture); 00046 _FrameTimeArray.push_back (41); // 41 ms = 24 frames/second 00047 } 00048 00049 _OpenGLID = _FrameTextureArray[0]->GetOpenGLID(); 00050 00051 SetFiltering (GL_NEAREST, GL_NEAREST); 00052 SetWrap (GL_CLAMP, GL_CLAMP, GL_CLAMP); 00053 SetRenderStates(); 00054 } 00055 00056 IOpenGLAnimatedTexture::~IOpenGLAnimatedTexture() 00057 { 00058 for (int i = 0; i < _Depth; i++) 00059 { 00060 _FrameTextureArray[i].Release(); 00061 } 00062 00063 _FrameTextureArray.clear(); 00064 _FrameTimeArray.clear(); 00065 } 00066 00067 00068 ObjectPtr<IOpenGLSurface> IOpenGLAnimatedTexture::GetSurfaceFrame (int Frame) 00069 { 00070 nuxAssert (Frame >= 0); 00071 nuxAssert (Frame < _Depth); 00072 00073 if ( (Frame >= 0) && (Frame < _Depth) ) 00074 { 00075 return _FrameTextureArray[Frame]->GetSurfaceLevel (0); 00076 } 00077 else 00078 { 00079 nuxAssertMsg (0, TEXT ("[IOpenGLAnimatedTexture::GetSurfaceFrame] Invalid surface level") ); 00080 } 00081 00082 return ObjectPtr<IOpenGLSurface> (0); 00083 } 00084 00085 void IOpenGLAnimatedTexture::GetSurfaceFrame (int Frame, ObjectPtr<IOpenGLSurface>& surface) 00086 { 00087 surface = ObjectPtr<IOpenGLSurface> (0); 00088 surface = GetSurfaceFrame (Frame); 00089 } 00090 00091 int IOpenGLAnimatedTexture::LockRect ( 00092 int Frame, 00093 SURFACE_LOCKED_RECT *pLockedRect, 00094 const SURFACE_RECT *pRect) 00095 { 00096 return _FrameTextureArray[Frame]->LockRect (0, pLockedRect, pRect); 00097 } 00098 00099 int IOpenGLAnimatedTexture::UnlockRect ( 00100 int Frame) 00101 { 00102 return _FrameTextureArray[Frame]->UnlockRect (0); 00103 } 00104 00105 void IOpenGLAnimatedTexture::PresentFirstFrame() 00106 { 00107 _CurrentFrame = 0; 00108 _OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID(); 00109 } 00110 00111 void IOpenGLAnimatedTexture::PresentNextFrame() 00112 { 00113 ++_CurrentFrame; 00114 00115 if (_CurrentFrame >= _Depth) 00116 _CurrentFrame = 0; 00117 00118 _OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID(); 00119 } 00120 00121 void IOpenGLAnimatedTexture::PresentLastFrame() 00122 { 00123 _CurrentFrame = _Depth - 1; 00124 _OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID(); 00125 } 00126 00127 void IOpenGLAnimatedTexture::SetFrameTime (int Frame, int time_ms) 00128 { 00129 nuxAssert (_CurrentFrame < (int) _FrameTimeArray.size() ); 00130 _FrameTimeArray[Frame] = time_ms; 00131 } 00132 00133 int IOpenGLAnimatedTexture::GetFrameTime() 00134 { 00135 nuxAssert (_CurrentFrame < (int) _FrameTimeArray.size() ); 00136 return _FrameTimeArray[_CurrentFrame]; 00137 } 00138 00139 t_u32 IOpenGLAnimatedTexture::GetNumFrame() 00140 { 00141 return _Depth; 00142 } 00143 00144 }