~thumper/nux/next-changes

« back to all changes in this revision

Viewing changes to NuxGraphics/IOpenGLRectangleTexture.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 "IOpenGLRectangleTexture.h"
 
25
 
 
26
NAMESPACE_BEGIN_OGL
 
27
 
 
28
IMPLEMENT_OBJECT_TYPE(IOpenGLRectangleTexture);
 
29
 
 
30
IOpenGLRectangleTexture::IOpenGLRectangleTexture(
 
31
    unsigned int Width
 
32
    , unsigned int Height
 
33
    , unsigned int Levels
 
34
    , BitmapFormat PixelFormat, bool Dummy)
 
35
    : IOpenGLBaseTexture(RTTEXTURERECTANGLE, Width, Height, 1, Levels, PixelFormat)
 
36
{
 
37
    if(Dummy == false)
 
38
    {
 
39
        glGenTextures(1, &_OpenGLID);
 
40
        CHECKGL( glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _OpenGLID) );
 
41
    }
 
42
 
 
43
    //_SurfaceArray.Empty(Levels);
 
44
    for(unsigned int l = 0; l < Levels; l++)
 
45
    {
 
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 );
 
49
    }
 
50
 
 
51
    SetFiltering(GL_NEAREST, GL_NEAREST);
 
52
    SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
 
53
    SetRenderStates();
 
54
    GRunTimeStats.Register(this);
 
55
}
 
56
 
 
57
IOpenGLRectangleTexture::~IOpenGLRectangleTexture()
 
58
{
 
59
    for(int l = 0; l < _NumMipLevel; l++)
 
60
    {
 
61
        _SurfaceArray[l] = 0;
 
62
    }
 
63
    _SurfaceArray.clear();
 
64
    CHECKGL( glDeleteTextures(1, &_OpenGLID) );
 
65
    _OpenGLID = 0;
 
66
    GRunTimeStats.UnRegister(this);
 
67
}
 
68
 
 
69
TRefGL<IOpenGLSurface> IOpenGLRectangleTexture::GetSurfaceLevel(int Level)
 
70
{
 
71
    if(Level < _NumMipLevel)
 
72
    {
 
73
        return _SurfaceArray[Level];
 
74
    }
 
75
    else
 
76
    {
 
77
        nuxAssertMsg(0, TEXT("[IOpenGLRectangleTexture::GetSurfaceLevel] Invalid surface level"));
 
78
    }
 
79
    return TRefGL<IOpenGLSurface>(0);
 
80
}
 
81
 
 
82
void IOpenGLRectangleTexture::GetSurfaceLevel(int Level, TRefGL<IOpenGLSurface>& surface)
 
83
{
 
84
    surface = 0;
 
85
    surface = GetSurfaceLevel(Level);
 
86
}
 
87
 
 
88
int IOpenGLRectangleTexture::LockRect(
 
89
                                      int Level,
 
90
                                      SURFACE_LOCKED_RECT * pLockedRect,
 
91
                                      const SURFACE_RECT * pRect)
 
92
{
 
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."));
 
96
 
 
97
 
 
98
    if(Level < _NumMipLevel)
 
99
    {
 
100
        TRefGL<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level];
 
101
        return pSurfaceLevel->LockRect(pLockedRect, pRect);
 
102
    }
 
103
    else
 
104
    {
 
105
        pLockedRect->pBits = 0;
 
106
        pLockedRect->Pitch = 0;
 
107
        return OGL_INVALID_SURFACE_LEVEL;
 
108
    }
 
109
    return OGL_OK;
 
110
}
 
111
 
 
112
int IOpenGLRectangleTexture::UnlockRect(
 
113
                                        int Level
 
114
                                        )
 
115
{
 
116
    nuxAssertMsg(Level >= 0, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level."));
 
117
    nuxAssertMsg(Level < _NumMipLevel, TEXT("[IOpenGLRectangleTexture::LockRect] Invalid mipmap level."));
 
118
 
 
119
    if(Level < _NumMipLevel)
 
120
    {
 
121
        TRefGL<IOpenGLSurface> pSurfaceLevel = _SurfaceArray[Level];
 
122
        return pSurfaceLevel->UnlockRect();
 
123
    }
 
124
    else
 
125
    {
 
126
        return OGL_INVALID_SURFACE_LEVEL;
 
127
    }
 
128
    return OGL_OK;
 
129
}
 
130
 
 
131
unsigned int IOpenGLRectangleTexture::EnableGammaCorrection(bool b)
 
132
{
 
133
    nuxAssert(_OpenGLID);
 
134
    return OGL_OK;
 
135
}
 
136
 
 
137
NAMESPACE_END_OGL