PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ProgramUniformBlock.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_PROGRAMUNIFORMBLOCK_H__ 00024 #define __PLRENDERER_PROGRAMUNIFORMBLOCK_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLRenderer/PLRenderer.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Forward declarations ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 class String; 00039 } 00040 namespace PLRenderer { 00041 class UniformBuffer; 00042 } 00043 00044 00045 //[-------------------------------------------------------] 00046 //[ Namespace ] 00047 //[-------------------------------------------------------] 00048 namespace PLRenderer { 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ Classes ] 00053 //[-------------------------------------------------------] 00054 /** 00055 * @brief 00056 * Abstract renderer program uniform block 00057 * 00058 * @remarks 00059 * The behavior of the "SetUniformBuffer()"-method depends on the used internal shader API. When using Cg, 00060 * a call of the "SetUniformBuffer()"-method has only an effect when then program is going to be set in the 00061 * near future - meaning it has no effect when the program, the uniform block is part of, is already the program 00062 * currently used for rendering. When using GLSL, the "SetUniformBuffer()"-method is accessing a global UBO 00063 * binding point, meaning that it doesn't matter whether or not the program, the uniform block is part of, is 00064 * currently used for rendering. For performance reasons, this abstract program uniform block interface can't 00065 * compensate those differences. It has to be as lightweight as possible in order to keep the interface performance 00066 * impact as low as possible. So, to be on the safe side, do only call the "SetUniformBuffer()"-method if the program, 00067 * the uniform block is part of, is currently not used for rendering. 00068 * 00069 * @note 00070 * - Do only call the "SetUniformBuffer()"-method when the program, the uniform block is part of, is currently not used for rendering 00071 */ 00072 class ProgramUniformBlock { 00073 00074 00075 //[-------------------------------------------------------] 00076 //[ Public virtual ProgramUniformBlock functions ] 00077 //[-------------------------------------------------------] 00078 public: 00079 /** 00080 * @brief 00081 * Sets the uniform buffer feeding this uniform block with data 00082 * 00083 * @param[in] pUniformBuffer 00084 * The uniform buffer feeding this uniform block with data, can be a null pointer 00085 * @param[in] nBindingPoint 00086 * Binding point to use 00087 * 00088 * @return 00089 * 'true' if all went fine, else 'false' (maybe the number of bytes within the given uniform buffer 00090 * is less than the number of bytes within this uniform block or there's a shader language mismatch) 00091 * 00092 * @remarks 00093 * The binding point is somewhat similar a texture unit. The total number of binding points 00094 * which can be used at the same time during rendering are limited to e.g. 45 (just an example!) 00095 * binding points. 00096 */ 00097 virtual bool SetUniformBuffer(UniformBuffer *pUniformBuffer, PLCore::uint32 nBindingPoint) = 0; 00098 00099 /** 00100 * @brief 00101 * Returns the uniform block index 00102 * 00103 * @return 00104 * The uniform block index 00105 */ 00106 virtual PLCore::uint32 GetIndex() const = 0; 00107 00108 /** 00109 * @brief 00110 * Returns the uniform block data size (in bytes) 00111 * 00112 * @return 00113 * The uniform block data size (in bytes) 00114 */ 00115 virtual PLCore::uint32 GetSize() const = 0; 00116 00117 /** 00118 * @brief 00119 * Returns the offset (in bytes) of an uniform inside the uniform block 00120 * 00121 * @param[in] sUniformName 00122 * Name of the uniform 00123 * 00124 * @return 00125 * The offset (in bytes) of an uniform inside the uniform block 00126 */ 00127 virtual PLCore::uint32 GetUniformOffset(const PLCore::String &sUniformName) const = 0; 00128 00129 /** 00130 * @brief 00131 * Returns the size (in bytes) of an uniform inside the uniform block 00132 * 00133 * @return 00134 * The size (in bytes) of an uniform inside the uniform block 00135 */ 00136 virtual PLCore::uint32 GetUniformSize(const PLCore::String &sUniformName) const = 0; 00137 00138 /** 00139 * @brief 00140 * Returns the number of array elements of an uniform inside the uniform block 00141 * 00142 * @return 00143 * The number of array elements of an uniform inside the uniform block, 1 for none array uniforms 00144 */ 00145 virtual PLCore::uint32 GetUniformNumOfArrayElements(const PLCore::String &sUniformName) const = 0; 00146 00147 00148 //[-------------------------------------------------------] 00149 //[ Protected functions ] 00150 //[-------------------------------------------------------] 00151 protected: 00152 /** 00153 * @brief 00154 * Constructor 00155 */ 00156 PLRENDERER_API ProgramUniformBlock(); 00157 00158 /** 00159 * @brief 00160 * Destructor 00161 */ 00162 PLRENDERER_API virtual ~ProgramUniformBlock(); 00163 00164 00165 //[-------------------------------------------------------] 00166 //[ Private functions ] 00167 //[-------------------------------------------------------] 00168 private: 00169 /** 00170 * @brief 00171 * Copy constructor 00172 * 00173 * @param[in] cSource 00174 * Source to copy from 00175 */ 00176 ProgramUniformBlock(const ProgramUniformBlock &cSource); 00177 00178 /** 00179 * @brief 00180 * Copy operator 00181 * 00182 * @param[in] cSource 00183 * Source to copy from 00184 * 00185 * @return 00186 * Reference to this instance 00187 */ 00188 ProgramUniformBlock &operator =(const ProgramUniformBlock &cSource); 00189 00190 00191 }; 00192 00193 00194 //[-------------------------------------------------------] 00195 //[ Namespace ] 00196 //[-------------------------------------------------------] 00197 } // PLRenderer 00198 00199 00200 #endif // __PLRENDERER_PROGRAMUNIFORMBLOCK_H__
|