Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/GLSL/src/OgreGLSLGpuProgram.cpp @ 3

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

=update

File size: 5.7 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
30#include "OgreGLSLExtSupport.h"
31#include "OgreGLSLGpuProgram.h"
32#include "OgreGLSLLinkProgramManager.h"
33#include "OgreGLSLLinkProgram.h"
34#include "OgreGLSLProgram.h"
35
36namespace Ogre {
37
38        GLuint GLSLGpuProgram::mVertexShaderCount = 0;
39        GLuint GLSLGpuProgram::mFragmentShaderCount = 0;
40
41    //-----------------------------------------------------------------------------
42        GLSLGpuProgram::GLSLGpuProgram(GLSLProgram* parent) : 
43        GLGpuProgram(parent->getCreator(), parent->getName(), parent->getHandle(), 
44            parent->getGroup(), false, 0), mGLSLProgram(parent)
45    {
46        mType = parent->getType();
47        mSyntaxCode = "glsl";
48
49                if (parent->getType() == GPT_VERTEX_PROGRAM)
50                {
51                        mProgramID = ++mVertexShaderCount;
52                }
53                else
54                {
55                        mProgramID = ++mFragmentShaderCount;
56                }
57
58        // transfer skeletal animation status from parent
59        mSkeletalAnimation = mGLSLProgram->isSkeletalAnimationIncluded();
60                // there is nothing to load
61                mLoadFromFile = false;
62
63    }
64    //-----------------------------------------------------------------------
65    GLSLGpuProgram::~GLSLGpuProgram()
66    {
67        // have to call this here reather than in Resource destructor
68        // since calling virtual methods in base destructors causes crash
69        unload(); 
70    }
71        //-----------------------------------------------------------------------------
72    void GLSLGpuProgram::loadImpl(void)
73    {
74                // nothing to load
75    }
76
77        //-----------------------------------------------------------------------------
78        void GLSLGpuProgram::unloadImpl(void)
79        {
80                // nothing to unload
81        }
82
83        //-----------------------------------------------------------------------------
84    void GLSLGpuProgram::loadFromSource(void)
85    {
86                // nothing to load
87        }
88
89        //-----------------------------------------------------------------------------
90        void GLSLGpuProgram::bindProgram(void)
91        {
92                // tell the Link Program Manager what shader is to become active
93                if (mType == GPT_VERTEX_PROGRAM)
94                {
95                        GLSLLinkProgramManager::getSingleton().setActiveVertexShader( this );
96                }
97                else // its a fragment shader
98                {
99                        GLSLLinkProgramManager::getSingleton().setActiveFragmentShader( this );
100                }
101        }
102
103        //-----------------------------------------------------------------------------
104        void GLSLGpuProgram::unbindProgram(void)
105        {
106                // tell the Link Program Manager what shader is to become inactive
107                if (mType == GPT_VERTEX_PROGRAM)
108                {
109                        GLSLLinkProgramManager::getSingleton().setActiveVertexShader( NULL );
110                }
111                else // its a fragment shader
112                {
113                        GLSLLinkProgramManager::getSingleton().setActiveFragmentShader( NULL );
114                }
115
116        }
117
118        //-----------------------------------------------------------------------------
119        void GLSLGpuProgram::bindProgramParameters(GpuProgramParametersSharedPtr params)
120        {
121                // activate the link program object
122                GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram();
123                // pass on parameters from params to program object uniforms
124                linkProgram->updateUniforms(params, mType);
125               
126        }
127
128        //-----------------------------------------------------------------------------
129        void GLSLGpuProgram::bindProgramPassIterationParameters(GpuProgramParametersSharedPtr params)
130        {
131                // activate the link program object
132                GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram();
133                // pass on parameters from params to program object uniforms
134                linkProgram->updatePassIterationUniforms( params );
135               
136        }
137        //-----------------------------------------------------------------------------
138        GLuint GLSLGpuProgram::getAttributeIndex(VertexElementSemantic semantic)
139        {
140                // get link program - only call this in the context of bound program
141                GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram();
142
143                if (linkProgram->isAttributeValid(semantic))
144                {
145                        return linkProgram->getAttributeIndex(semantic);
146                }
147                else
148                {
149                        // fall back to default implementation, allow default bindings
150                        return GLGpuProgram::getAttributeIndex(semantic);
151                }
152               
153        }
154        //-----------------------------------------------------------------------------
155        bool GLSLGpuProgram::isAttributeValid(VertexElementSemantic semantic)
156        {
157                // get link program - only call this in the context of bound program
158                GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram();
159
160                if (linkProgram->isAttributeValid(semantic))
161                {
162                        return true;
163                }
164                else
165                {
166                        // fall back to default implementation, allow default bindings
167                        return GLGpuProgram::isAttributeValid(semantic);
168                }
169        }
170
171
172
173}
174
Note: See TracBrowser for help on using the repository browser.