00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CAELUM__FAST_GPU_PARAM_REF_H
00022 #define CAELUM__FAST_GPU_PARAM_REF_H
00023
00024 #include "CaelumPrerequisites.h"
00025
00026 namespace Caelum
00027 {
00033 #define CAELUM_DEBUG_PARAM_REF OGRE_DEBUG_MODE
00034
00049 class CAELUM_EXPORT FastGpuParamRef
00050 {
00051 public:
00053 FastGpuParamRef(): mPhysicalIndex(InvalidPhysicalIndex)
00054 {
00055
00056 }
00057
00059 FastGpuParamRef(Ogre::GpuProgramParametersSharedPtr paramsPtr, const Ogre::String& name);
00060
00071 void bind(
00072 Ogre::GpuProgramParametersSharedPtr paramsPtr,
00073 const Ogre::String& name,
00074 bool throwIfNotFound = false);
00075
00081 void unbind();
00082
00084 inline bool isBound() const { return mPhysicalIndex != InvalidPhysicalIndex; }
00085
00087 inline size_t getPhysicalIndex () const { return mPhysicalIndex; }
00088
00089 protected:
00098 template<typename ArgumentT>
00099 inline void doSet(const Ogre::GpuProgramParametersSharedPtr& params, ArgumentT arg) const {
00100 #if CAELUM_DEBUG_PARAM_REF
00101 assert(params.getPointer() == mParams.getPointer());
00102 #endif
00103 assert(!params.isNull());
00104 if (mPhysicalIndex != InvalidPhysicalIndex) {
00105 params->_writeRawConstant(mPhysicalIndex, arg);
00106 }
00107 }
00108
00109 template<typename ArgumentT>
00110 inline void doSet(const Ogre::GpuProgramParametersSharedPtr& params, ArgumentT arg, size_t count) const {
00111 #if CAELUM_DEBUG_PARAM_REF
00112 assert(params.getPointer() == mParams.getPointer());
00113 #endif
00114 assert(!params.isNull());
00115 if (mPhysicalIndex != InvalidPhysicalIndex) {
00116 params->_writeRawConstant(mPhysicalIndex, arg, count);
00117 }
00118 }
00119
00120 public:
00122 inline void set(const Ogre::GpuProgramParametersSharedPtr& params, int val) const { doSet<int>(params, val); }
00124 inline void set(const Ogre::GpuProgramParametersSharedPtr& params, Ogre::Real val) const { doSet<Ogre::Real>(params, val); }
00126 inline void set(const Ogre::GpuProgramParametersSharedPtr& params, const Ogre::Vector3& val) const { doSet<const Ogre::Vector3&>(params, val); }
00128 inline void set(const Ogre::GpuProgramParametersSharedPtr& params, const Ogre::Vector4& val) const { doSet<const Ogre::Vector4&>(params, val); }
00130 inline void set(const Ogre::GpuProgramParametersSharedPtr& params, const Ogre::ColourValue& val) const { doSet<const Ogre::ColourValue&>(params, val); }
00132 inline void set(const Ogre::GpuProgramParametersSharedPtr& params, const Ogre::Matrix4& val) const { doSet<const Ogre::Matrix4*>(params, &val, 1); }
00133
00134 private:
00135 #if CAELUM_DEBUG_PARAM_REF
00136 Ogre::GpuProgramParametersSharedPtr mParams;
00137 #endif
00138 static const size_t InvalidPhysicalIndex = 0xFFFFFFFF;
00139 size_t mPhysicalIndex;
00140 };
00141 }
00142
00143 #endif