nux-0.9.48

NuxGraphics/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   t_s32 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                         t_u32 Width,
00048                         t_u32 Height,
00049                         t_u32 Depth,
00050                         t_u32 NumMipLevel,
00051                         BitmapFormat PixelFormat, NUX_FILE_LINE_PROTO);
00052 
00053     virtual ~IOpenGLBaseTexture();
00054 
00055     BitmapFormat GetPixelFormat() const
00056     {
00057       return _PixelFormat;
00058     }
00059     t_s32 GetNumMipLevel() const
00060     {
00061       return _NumMipLevel;
00062     }
00063     bool IsPowerOfTwo() const
00064     {
00065       return _IsPOT;
00066     }
00067 
00068     t_s32 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     t_s32 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     t_s32 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 (t_u32 MIN = GL_NEAREST, t_u32 MAG = GL_NEAREST/*, t_u32 MIP = GL_NEAREST*/);
00124     void SetWrap (t_u32 U = GL_REPEAT, t_u32 V = GL_REPEAT, t_u32 W = GL_REPEAT);
00125     void SetLOD (float MinLod = -1000.0f, float MaxLod = +1000.0f);
00126     void SetMipLevel (t_u32 MinMip = 0, t_u32 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 (
00140       int Level
00141       );
00142 
00144     virtual void* GetSurfaceData (int level, int &width, int &height, int &format);
00145 
00146   protected:
00147     GLTextureStates _TextureStates;
00148     bool            _IsPOT;             // is power of two?
00149     t_s32           _NumMipLevel;
00150     BitmapFormat    _PixelFormat;
00151 
00152     // These parameters are scalable across textures, cube textures and volume textures.
00153     // For texture and cube texture _Depth is equal to 1.
00154     // For cube texture, _Width = _Height
00155     t_s32        _Width;
00156     t_s32        _Height;
00157     int         _Depth;
00158     int         _RowMemoryAlignment;
00159 
00160     friend class IOpenGLSurface;
00161     friend class IOpenGLVolume;
00162     friend void GetTextureDesc (
00163       IOpenGLBaseTexture *pTexture,
00164       t_u32 Level,
00165       TEXTURE_DESC *pDesc
00166     );
00167     friend t_s32 GetTextureSize (IOpenGLBaseTexture *pTexture);
00168   };
00169 
00170 }
00171 
00172 #endif // IOPENGLBASETEXTURE_H