PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Program.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_PROGRAM_H__ 00024 #define __PLRENDERER_PROGRAM_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/Event.h> 00032 #include "PLRenderer/Renderer/Resource.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Forward declarations ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 template <class ValueType> class Array; 00040 } 00041 namespace PLRenderer { 00042 class VertexShader; 00043 class ProgramUniform; 00044 class GeometryShader; 00045 class FragmentShader; 00046 class ProgramAttribute; 00047 class ProgramUniformBlock; 00048 } 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ Namespace ] 00053 //[-------------------------------------------------------] 00054 namespace PLRenderer { 00055 00056 00057 //[-------------------------------------------------------] 00058 //[ Classes ] 00059 //[-------------------------------------------------------] 00060 /** 00061 * @brief 00062 * Abstract renderer program resource 00063 * 00064 * @note 00065 * - While each program must have a vertex shader and a fragment shader, a geometry shader is optional 00066 * - The program is using lazy evaluation, so the program is only compiled & linked when really required 00067 * - In performance critical situations, use uniform blocks if they are available 00068 * - In performance critical situations, you may want to request e.g. the pointer to uniforms only once, not constantly 00069 */ 00070 class Program : public Resource { 00071 00072 00073 //[-------------------------------------------------------] 00074 //[ Events ] 00075 //[-------------------------------------------------------] 00076 public: 00077 PLCore::Event<Program*> EventDirty; /**< The program became dirty, previous pointers to attributes or uniforms may no longer be valid, pointer to this program as parameter (always valid, do not delete it) */ 00078 00079 00080 //[-------------------------------------------------------] 00081 //[ Public functions ] 00082 //[-------------------------------------------------------] 00083 public: 00084 /** 00085 * @brief 00086 * Destructor 00087 */ 00088 PLRENDERER_API virtual ~Program(); 00089 00090 00091 //[-------------------------------------------------------] 00092 //[ Public virtual Program functions ] 00093 //[-------------------------------------------------------] 00094 public: 00095 /** 00096 * @brief 00097 * Returns the name of the shader language the program is using 00098 * 00099 * @return 00100 * The name of the shader language the program is using (for example "GLSL" or "Cg") 00101 */ 00102 virtual PLCore::String GetShaderLanguage() const = 0; 00103 00104 /** 00105 * @brief 00106 * Returns the vertex shader the program is using 00107 * 00108 * @return 00109 * Vertex shader the program is using (do not delete it), can be a null pointer 00110 */ 00111 virtual PLRenderer::VertexShader *GetVertexShader() const = 0; 00112 00113 /** 00114 * @brief 00115 * Sets the vertex shader the program is using 00116 * 00117 * @param[in] pVertexShader 00118 * Vertex shader the program is using, can be a null pointer, vertex shader and program language must match! 00119 * 00120 * @return 00121 * 'true' if all went fine, else 'false' (maybe shader language mismatch?) 00122 * 00123 * @note 00124 * - The given vertex shader instance is just shared and will not be destroyed automatically by this program 00125 * - The given vertex shader instance must stay valid as long as it's used within this program 00126 */ 00127 virtual bool SetVertexShader(PLRenderer::VertexShader *pVertexShader) = 0; 00128 00129 /** 00130 * @brief 00131 * Returns the geometry shader the program is using 00132 * 00133 * @return 00134 * Geometry shader the program is using (do not delete it), can be a null pointer 00135 */ 00136 virtual PLRenderer::GeometryShader *GetGeometryShader() const = 0; 00137 00138 /** 00139 * @brief 00140 * Sets the geometry shader the program is using 00141 * 00142 * @param[in] pGeometryShader 00143 * Geometry shader the program is using, can be a null pointer, geometry shader and program language must match! 00144 * 00145 * @return 00146 * 'true' if all went fine, else 'false' (maybe shader language mismatch?) 00147 * 00148 * @note 00149 * - The given geometry shader instance is just shared and will not be destroyed automatically by this program 00150 * - The given geometry shader instance must stay valid as long as it's used within this program 00151 */ 00152 virtual bool SetGeometryShader(PLRenderer::GeometryShader *pGeometryShader) = 0; 00153 00154 /** 00155 * @brief 00156 * Returns the fragment shader the program is using 00157 * 00158 * @return 00159 * Fragment shader the program is using (do not delete it), can be a null pointer 00160 */ 00161 virtual PLRenderer::FragmentShader *GetFragmentShader() const = 0; 00162 00163 /** 00164 * @brief 00165 * Sets the fragment shader the program is using 00166 * 00167 * @param[in] pFragmentShader 00168 * Fragment shader the program is using, can be a null pointer, fragment shader and program language must match! 00169 * 00170 * @return 00171 * 'true' if all went fine, else 'false' (maybe shader language mismatch?) 00172 * 00173 * @note 00174 * - The given fragment shader instance is just shared and will not be destroyed automatically by this program 00175 * - The given fragment shader instance must stay valid as long as it's used within this program 00176 */ 00177 virtual bool SetFragmentShader(PLRenderer::FragmentShader *pFragmentShader) = 0; 00178 00179 /** 00180 * @brief 00181 * Returns whether or not the program is valid (successfully compiled, linked and ready to be used) 00182 * 00183 * @return 00184 * 'true' if the program is valid, else 'false' 00185 */ 00186 virtual bool IsValid() = 0; 00187 00188 /** 00189 * @brief 00190 * Returns the compiled program 00191 * 00192 * @return 00193 * The compiled program 00194 * 00195 * @remarks 00196 * @verbatim 00197 * Usage example writing the compiled program into a text file: 00198 * 00199 * PLCore::File cFile("d:\\CompiledProgram.txt"); 00200 * if (cFile.Open(PLCore::File::FileCreate|PLCore::File::FileWrite)) { 00201 * const PLCore::String sProgram = pMyProgram->GetCompiledProgram(); 00202 * cFile.Write(sProgram.GetASCII(), sProgram.GetLength(), 1); 00203 * cFile.Close(); 00204 * } 00205 * @endverbatim 00206 * 00207 * @note 00208 * - The compiled program depends on the used shader language, it's also possible 00209 * that an implementation is not able to return a compiled program 00210 */ 00211 virtual PLCore::String GetCompiledProgram() = 0; 00212 00213 /** 00214 * @brief 00215 * Get attributes 00216 * 00217 * @return 00218 * List of attributes (do NOT delete the program attribute instances!) 00219 */ 00220 virtual const PLCore::Array<ProgramAttribute*> &GetAttributes() = 0; 00221 00222 /** 00223 * @brief 00224 * Get attribute 00225 * 00226 * @param[in] sName 00227 * Attribute name 00228 * 00229 * @return 00230 * Attribute (do not delete it, can be a null pointer, if no attribute with that name could be found) 00231 */ 00232 virtual ProgramAttribute *GetAttribute(const PLCore::String &sName) = 0; 00233 00234 /** 00235 * @brief 00236 * Get uniforms 00237 * 00238 * @return 00239 * List of uniforms (do NOT delete the program uniform instances!) 00240 */ 00241 virtual const PLCore::Array<ProgramUniform*> &GetUniforms() = 0; 00242 00243 /** 00244 * @brief 00245 * Get uniform 00246 * 00247 * @param[in] sName 00248 * Uniform name 00249 * 00250 * @return 00251 * Uniform (do not delete it, can be a null pointer, if no uniform with that name could be found) 00252 * 00253 * @see 00254 * - "ProgramUniform"-class for more information 00255 */ 00256 virtual ProgramUniform *GetUniform(const PLCore::String &sName) = 0; 00257 00258 /** 00259 * @brief 00260 * Get uniform blocks 00261 * 00262 * @return 00263 * List of uniform blocks (do NOT delete the program uniform block instances!) 00264 */ 00265 virtual const PLCore::Array<ProgramUniformBlock*> &GetUniformBlocks() = 0; 00266 00267 /** 00268 * @brief 00269 * Get uniform block 00270 * 00271 * @param[in] sName 00272 * Uniform block name 00273 * 00274 * @return 00275 * Uniform block (do not delete it, can be a null pointer, if no uniform block with that name could be found) 00276 */ 00277 virtual ProgramUniformBlock *GetUniformBlock(const PLCore::String &sName) = 0; 00278 00279 00280 //[-------------------------------------------------------] 00281 //[ Protected virtual Program functions ] 00282 //[-------------------------------------------------------] 00283 protected: 00284 /** 00285 * @brief 00286 * Makes this program to the renderers currently used program 00287 * 00288 * @return 00289 * 'true' if all went fine, else 'false' 00290 */ 00291 virtual bool MakeCurrent() = 0; 00292 00293 /** 00294 * @brief 00295 * This program will no longer be the renderers currently used program 00296 * 00297 * @return 00298 * 'true' if all went fine, else 'false' 00299 */ 00300 virtual bool UnmakeCurrent() = 0; 00301 00302 00303 //[-------------------------------------------------------] 00304 //[ Protected functions ] 00305 //[-------------------------------------------------------] 00306 protected: 00307 /** 00308 * @brief 00309 * Constructor 00310 * 00311 * @param[in] cRenderer 00312 * Owner renderer 00313 */ 00314 PLRENDERER_API Program(Renderer &cRenderer); 00315 00316 00317 //[-------------------------------------------------------] 00318 //[ Private functions ] 00319 //[-------------------------------------------------------] 00320 private: 00321 /** 00322 * @brief 00323 * Copy constructor 00324 * 00325 * @param[in] cSource 00326 * Source to copy from 00327 */ 00328 Program(const Program &cSource); 00329 00330 /** 00331 * @brief 00332 * Copy operator 00333 * 00334 * @param[in] cSource 00335 * Source to copy from 00336 * 00337 * @return 00338 * Reference to this instance 00339 */ 00340 Program &operator =(const Program &cSource); 00341 00342 00343 }; 00344 00345 00346 //[-------------------------------------------------------] 00347 //[ Namespace ] 00348 //[-------------------------------------------------------] 00349 } // PLRenderer 00350 00351 00352 #endif // __PLRENDERER_PROGRAM_H__
|