~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxGraphics/IOpenGLAnimatedTexture.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
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.
 
7
 *
 
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.
 
13
 *
 
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/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "GpuDevice.h"
 
24
#include "GLDeviceObjects.h"
 
25
#include "IOpenGLAnimatedTexture.h"
 
26
 
 
27
 
 
28
namespace nux
 
29
{
 
30
 
 
31
  NUX_IMPLEMENT_OBJECT_TYPE (IOpenGLAnimatedTexture);
 
32
 
 
33
  IOpenGLAnimatedTexture::IOpenGLAnimatedTexture (
 
34
    int Width
 
35
    , int Height
 
36
    , int Depth
 
37
    , BitmapFormat PixelFormat)
 
38
    :    IOpenGLBaseTexture (RTANIMATEDTEXTURE, Width, Height, Depth, 1, PixelFormat)
 
39
    ,    _CurrentFrame (0)
 
40
  {
 
41
    for (int i = 0; i < Depth; i++)
 
42
    {
 
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
 
46
    }
 
47
 
 
48
    _OpenGLID = _FrameTextureArray[0]->GetOpenGLID();
 
49
 
 
50
    SetFiltering (GL_NEAREST, GL_NEAREST);
 
51
    SetWrap (GL_CLAMP, GL_CLAMP, GL_CLAMP);
 
52
    SetRenderStates();
 
53
  }
 
54
 
 
55
  IOpenGLAnimatedTexture::~IOpenGLAnimatedTexture()
 
56
  {
 
57
    for (int i = 0; i < _Depth; i++)
 
58
    {
 
59
      _FrameTextureArray[i].Release();
 
60
    }
 
61
 
 
62
    _FrameTextureArray.clear();
 
63
    _FrameTimeArray.clear();
 
64
  }
 
65
 
 
66
 
 
67
  IntrusiveSP<IOpenGLSurface> IOpenGLAnimatedTexture::GetSurfaceFrame (int Frame)
 
68
  {
 
69
    nuxAssert (Frame >= 0);
 
70
    nuxAssert (Frame < _Depth);
 
71
 
 
72
    if ( (Frame >= 0) && (Frame < _Depth) )
 
73
    {
 
74
      return _FrameTextureArray[Frame]->GetSurfaceLevel (0);
 
75
    }
 
76
    else
 
77
    {
 
78
      nuxAssertMsg (0, TEXT ("[IOpenGLAnimatedTexture::GetSurfaceFrame] Invalid surface level") );
 
79
    }
 
80
 
 
81
    return IntrusiveSP<IOpenGLSurface> (0);
 
82
  }
 
83
 
 
84
  void IOpenGLAnimatedTexture::GetSurfaceFrame (int Frame, IntrusiveSP<IOpenGLSurface>& surface)
 
85
  {
 
86
    surface = IntrusiveSP<IOpenGLSurface> (0);
 
87
    surface = GetSurfaceFrame (Frame);
 
88
  }
 
89
 
 
90
  int IOpenGLAnimatedTexture::LockRect (
 
91
    int Frame,
 
92
    SURFACE_LOCKED_RECT *pLockedRect,
 
93
    const SURFACE_RECT *pRect)
 
94
  {
 
95
    return _FrameTextureArray[Frame]->LockRect (0, pLockedRect, pRect);
 
96
  }
 
97
 
 
98
  int IOpenGLAnimatedTexture::UnlockRect (
 
99
    int Frame)
 
100
  {
 
101
    return _FrameTextureArray[Frame]->UnlockRect (0);
 
102
  }
 
103
 
 
104
  void IOpenGLAnimatedTexture::PresentFirstFrame()
 
105
  {
 
106
    _CurrentFrame = 0;
 
107
    _OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID();
 
108
  }
 
109
 
 
110
  void IOpenGLAnimatedTexture::PresentNextFrame()
 
111
  {
 
112
    ++_CurrentFrame;
 
113
 
 
114
    if (_CurrentFrame >= _Depth)
 
115
      _CurrentFrame = 0;
 
116
 
 
117
    _OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID();
 
118
  }
 
119
 
 
120
  void IOpenGLAnimatedTexture::PresentLastFrame()
 
121
  {
 
122
    _CurrentFrame = _Depth - 1;
 
123
    _OpenGLID = _FrameTextureArray[_CurrentFrame]->GetOpenGLID();
 
124
  }
 
125
 
 
126
  void IOpenGLAnimatedTexture::SetFrameTime (int Frame, int time_ms)
 
127
  {
 
128
    nuxAssert (_CurrentFrame < (int) _FrameTimeArray.size() );
 
129
    _FrameTimeArray[Frame] = time_ms;
 
130
  }
 
131
 
 
132
  int IOpenGLAnimatedTexture::GetFrameTime()
 
133
  {
 
134
    nuxAssert (_CurrentFrame < (int) _FrameTimeArray.size() );
 
135
    return _FrameTimeArray[_CurrentFrame];
 
136
  }
 
137
 
 
138
  t_u32 IOpenGLAnimatedTexture::GetNumFrame()
 
139
  {
 
140
    return _Depth;
 
141
  }
 
142
 
 
143
}