Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/GLSL/include/OgreGLSLLinkProgramManager.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 5.5 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __GLSLLinkProgramManager_H__
30#define __GLSLLinkProgramManager_H__
31
32#include "OgreGLPrerequisites.h"
33#include "OgreSingleton.h"
34
35#include "OgreGLSLExtSupport.h"
36#include "OgreGLSLLinkProgram.h"
37
38namespace Ogre {
39
40        /** Ogre assumes that there are seperate vertex and fragment programs to deal with but
41                GLSL has one program object that represents the active vertex and fragment shader objects
42                during a rendering state.  GLSL Vertex and fragment
43                shader objects are compiled seperately and then attached to a program object and then the
44                program object is linked.  Since Ogre can only handle one vertex program and one fragment
45                program being active in a pass, the GLSL Link Program Manager does the same.  The GLSL Link
46                program manager acts as a state machine and activates a program object based on the active
47                vertex and fragment program.  Previously created program objects are stored along with a unique
48                key in a hash_map for quick retrieval the next time the program object is required.
49
50        */
51
52        class _OgrePrivate GLSLLinkProgramManager : public Singleton<GLSLLinkProgramManager>
53        {
54
55        private:
56       
57                typedef HashMap<GLuint, GLSLLinkProgram*> LinkProgramMap;
58                typedef LinkProgramMap::iterator LinkProgramIterator;
59
60                /// container holding previously created program objects
61                LinkProgramMap LinkPrograms; 
62
63                /// active objects defining the active rendering gpu state
64                GLSLGpuProgram* mActiveVertexGpuProgram;
65                GLSLGpuProgram* mActiveFragmentGpuProgram;
66                GLSLLinkProgram* mActiveLinkProgram;
67
68                typedef std::map<String, GLenum> StringToEnumMap;
69                StringToEnumMap mTypeEnumMap;
70
71                /// Use type to complete other information
72                void completeDefInfo(GLenum gltype, GpuConstantDefinition& defToUpdate);
73                /// Find where the data for a specific uniform should come from, populate
74                bool completeParamSource(const String& paramName,
75                        const GpuConstantDefinitionMap* vertexConstantDefs, 
76                        const GpuConstantDefinitionMap* fragmentConstantDefs, 
77                        GLUniformReference& refToUpdate);
78
79        public:
80
81                GLSLLinkProgramManager(void);
82
83                ~GLSLLinkProgramManager(void);
84
85                /**
86                        Get the program object that links the two active shader objects together
87                        if a program object was not already created and linked a new one is created and linked
88                */
89                GLSLLinkProgram* getActiveLinkProgram(void);
90
91                /** Set the active fragment shader for the next rendering state.
92                        The active program object will be cleared.
93                        Normally called from the GLSLGpuProgram::bindProgram and unbindProgram methods
94                */
95                void setActiveFragmentShader(GLSLGpuProgram* fragmentGpuProgram);
96                /** Set the active vertex shader for the next rendering state.
97                        The active program object will be cleared.
98                        Normally called from the GLSLGpuProgram::bindProgram and unbindProgram methods
99                */
100                void setActiveVertexShader(GLSLGpuProgram* vertexGpuProgram);
101
102                /** Populate a list of uniforms based on a program object.
103                @param programObject Handle to the program object to query
104                @param vertexConstantDefs Definition of the constants extracted from the
105                        vertex program, used to match up physical buffer indexes with program
106                        uniforms. May be null if there is no vertex program.
107                @param fragmentConstantDefs Definition of the constants extracted from the
108                        fragment program, used to match up physical buffer indexes with program
109                        uniforms. May be null if there is no fragment program.
110                @param list The list to populate (will not be cleared before adding, clear
111                it yourself before calling this if that's what you want).
112                */
113                void extractUniforms(GLhandleARB programObject, 
114                        const GpuConstantDefinitionMap* vertexConstantDefs, 
115                        const GpuConstantDefinitionMap* fragmentConstantDefs, 
116                        GLUniformReferenceList& list);
117                /** Populate a list of uniforms based on GLSL source.
118                @param src Reference to the source code
119                @param list The defs to populate (will not be cleared before adding, clear
120                it yourself before calling this if that's what you want).
121                @param filename The file name this came from, for logging errors.
122                */
123                void extractConstantDefs(const String& src, GpuNamedConstants& constantDefs, 
124                        const String& filename);
125
126                static GLSLLinkProgramManager& getSingleton(void);
127        static GLSLLinkProgramManager* getSingletonPtr(void);
128
129        };
130
131}
132
133#endif // __GLSLLinkProgramManager_H__
Note: See TracBrowser for help on using the repository browser.