~thumper/nux/next-changes

« back to all changes in this revision

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