Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/GLSL/include/OgreGLSLProgram.h @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 5.8 KB
RevLine 
[1]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 __GLSLProgram_H__
30#define __GLSLProgram_H__
31
32#include "OgreGLPrerequisites.h"
33#include "OgreHighLevelGpuProgram.h"
34
35namespace Ogre {
36    /** Specialisation of HighLevelGpuProgram to provide support for OpenGL
37        Shader Language (GLSL).
38    @remarks
39                GLSL has no target assembler or entry point specification like DirectX 9 HLSL.
40                Vertex and Fragment shaders only have one entry point called "main". 
41                When a shader is compiled, microcode is generated but can not be accessed by
42                the application.
43                GLSL also does not provide assembler low level output after compiling.  The GL Render
44                system assumes that the Gpu program is a GL Gpu program so GLSLProgram will create a
45                GLSLGpuProgram that is subclassed from GLGpuProgram for the low level implementation.
46                The GLSLProgram class will create a shader object and compile the source but will
47                not create a program object.  It's up to GLSLGpuProgram class to request a program object
48                to link the shader object to.
49
50        @note
51                GLSL supports multiple modular shader objects that can be attached to one program
52                object to form a single shader.  This is supported through the "attach" material script
53                command.  All the modules to be attached are listed on the same line as the attach command
54                seperated by white space.
55       
56    */
57    class _OgrePrivate GLSLProgram : public HighLevelGpuProgram
58    {
59    public:
60        /// Command object for attaching another GLSL Program
61        class CmdAttach : public ParamCommand
62        {
63        public:
64            String doGet(const void* target) const;
65            void doSet(void* target, const String& shaderNames);
66        };
67
68        GLSLProgram(ResourceManager* creator, 
69            const String& name, ResourceHandle handle,
70            const String& group, bool isManual, ManualResourceLoader* loader);
71                ~GLSLProgram();
72
73                const GLhandleARB getGLHandle() const { return mGLHandle; }
74                void attachToProgramObject( const GLhandleARB programObject );
75                void detachFromProgramObject( const GLhandleARB programObject );
76                String getAttachedShaderNames() const { return mAttachedShaderNames; }
77
78        /** Attach another GLSL Shader to this one. */
79        void attachChildShader(const String& name);
80
81                /** Sets the preprocessor defines use to compile the program. */
82                void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
83                /** Sets the preprocessor defines use to compile the program. */
84                const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
85
86        /// Overridden from GpuProgram
87        const String& getLanguage(void) const;
88
89                /// Command object for setting macro defines
90                class CmdPreprocessorDefines : public ParamCommand
91                {
92                public:
93                        String doGet(const void* target) const;
94                        void doSet(void* target, const String& val);
95                };
96        protected:
97                static CmdPreprocessorDefines msCmdPreprocessorDefines;
98        static CmdAttach msCmdAttach;
99
100        /** Internal load implementation, must be implemented by subclasses.
101        */
102        void loadFromSource(void);
103        /** Internal method for creating a dummy low-level program for this
104        high-level program.     GLSL does not give access to the low level implementation of the
105                shader so this method creates an object sub-classed from GLGpuProgram just to be
106                compatible with GLRenderSystem.
107                */
108                void createLowLevelImpl(void);
109        /// Internal unload implementation, must be implemented by subclasses
110        void unloadHighLevelImpl(void);
111                /// Overridden from HighLevelGpuProgram
112                void unloadImpl(void);
113
114        /// Populate the passed parameters with name->index map
115        void populateParameterNames(GpuProgramParametersSharedPtr params);
116        /// Populate the passed parameters with name->index map, must be overridden
117        void buildConstantDefinitions() const;
118                /// compile source into shader object
119                bool compile( const bool checkErrors = true);
120
121        private:
122                /// GL handle for shader object
123                GLhandleARB mGLHandle;
124                /// flag indicating if shader object successfully compiled
125                GLint mCompiled;
126                /// attached Shader names
127                String mAttachedShaderNames;
128                /// Preprocessor options
129                String mPreprocessorDefines;
130                /// container of attached programs
131                typedef std::vector< GLSLProgram* > GLSLProgramContainer;
132                typedef GLSLProgramContainer::iterator GLSLProgramContainerIterator;
133                GLSLProgramContainer mAttachedGLSLPrograms;
134
135    };
136}
137
138#endif // __GLSLProgram_H__
Note: See TracBrowser for help on using the repository browser.