~thumper/nux/next-changes

« back to all changes in this revision

Viewing changes to NuxGraphics/IOpenGLVolumeTexture.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 21:15:42 UTC
  • Revision ID: neil.patel@canonical.com-20100901211542-cw2ce3ak28unouwb
Add NuxGraphics with licensing

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 "GLDeviceObjects.h"
 
24
#include "IOpenGLVolumeTexture.h"
 
25
 
 
26
NAMESPACE_BEGIN_OGL
 
27
 
 
28
IMPLEMENT_OBJECT_TYPE(IOpenGLVolumeTexture);
 
29
 
 
30
IOpenGLVolumeTexture::IOpenGLVolumeTexture(
 
31
    unsigned int Width
 
32
    , unsigned int Height
 
33
    , unsigned int Depth
 
34
    , unsigned int Levels
 
35
    , BitmapFormat PixelFormat)
 
36
    : IOpenGLBaseTexture(RTVOLUMETEXTURE, Width, Height, Depth, Levels, PixelFormat)
 
37
{
 
38
    CHECKGL( glGenTextures(1, &_OpenGLID) );
 
39
    CHECKGL( glBindTexture(GL_TEXTURE_3D, _OpenGLID) );
 
40
 
 
41
    _VolumeSurfaceArray = new std::vector< TRefGL<IOpenGLSurface> >[_NumMipLevel];
 
42
    for (t_u32 mip = 0; mip < _NumMipLevel; mip++)
 
43
    {
 
44
        for (t_u32 slice = 0; slice < ImageSurface::GetLevelDim(_PixelFormat, _Depth, mip); slice++)
 
45
        {
 
46
            //IOpenGLSurface* surface = new IOpenGLSurface(this, _OpenGLID, GL_TEXTURE_3D, GL_TEXTURE_3D, mip, slice);
 
47
            //surface->InitializeLevel();
 
48
            _VolumeSurfaceArray[mip].push_back(new IOpenGLSurface(this, _OpenGLID, GL_TEXTURE_3D, GL_TEXTURE_3D, mip, slice));
 
49
        }
 
50
    }
 
51
 
 
52
    for (int mip = 0; mip < _NumMipLevel; mip++)
 
53
    {
 
54
        IOpenGLVolume* volume = new IOpenGLVolume(this, _OpenGLID, GL_TEXTURE_3D, GL_TEXTURE_3D, mip);
 
55
        volume->InitializeLevel();
 
56
        _VolumeArray.push_back(volume);
 
57
    }
 
58
 
 
59
    CHECKGL( glBindTexture(GL_TEXTURE_3D, _OpenGLID) );
 
60
    SetFiltering(GL_NEAREST, GL_NEAREST);
 
61
    SetWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
 
62
    SetRenderStates();
 
63
    GRunTimeStats.Register(this);
 
64
}
 
65
 
 
66
IOpenGLVolumeTexture::~IOpenGLVolumeTexture()
 
67
{
 
68
    
 
69
    for (t_u32 mip = 0; mip < _NumMipLevel; mip++)
 
70
    {
 
71
        for (t_u32 slice = 0; slice < ImageSurface::GetLevelDim(_PixelFormat, _Depth, mip); slice++)    
 
72
        {
 
73
            // destroying a surface
 
74
            _VolumeSurfaceArray[mip][slice] = 0;;
 
75
        }
 
76
        _VolumeSurfaceArray[mip].clear();
 
77
    }
 
78
    INL_SAFE_DELETE_ARRAY(_VolumeSurfaceArray);
 
79
 
 
80
 
 
81
    for (int mip = 0; mip < _NumMipLevel; mip++)
 
82
    {
 
83
        // destroying a IOpenGLVolume
 
84
        _VolumeArray[mip] = 0;
 
85
    }
 
86
 
 
87
    CHECKGL( glDeleteTextures(1, &_OpenGLID) );
 
88
    _OpenGLID = 0;
 
89
    GRunTimeStats.UnRegister(this);
 
90
}
 
91
 
 
92
int IOpenGLVolumeTexture::LockRect(
 
93
             int Slice,
 
94
             int Level,
 
95
             SURFACE_LOCKED_RECT * pLockedRect,
 
96
             const SURFACE_RECT * pRect)
 
97
{
 
98
    nuxAssertMsg(pLockedRect, TEXT("[IOpenGLVolumeTexture::LockRect] Invalid parameter 'pLockedRect'."));
 
99
    nuxAssertMsg(Level >= 0, TEXT("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level."));
 
100
    nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level."));
 
101
    nuxAssertMsg(Slice >= 0, TEXT("[IOpenGLVolumeTexture::LockRect] Invalid slice index."));
 
102
    nuxAssertMsg(Slice < ImageSurface::GetLevelDim(_PixelFormat, _Depth, Level), TEXT("[IOpenGLVolumeTexture::LockRect] Invalid slice index."));
 
103
 
 
104
    if(Slice<0)
 
105
        Slice = 0;
 
106
    if(Slice >= _Depth)
 
107
        Slice = _Depth-1;
 
108
 
 
109
    if(Level < _NumMipLevel)
 
110
    {
 
111
        TRefGL<IOpenGLSurface> pVolumeSurfaceLevel = _VolumeSurfaceArray[Level][Slice];
 
112
        return pVolumeSurfaceLevel->LockRect(pLockedRect, pRect);
 
113
    }
 
114
    else
 
115
    {
 
116
        pLockedRect->pBits = 0;
 
117
        pLockedRect->Pitch = 0;
 
118
        return OGL_INVALID_SURFACE_LEVEL;
 
119
    }
 
120
    return OGL_OK;
 
121
}
 
122
 
 
123
int IOpenGLVolumeTexture::UnlockRect(
 
124
               int Slice,
 
125
               int Level
 
126
               )
 
127
{
 
128
    nuxAssertMsg(Level >= 0, TEXT("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level."));
 
129
    nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLVolumeTexture::LockRect] Invalid mipmap level."));
 
130
 
 
131
    if(Level < _NumMipLevel)
 
132
    {
 
133
        TRefGL<IOpenGLSurface> pVolumeSurfaceLevel = _VolumeSurfaceArray[Level][Slice];
 
134
        return pVolumeSurfaceLevel->UnlockRect();
 
135
    }
 
136
    else
 
137
    {
 
138
        return OGL_INVALID_SURFACE_LEVEL;
 
139
    }
 
140
    return OGL_OK;
 
141
}
 
142
 
 
143
int IOpenGLVolumeTexture::LockBox(int Level,
 
144
                                  VOLUME_LOCKED_BOX * pLockedVolume,
 
145
                                  const VOLUME_BOX * pBox)
 
146
{
 
147
    nuxAssertMsg(pLockedVolume, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid parameter 'pLockedRect'."));
 
148
    nuxAssertMsg(Level >= 0, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level."));
 
149
    nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level."));
 
150
 
 
151
    if(pBox)
 
152
    {
 
153
        nuxAssertMsg(pBox->Front >= 0, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid slice index."));
 
154
        nuxAssertMsg(pBox->Front < pBox->Back, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid slice index."));
 
155
        nuxAssertMsg(pBox->Back <= ImageSurface::GetLevelDim(_PixelFormat, _Depth, Level),
 
156
            TEXT("[IOpenGLVolumeTexture::LockBox] Invalid slice index."));
 
157
    }
 
158
 
 
159
    return _VolumeArray[Level]->LockBox(pLockedVolume, pBox);
 
160
}
 
161
 
 
162
int IOpenGLVolumeTexture::UnlockBox(int Level)
 
163
{
 
164
    nuxAssertMsg(Level >= 0, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level."));
 
165
    nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLVolumeTexture::LockBox] Invalid mipmap level."));
 
166
 
 
167
    return _VolumeArray[Level]->UnlockBox();
 
168
}
 
169
 
 
170
NAMESPACE_END_OGL