1 /* 2 ----------------------------------------------------------------------------- 3 This source file is part of OGRE 4 (Object-oriented Graphics Rendering Engine) 5 For the latest info, see http://www.ogre3d.org/ 6 7 Copyright (c) 2000-2014 Torus Knot Software Ltd 8 9 Permission is hereby granted, free of charge, to any person obtaining a copy 10 of this software and associated documentation files (the "Software"), to deal 11 in the Software without restriction, including without limitation the rights 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 copies of the Software, and to permit persons to whom the Software is 14 furnished to do so, subject to the following conditions: 15 16 The above copyright notice and this permission notice shall be included in 17 all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 THE SOFTWARE. 26 ----------------------------------------------------------------------------- 27 */ 28 #ifndef __GLSLProgram_H__ 29 #define __GLSLProgram_H__ 30 31 #include "OgreGL3PlusPrerequisites.h" 32 #include "OgreGpuProgram.h" 33 #include "OgreHardwareVertexBuffer.h" 34 #include "OgreGL3PlusHardwareUniformBuffer.h" 35 #include "OgreGL3PlusHardwareShaderStorageBuffer.h" 36 #include "OgreGL3PlusHardwareCounterBuffer.h" 37 #include "OgreGLSLProgramCommon.h" 38 #include "OgreGLSLShader.h" 39 40 namespace Ogre { 41 /** Structure used to keep track of named atomic counter uniforms 42 in the linked program object. Same as GLUniformReference, but 43 contains an additional offset parameter which currently only 44 atomic counters feature. 45 */ 46 struct GLAtomicCounterReference 47 { 48 /// GL binding handle (similar to location) 49 GLint mBinding; 50 /// GL offset (only used for atomic counters) 51 GLint mOffset; 52 /// Which type of program params will this value come from? 53 GpuProgramType mSourceProgType; 54 /// The constant definition it relates to 55 const GpuConstantDefinition* mConstantDef; 56 }; 57 58 typedef std::vector<GLAtomicCounterReference> GLAtomicCounterReferenceList; 59 typedef GLAtomicCounterReferenceList::iterator GLAtomicCounterReferenceIterator; 60 typedef std::map<GpuSharedParametersPtr, HardwareUniformBufferSharedPtr> SharedParamsBufferMap; 61 typedef std::vector<HardwareCounterBufferSharedPtr> GLCounterBufferList; 62 typedef GLCounterBufferList::iterator GLCounterBufferIterator; 63 64 /** C++ encapsulation of GLSL program object. 65 */ 66 class _OgreGL3PlusExport GLSLProgram : public GLSLProgramCommon 67 { 68 public: 69 void bindFixedAttributes(GLuint program); 70 getVertexShader()71 GLSLShader* getVertexShader() const { return static_cast<GLSLShader*>(mVertexShader); } getHullShader()72 GLSLShader* getHullShader() const { return mHullShader; } getDomainShader()73 GLSLShader* getDomainShader() const { return mDomainShader; } getGeometryShader()74 GLSLShader* getGeometryShader() const { return mGeometryShader; } getFragmentShader()75 GLSLShader* getFragmentShader() const { return mFragmentShader; } getComputeShader()76 GLSLShader* getComputeShader() const { return mComputeShader; } 77 isUsingShader(GLSLShaderCommon * shader)78 bool isUsingShader(GLSLShaderCommon* shader) const 79 { 80 return mVertexShader == shader || (GLSLShaderCommon*)mGeometryShader == shader || 81 (GLSLShaderCommon*)mFragmentShader == shader || 82 (GLSLShaderCommon*)mHullShader == shader || 83 (GLSLShaderCommon*)mDomainShader == shader || 84 (GLSLShaderCommon*)mComputeShader == shader; 85 } 86 87 virtual void updateAtomicCounters(GpuProgramParametersSharedPtr params, uint16 mask, 88 GpuProgramType fromProgType) = 0; 89 90 void setTransformFeedbackVaryings(const std::vector<String>& nameStrings); 91 protected: 92 /// Constructor should only be used by GLSLMonolithicProgramManager and GLSLSeparableProgramManager 93 GLSLProgram(GLSLShader* vertexProgram, 94 GLSLShader* hullProgram, 95 GLSLShader* domainProgram, 96 GLSLShader* geometryProgram, 97 GLSLShader* fragmentProgram, 98 GLSLShader* computeProgram); 99 100 /// Container of atomic counter uniform references that are active in the program object 101 GLAtomicCounterReferenceList mGLAtomicCounterReferences; 102 /// Map of shared parameter blocks to uniform buffer references 103 SharedParamsBufferMap mSharedParamsBufferMap; 104 /// Container of counter buffer references that are active in the program object 105 GLCounterBufferList mGLCounterBufferReferences; 106 107 /// Linked hull (control) shader. 108 GLSLShader* mHullShader; 109 /// Linked domain (evaluation) shader. 110 GLSLShader* mDomainShader; 111 /// Linked geometry shader. 112 GLSLShader* mGeometryShader; 113 /// Linked fragment shader. 114 GLSLShader* mFragmentShader; 115 /// Linked compute shader. 116 GLSLShader* mComputeShader; 117 118 uint32 getCombinedHash(); 119 120 Ogre::String getCombinedName(void); 121 /// Get the the binary data of a program from the microcode cache 122 void getMicrocodeFromCache(uint32 id); 123 }; 124 125 126 } 127 128 #endif // __GLSLProgram_H__ 129