Back to index

nux  3.0.0
IOpenGLAsmShader.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 IOPENGLASMSHADER_H
00024 #define IOPENGLASMSHADER_H
00025 
00026 namespace nux
00027 {
00028 
00029   typedef enum
00030   {
00031     VTXATTRIB_INVALID           = -1,
00032     VTXATTRIB_POSITION          = 0,
00033     VTXATTRIB_WEIGHT            = 1,
00034     VTXATTRIB_NORMAL            = 2,
00035     VTXATTRIB_COLOR             = 3,
00036     VTXATTRIB_COLOR_PRIMARY     = 3,
00037     VTXATTRIB_COLOR_SECONDARY   = 4,
00038     VTXATTRIB_FOGCOORD          = 5,
00039     VTXATTRIB_TEXCOORD          = 8,
00040     VTXATTRIB_TEXCOORD0         = 8,
00041     VTXATTRIB_TEXCOORD1         = 9,
00042     VTXATTRIB_TEXCOORD2         = 10,
00043     VTXATTRIB_TEXCOORD3         = 11,
00044     VTXATTRIB_TEXCOORD4         = 12,
00045     VTXATTRIB_TEXCOORD5         = 13,
00046     VTXATTRIB_TEXCOORD6         = 14,
00047     VTXATTRIB_TEXCOORD7         = 15,
00048   } VtxAttributeIndex;
00049 
00050   class IOpenGLResource;
00051 
00052   class IOpenGLAsmShader:  public IOpenGLResource
00053   {
00054     NUX_DECLARE_OBJECT_TYPE(IOpenGLAsmShader, IOpenGLResource);
00055     IOpenGLAsmShader(NString ShaderName, OpenGLResourceType ResourceType);
00056     virtual ~IOpenGLAsmShader();
00057   public:
00058     virtual void SetShaderCode(const ANSICHAR *ShaderCode) = 0;
00059     virtual bool Compile() = 0;
00060     virtual bool IsValid() = 0;
00061     NString _ShaderName;
00062     NString _ShaderCode;
00063   };
00064 
00065   class IOpenGLAsmVertexShader:  public IOpenGLAsmShader
00066   {
00067     NUX_DECLARE_OBJECT_TYPE(IOpenGLAsmVertexShader, IOpenGLAsmShader);
00068   public:
00069     virtual ~IOpenGLAsmVertexShader();
00070     virtual void SetShaderCode(const ANSICHAR *ShaderCode);
00071     virtual bool Compile();
00072     virtual bool IsValid();
00073   private:
00074     IOpenGLAsmVertexShader(NString ShaderName = NString("VertexProgram"));
00075     bool m_CompiledAndReady;
00076     friend class GpuDevice;
00077   };
00078 
00079   class IOpenGLAsmPixelShader:  public IOpenGLAsmShader
00080   {
00081     NUX_DECLARE_OBJECT_TYPE(IOpenGLAsmPixelShader, IOpenGLAsmShader);
00082   public:
00083     virtual ~IOpenGLAsmPixelShader();
00084     virtual void SetShaderCode(const ANSICHAR *ShaderCode);
00085     virtual bool Compile();
00086     virtual bool IsValid();
00087   private:
00088     IOpenGLAsmPixelShader(NString ShaderName = NString("PixelProgram"));
00089     bool m_CompiledAndReady;
00090     friend class GpuDevice;
00091   };
00092 
00093 
00094   class IOpenGLAsmShaderProgram:  public IOpenGLResource
00095   {
00096     NUX_DECLARE_OBJECT_TYPE(IOpenGLAsmShaderProgram, IOpenGLResource);
00097   public:
00098     virtual ~IOpenGLAsmShaderProgram();
00099 
00100     void LoadVertexShader(const char *glslshader);
00101     void LoadPixelShader(const char *glslshader);
00102     void LoadIShaderFile(const char *ShaderFileName);
00103     void LoadIShader(const char *ShaderCode);
00104     void Link();
00105 
00106     bool IsValid();
00107 
00108     void Begin();
00109     void End();
00110 
00111     void SetVertexEnvParameter4dARB         (unsigned int index, double x, double y, double z, double w);
00112     void SetVertexEnvParameter4dvARB        (unsigned int index, const double *params);
00113     void SetVertexEnvParameter4fARB         (unsigned int index, float x, float y, float z, float w);
00114     void SetVertexEnvParameter4fvARB        (unsigned int index, const float *params);
00115     void SetVertexLocalParameter4dARB       (unsigned int index, double x, double y, double z, double w);
00116     void SetVertexLocalParameter4dvARB      (unsigned int index, const double *params);
00117     void SetVertexLocalParameter4fARB       (unsigned int index, float x, float y, float z, float w);
00118     void SetVertexLocalParameter4fvARB      (unsigned int index, const float *params);
00119 
00120     void SetFragmentEnvParameter4dARB       (unsigned int index, double x, double y, double z, double w);
00121     void SetFragmentEnvParameter4dvARB      (unsigned int index, const double *params);
00122     void SetFragmentEnvParameter4fARB       (unsigned int index, float x, float y, float z, float w);
00123     void SetFragmentEnvParameter4fvARB      (unsigned int index, const float *params);
00124     void SetFragmentLocalParameter4dARB     (unsigned int index, double x, double y, double z, double w);
00125     void SetFragmentLocalParameter4dvARB    (unsigned int index, const double *params);
00126     void SetFragmentLocalParameter4fARB     (unsigned int index, float x, float y, float z, float w);
00127     void SetFragmentLocalParameter4fvARB    (unsigned int index, const float *params);
00128 
00129   private:
00130     IOpenGLAsmShaderProgram(NString ShaderProgramName = NString("AsmShaderProgram"));
00131     std::vector<ObjectPtr<IOpenGLAsmShader> > ShaderObjectList;
00132     NString _ShaderProgramName;
00133 
00134     ObjectPtr<IOpenGLAsmVertexShader> m_AsmVertexProgram;
00135     ObjectPtr<IOpenGLAsmPixelShader> m_AsmFragmentProgram;
00136 
00137     friend class GpuDevice;
00138   };
00139 
00140 }
00141 
00142 #endif // IOPENGLASMSHADER_H