PixelLightAPI  .
ProgramWrapper.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ProgramWrapper.h                               *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLRENDERER_PROGRAMWRAPPER_H__
00024 #define __PLRENDERER_PROGRAMWRAPPER_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLRenderer/Renderer/Program.h"
00032 #include "PLRenderer/Renderer/VertexBuffer.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Forward declarations                                  ]
00037 //[-------------------------------------------------------]
00038 namespace PLMath {
00039     class Vector2;
00040     class Vector2i;
00041     class Vector3;
00042     class Vector3i;
00043     class Vector4;
00044     class Matrix3x3;
00045     class Matrix3x4;
00046     class Matrix4x4;
00047     class Quaternion;
00048 }
00049 namespace PLGraphics {
00050     class Color3;
00051     class Color4;
00052 }
00053 namespace PLRenderer {
00054     class TextureBuffer;
00055     class UniformBuffer;
00056 }
00057 
00058 
00059 //[-------------------------------------------------------]
00060 //[ Namespace                                             ]
00061 //[-------------------------------------------------------]
00062 namespace PLRenderer {
00063 
00064 
00065 //[-------------------------------------------------------]
00066 //[ Classes                                               ]
00067 //[-------------------------------------------------------]
00068 /**
00069 *  @brief
00070 *    Comfort renderer program wrapper
00071 *
00072 *  @remarks
00073 *    The "Program.h"-header is slim and the program interface is designed to be universal and efficient.
00074 *    While this is fine in general, it may feel to complicated in simple daily use. For example, in order
00075 *    to set a program attribute one has to write for instance
00076 *        ProgramAttribute *pProgramAttribute = pProgram->GetAttribute("VertexPosition");
00077 *        if (pProgramAttribute)
00078 *            pProgramAttribute->Set(pVertexBuffer, VertexBuffer::Position);
00079 *
00080 *    The purpose of this "ProgramWrapper"-interface is to make simple usage as shown in the example above
00081 *    more compact and direct by allowing to write
00082 *        m_pProgram->Set("VertexPosition", m_pVertexBuffer, VertexBuffer::Position)
00083 *    instead.
00084 *
00085 *    Please note that "ProgramWrapper" is just an interface and no real class which can be instanced. All
00086 *    methods are inlined and simple. In order to use this interface write e.g.
00087 *        ProgramWrapper *pProgram = static_cast<ProgramWrapper*>(pShaderLanguage->CreateProgram(pVertexShader, pFragmentShader));
00088 *    This means that it is actually a hack because one has to cast an class instance to a certain class, although the class
00089 *    instance is in fact not an instance of it. Due to the simplicity of "ProgramWrapper" and the fact that it doesn't introduce
00090 *    e.g. new variables, this is working.
00091 *
00092 *  @note
00093 *    - In case you need the best possible performance when dealing with GPU programs, you may not want to use this program wrapper (see "Program"-class)
00094 */
00095 class ProgramWrapper : public Program {
00096 
00097 
00098     //[-------------------------------------------------------]
00099     //[ Public functions                                      ]
00100     //[-------------------------------------------------------]
00101     public:
00102         //[-------------------------------------------------------]
00103         //[ Program uniform ("ProgramUniform"-class)              ] -> See "ProgramUniform"-class for more information
00104         //[-------------------------------------------------------]
00105         inline void Get(const PLCore::String &sUniformName, int &nX);
00106         inline void Get(const PLCore::String &sUniformName, float &fX);
00107         inline void Get(const PLCore::String &sUniformName, double &fX);
00108         inline void Set(const PLCore::String &sUniformName, int nX);
00109         inline void Set(const PLCore::String &sUniformName, float fX);
00110         inline void Set(const PLCore::String &sUniformName, double fX);
00111         inline void Get(const PLCore::String &sUniformName, int &nX, int &nY);
00112         inline void Get(const PLCore::String &sUniformName, float &fX, float &fY);
00113         inline void Get(const PLCore::String &sUniformName, double &fX, double &fY);
00114         inline void Get(const PLCore::String &sUniformName, PLMath::Vector2i &vVector);
00115         inline void Get(const PLCore::String &sUniformName, PLMath::Vector2 &vVector);
00116         inline void Get2(const PLCore::String &sUniformName, int *pnComponents);
00117         inline void Get2(const PLCore::String &sUniformName, float *pfComponents);
00118         inline void Get2(const PLCore::String &sUniformName, double *pfComponents);
00119         inline void Set(const PLCore::String &sUniformName, int nX, int nY);
00120         inline void Set(const PLCore::String &sUniformName, float fX, float fY);
00121         inline void Set(const PLCore::String &sUniformName, double fX, double fY);
00122         inline void Set(const PLCore::String &sUniformName, const PLMath::Vector2i &vVector);
00123         inline void Set(const PLCore::String &sUniformName, const PLMath::Vector2 &vVector);
00124         inline void Set2(const PLCore::String &sUniformName, const int *pnComponents);
00125         inline void Set2(const PLCore::String &sUniformName, const float *pfComponents);
00126         inline void Set2(const PLCore::String &sUniformName, const double *pfComponents);
00127         inline void Get(const PLCore::String &sUniformName, int &nX, int &nY, int &nZ);
00128         inline void Get(const PLCore::String &sUniformName, float &fX, float &fY, float &fZ);
00129         inline void Get(const PLCore::String &sUniformName, double &fX, double &fY, double &fZ);
00130         inline void Get(const PLCore::String &sUniformName, PLMath::Vector3i &vVector);
00131         inline void Get(const PLCore::String &sUniformName, PLMath::Vector3 &vVector);
00132         inline void Get(const PLCore::String &sUniformName, PLGraphics::Color3 &cColor);    // Floating point
00133         inline void Get3(const PLCore::String &sUniformName, int *pnComponents);
00134         inline void Get3(const PLCore::String &sUniformName, float *pfComponents);
00135         inline void Get3(const PLCore::String &sUniformName, double *pfComponents);
00136         inline void Set(const PLCore::String &sUniformName, int nX, int nY, int nZ);
00137         inline void Set(const PLCore::String &sUniformName, float fX, float fY, float fZ);
00138         inline void Set(const PLCore::String &sUniformName, double fX, double fY, double fZ);
00139         inline void Set(const PLCore::String &sUniformName, const PLMath::Vector3i &vVector);
00140         inline void Set(const PLCore::String &sUniformName, const PLMath::Vector3 &vVector);
00141         inline void Set(const PLCore::String &sUniformName, const PLGraphics::Color3 &cColor);  // Floating point
00142         inline void Set3(const PLCore::String &sUniformName, const int *pnComponents);
00143         inline void Set3(const PLCore::String &sUniformName, const float *pfComponents);
00144         inline void Set3(const PLCore::String &sUniformName, const double *pfComponents);
00145         inline void Get(const PLCore::String &sUniformName, int &nX, int &nY, int &nZ, int &nW);
00146         inline void Get(const PLCore::String &sUniformName, float &fX, float &fY, float &fZ, float &fW);
00147         inline void Get(const PLCore::String &sUniformName, double &fX, double &fY, double &fZ, double &fW);
00148         inline void Get(const PLCore::String &sUniformName, PLMath::Vector4 &vVector);
00149         inline void Get(const PLCore::String &sUniformName, PLGraphics::Color4 &cColor);    // Floating point
00150         inline void Get(const PLCore::String &sUniformName, PLMath::Quaternion &qQuaternion);
00151         inline void Get4(const PLCore::String &sUniformName, int *pnComponents);
00152         inline void Get4(const PLCore::String &sUniformName, float *pfComponents);
00153         inline void Get4(const PLCore::String &sUniformName, double *pfComponents);
00154         inline void Set(const PLCore::String &sUniformName, int nX, int nY, int nZ, int nW);
00155         inline void Set(const PLCore::String &sUniformName, float fX, float fY, float fZ, float fW);
00156         inline void Set(const PLCore::String &sUniformName, double fX, double fY, double fZ, double fW);
00157         inline void Set(const PLCore::String &sUniformName, const PLMath::Vector4 &vVector);
00158         inline void Set(const PLCore::String &sUniformName, const PLGraphics::Color4 &cColor);  // Floating point
00159         inline void Set(const PLCore::String &sUniformName, const PLMath::Quaternion &qQuaternion);
00160         inline void Set4(const PLCore::String &sUniformName, const int *pnComponents);
00161         inline void Set4(const PLCore::String &sUniformName, const float *pfComponents);
00162         inline void Set4(const PLCore::String &sUniformName, const double *pfComponents);
00163         inline void Get(const PLCore::String &sUniformName, PLMath::Matrix3x3 &mMatrix);
00164         inline void Get(const PLCore::String &sUniformName, PLMath::Matrix4x4 &mMatrix);
00165         inline void Set(const PLCore::String &sUniformName, const PLMath::Matrix3x3 &mMatrix, bool bTranspose = false);
00166         inline void Set(const PLCore::String &sUniformName, const PLMath::Matrix4x4 &mMatrix, bool bTranspose = false);
00167         inline int GetTextureUnit(const PLCore::String &sUniformName);
00168         inline int Set(const PLCore::String &sUniformName, TextureBuffer *pTextureBuffer);
00169 
00170         //[-------------------------------------------------------]
00171         //[ Program uniform buffer ("ProgramUniformBlock"-class)  ] -> See "ProgramUniformBlock"-class for more information
00172         //[-------------------------------------------------------]
00173         /**
00174         *  @brief
00175         *    Sets the uniform buffer feeding the specified uniform block with data
00176         *
00177         *  @param[in] sUniformBlockName
00178         *    Uniform block name
00179         *  @param[in] pUniformBuffer
00180         *    The uniform buffer feeding this uniform block with data, can be a null pointer
00181         *  @param[in] nBindingPoint
00182         *    Binding point to use
00183         *
00184         *  @return
00185         *    'true' if all went fine, else 'false' (maybe the number of bytes within the given uniform buffer
00186         *    is less than the number of bytes within this uniform block or there's a shader language mismatch)
00187         *
00188         *  @remarks
00189         *    The binding point is somewhat similar a texture unit. The total number of binding points
00190         *    which can be used at the same time during rendering are limited to e.g. 45 (just an example!)
00191         *    binding points.
00192         */
00193         inline bool Set(const PLCore::String &sUniformBlockName, UniformBuffer *pUniformBuffer, PLCore::uint32 nBindingPoint);
00194 
00195         //[-------------------------------------------------------]
00196         //[ Program attribute ("ProgramAttribute"-class)          ] -> See "ProgramAttribute"-class for more information
00197         //[-------------------------------------------------------]
00198         /**
00199         *  @brief
00200         *    Sets a attribute by using an index to reference the vertex buffer attribute to use
00201         *
00202         *  @param[in] sAttributeName
00203         *    Attribute name
00204         *  @param[in] pVertexBuffer
00205         *    Vertex buffer to use, can be a null pointer
00206         *  @param[in] nIndex
00207         *    Index of the vertex buffer attribute to connect with the vertex shader attribute
00208         *
00209         *  @return
00210         *    'true' if all went fine, else 'false' (maybe there's no attribute with the given name?
00211         *
00212         *  @note
00213         *    - Comfort method
00214         */
00215         inline bool Set(const PLCore::String &sAttributeName, VertexBuffer *pVertexBuffer, PLCore::uint32 nIndex);
00216 
00217         /**
00218         *  @brief
00219         *    Sets a attribute by using a semantic to reference the vertex buffer attribute to use
00220         *
00221         *  @param[in] sAttributeName
00222         *    Attribute name
00223         *  @param[in] pVertexBuffer
00224         *    Vertex buffer to use, can be a null pointer
00225         *  @param[in] nSemantic
00226         *    Semantic of the vertex buffer attribute to connect with the vertex shader attribute
00227         *  @param[in] nChannel
00228         *    Pipeline channel (see ESemantic, maximum see MaxPipelineChannels)
00229         *
00230         *  @return
00231         *    'true' if all went fine, else 'false' (maybe there's no attribute with the given name?
00232         *
00233         *  @note
00234         *    - Comfort method
00235         */
00236         inline bool Set(const PLCore::String &sAttributeName, VertexBuffer *pVertexBuffer, VertexBuffer::ESemantic nSemantic, PLCore::uint32 nChannel = 0);
00237 
00238 
00239     //[-------------------------------------------------------]
00240     //[ Private functions                                     ]
00241     //[-------------------------------------------------------]
00242     private:
00243         /**
00244         *  @brief
00245         *    Copy constructor
00246         *
00247         *  @param[in] cRenderer
00248         *    Owner renderer
00249         */
00250         inline ProgramWrapper(Renderer &cRenderer);
00251 
00252 
00253 };
00254 
00255 
00256 //[-------------------------------------------------------]
00257 //[ Namespace                                             ]
00258 //[-------------------------------------------------------]
00259 } // PLRenderer
00260 
00261 
00262 //[-------------------------------------------------------]
00263 //[ Implementation                                        ]
00264 //[-------------------------------------------------------]
00265 #include "PLRenderer/Renderer/ProgramWrapper.inl"
00266 
00267 
00268 #endif // __PLRENDERER_PROGRAMWRAPPER_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:58
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported