Back to index

nux  3.0.0
GLTextureStates.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 GLTEXTURESTATES_H
00024 #define GLTEXTURESTATES_H
00025 
00026 #include "NuxCore/NuxCore.h"
00027 
00028 namespace nux
00029 {
00030 
00031   enum
00032   {
00033     GFXTS_ADDRESSU,                          // GL_REPEAT
00034     GFXTS_ADDRESSV,                          // GL_REPEAT
00035     GFXTS_ADDRESSW,                          // GL_REPEAT
00036 
00037     GFXTS_MINFILTER,                         // GL_NEAREST
00038     GFXTS_MAGFILTER,                         // GL_NEAREST
00039     GFXTS_MIPFILTER,                         // GL_NEAREST
00040 
00041     GFXTS_MIP_BASE_LEVEL,                    // 0
00042     GFXTS_MIP_MAX_LEVEL,                     // 1000
00043     GFXTS_MIN_LOD,                           // -1000
00044     GFXTS_MAX_LOD,                           // +1000
00045 
00046     GFXTS_BORDERCOLOR,                       // 0x00000000
00047 
00048 
00049     GFXTS_MAX_TEXTURESTATES,
00050   };
00051 
00052   struct TextureStateMap
00053   {
00054     bool           Checked;
00055     unsigned int    State;
00056     unsigned int    Dirty;
00057     unsigned int    iValue;
00058     float           fValue;
00059     TextureStateMap()
00060     {
00061       Dirty = true;
00062     }
00063   };
00064 
00065   class GpuDevice;
00066   class GLTextureStates
00067   {
00068   public:
00069     GLTextureStates(GLuint Type = GL_TEXTURE_2D);
00070     ~GLTextureStates();
00071 
00072     void ResetDefault();
00073     void ResetStateChangeToDefault();
00074     void SetRenderStates();
00075 
00076     void SetType(GLuint Type);
00077 
00078     void SetFiltering(
00079       unsigned int MIN = GL_NEAREST,
00080       unsigned int MAG = GL_NEAREST/*,
00081         unsigned int MIP = GL_NEAREST*/);
00082 
00083     void SetWrap(
00084       unsigned int U = GL_REPEAT,
00085       unsigned int V = GL_REPEAT,
00086       unsigned int W = GL_REPEAT);
00087 
00088     void SetLOD(
00089       float MinLod = -1000.0f,
00090       float MaxLod = +1000.0f);
00091 
00092     void SetMipLevel(
00093       unsigned int MinMip = 0,
00094       unsigned int MaxMip = 1000);
00095 
00096     void SetBorderColor(
00097       float R,
00098       float G,
00099       float B,
00100       float A);
00101 
00102   private:
00103     void HW_SetFiltering();
00104     void HW_SetWrap();
00105     void HW_SetLOD();
00106     void HW_SetMipLevel();
00107     void HW_SetBorderColor();
00108 
00109     GLuint m_Type;
00110     TextureStateMap m_TextureStateChanges[GFXTS_MAX_TEXTURESTATES];
00111 
00112     friend class GpuDevice;
00113   };
00114 
00115 // #define SET_TS_VALUE(a, b)  (a).iValue = (b); (a).Dirty = true;
00116 // #define TS_VALUE(a, b)      (a).iValue
00117 //
00118 // #define SET_TS_VALUE_FLOAT(a, b)  (a).fValue = (b); (a).Dirty = true;
00119 // #define TS_VALUE_FLOAT(a, b)      (a).fValue
00120 //
00121 //
00122 // inline void GLTextureStates::SetFiltering(
00123 //                          unsigned int MIN,
00124 //                          unsigned int MAG
00125 //                          /*,unsigned int MIP*/)
00126 // {
00127 //     nuxAssertMsg(
00128 //         (MIN == GL_LINEAR) ||
00129 //         (MIN == GL_NEAREST) ||
00130 //         (MIN == GL_NEAREST_MIPMAP_NEAREST) ||
00131 //         (MIN == GL_LINEAR_MIPMAP_NEAREST) ||
00132 //         (MIN == GL_NEAREST_MIPMAP_LINEAR) ||
00133 //         (MIN == GL_LINEAR_MIPMAP_LINEAR),
00134 //         "Error[GLTextureStates::SetFiltering]: Invalid Min. Filter State");
00135 //
00136 //     nuxAssertMsg(
00137 //         (MAG == GL_LINEAR) ||
00138 //         (MAG == GL_NEAREST),
00139 //         "Error[GLTextureStates::SetFiltering]: Invalid Mag. Filter State");
00140 //
00141 // //    nuxAssertMsg(
00142 // //        (MIP == GL_LINEAR) ||
00143 // //        (MIP == GL_NEAREST),
00144 // //        "Error[GLTextureStates::SetFiltering]: Invalid Mipmap Filter State");
00145 //
00146 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_MINFILTER], MIN);
00147 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_MAGFILTER], MAG);
00148 //     //SET_TS_VALUE(m_TextureStateChanges[GFXTS_MIPFILTER], MIP);
00149 // }
00150 //
00151 // inline void GLTextureStates::SetWrap(
00152 //                     unsigned int U,
00153 //                     unsigned int V,
00154 //                     unsigned int W)
00155 // {
00156 //     nuxAssertMsg(
00157 //         (U == GL_CLAMP) ||
00158 //         (U == GL_CLAMP_TO_EDGE) ||
00159 //         (U == GL_REPEAT),
00160 //         "Error[GLTextureStates::SetWrap]: Invalid U Wrap State");
00161 //     nuxAssertMsg(
00162 //         (V == GL_CLAMP) ||
00163 //         (V == GL_CLAMP_TO_EDGE) ||
00164 //         (V == GL_REPEAT),
00165 //         "Error[GLTextureStates::SetWrap]: Invalid V Wrap State");
00166 //     nuxAssertMsg(
00167 //         (W == GL_CLAMP) ||
00168 //         (W == GL_CLAMP_TO_EDGE) ||
00169 //         (W == GL_REPEAT),
00170 //         "Error[GLTextureStates::SetWrap]: Invalid W Wrap State");
00171 //
00172 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_ADDRESSU], U);
00173 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_ADDRESSV], V);
00174 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_ADDRESSW], W);
00175 //
00176 //
00177 // }
00178 //
00179 // inline void GLTextureStates::SetLOD(float MinLod,
00180 //                                     float MaxLod)
00181 // {
00182 //     SET_TS_VALUE_FLOAT(m_TextureStateChanges[GFXTS_MIN_LOD], MinLod);
00183 //     SET_TS_VALUE_FLOAT(m_TextureStateChanges[GFXTS_MAX_LOD], MaxLod);
00184 // }
00185 //
00186 // inline void GLTextureStates::SetMipLevel(
00187 //                         unsigned int MinMip,
00188 //                         unsigned int MaxMip)
00189 // {
00190 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_MIP_BASE_LEVEL], MinMip);
00191 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_MIP_MAX_LEVEL], MaxMip);
00192 // }
00193 //
00194 // inline void GLTextureStates::SetBorderColor(
00195 //                            float R,
00196 //                            float G,
00197 //                            float B,
00198 //                            float A)
00199 // {
00200 //     unsigned int r, g, b, a;
00201 //     r = 255 * Clamp(R, 0.0f, 1.0f);
00202 //     g = 255 * Clamp(G, 0.0f, 1.0f);
00203 //     b = 255 * Clamp(B, 0.0f, 1.0f);
00204 //     a = 255 * Clamp(A, 0.0f, 1.0f);
00205 //     unsigned int color = (unsigned int) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b));
00206 //
00207 //     SET_TS_VALUE(m_TextureStateChanges[GFXTS_BORDERCOLOR], color);
00208 // }
00209 //
00210 // #undef SET_TS_VALUE
00211 // #undef TS_VALUE
00212 //
00213 // #undef SET_TS_VALUE_FLOAT
00214 // #undef TS_VALUE_FLOAT
00215 
00216 }
00217 
00218 #endif // GLTEXTURESTATES_H
00219