Back to index

nux  3.0.0
IOpenGLBaseTexture.h
Go to the documentation of this file.
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 
00023 #ifndef IOPENGLBASETEXTURE_H
00024 #define IOPENGLBASETEXTURE_H
00025 
00026 #include "GLResource.h"
00027 #include "IOpenGLResource.h"
00028 #include "GLShaderParameter.h"
00029 #include "GLTextureStates.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class IOpenGLResource;
00035   class IOpenGLBaseTexture;
00036 
00037   int GetTextureSize(IOpenGLBaseTexture *pTexture);
00038 
00039 // todo: It should not be possible to create an object of type IOpenGLBaseTexture directly.
00040   class IOpenGLBaseTexture: public IOpenGLResource
00041   {
00042     NUX_DECLARE_OBJECT_TYPE(IOpenGLBaseTexture, IOpenGLResource);
00043 
00044   public:
00045 
00046     IOpenGLBaseTexture(OpenGLResourceType ResourceType,
00047                         unsigned int Width,
00048                         unsigned int Height,
00049                         unsigned int Depth,
00050                         unsigned int NumMipLevel,
00051                         BitmapFormat PixelFormat, NUX_FILE_LINE_PROTO);
00052 
00053     virtual ~IOpenGLBaseTexture();
00054 
00055     BitmapFormat GetPixelFormat() const
00056     {
00057       return _PixelFormat;
00058     }
00059     int GetNumMipLevel() const
00060     {
00061       return _NumMipLevel;
00062     }
00063     bool IsPowerOfTwo() const
00064     {
00065       return _IsPOT;
00066     }
00067 
00068     int GetWidth() const
00069     {
00070       if (_ResourceType == RTTEXTURE)
00071         return _Width;
00072 
00073       if (_ResourceType == RTTEXTURERECTANGLE)
00074         return _Width;
00075 
00076       if (_ResourceType == RTCUBETEXTURE)
00077         return _Width;
00078 
00079       return 0;
00080     }
00081 
00082     int GetHeight() const
00083     {
00084       if (_ResourceType == RTTEXTURE)
00085         return _Height;
00086 
00087       if (_ResourceType == RTTEXTURERECTANGLE)
00088         return _Height;
00089 
00090       if (_ResourceType == RTCUBETEXTURE)
00091         return _Width;
00092 
00093       return 0;
00094     }
00095 
00096     int GetDepth() const
00097     {
00098       if (_ResourceType == RTTEXTURE)
00099         return 1;
00100 
00101       if (_ResourceType == RTTEXTURERECTANGLE)
00102         return 1;
00103 
00104       if (_ResourceType == RTCUBETEXTURE)
00105         return 1;
00106 
00107       if (_ResourceType == RTVOLUMETEXTURE)
00108         return _Depth;
00109 
00110       if (_ResourceType == RTANIMATEDTEXTURE)
00111         return _Depth;
00112 
00113       return 0;
00114     }
00115 
00116     int GetFormatRowMemoryAlignment() const
00117     {
00118       return _RowMemoryAlignment;
00119     }
00120     //GLTextureStates& GetTextureStates() {return _TextureStates;}
00121 
00122     void SetRenderStates();
00123     void SetFiltering(unsigned int MIN = GL_NEAREST, unsigned int MAG = GL_NEAREST/*, unsigned int MIP = GL_NEAREST*/);
00124     void SetWrap(unsigned int U = GL_REPEAT, unsigned int V = GL_REPEAT, unsigned int W = GL_REPEAT);
00125     void SetLOD(float MinLod = -1000.0f, float MaxLod = +1000.0f);
00126     void SetMipLevel(unsigned int MinMip = 0, unsigned int MaxMip = 1000);
00127     void SetBorderColor(float R, float G, float B, float A);
00128 
00129     int BindTexture();
00130     int BindTextureToUnit(int TextureUnitIndex);
00131 
00132     virtual void GetSurfaceLevel(int Level, ObjectPtr<IOpenGLSurface>& surface);
00133     virtual ObjectPtr<IOpenGLSurface> GetSurfaceLevel(int Level);
00134     virtual int LockRect(
00135       int Level,
00136       SURFACE_LOCKED_RECT *pLockedRect,
00137       const SURFACE_RECT *pRect);
00138 
00139     virtual int UnlockRect(int Level);
00140 
00142 
00152     virtual unsigned char* GetSurfaceData(int level, int &width, int &height, int &stride);
00153 
00154   protected:
00155     GLTextureStates _TextureStates;
00156     bool            _IsPOT;             // is power of two?
00157     int           _NumMipLevel;
00158     BitmapFormat    _PixelFormat;
00159 
00160     // These parameters are scalable across textures, cube textures and volume textures.
00161     // For texture and cube texture _Depth is equal to 1.
00162     // For cube texture, _Width = _Height
00163     int        _Width;
00164     int        _Height;
00165     int         _Depth;
00166     int         _RowMemoryAlignment;
00167 
00168     friend class IOpenGLSurface;
00169     friend class IOpenGLVolume;
00170     friend void GetTextureDesc(
00171       IOpenGLBaseTexture *pTexture,
00172       unsigned int Level,
00173       TEXTURE_DESC *pDesc
00174     );
00175     friend int GetTextureSize(IOpenGLBaseTexture *pTexture);
00176   };
00177 
00178 }
00179 
00180 #endif // IOPENGLBASETEXTURE_H