Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/atifs/src/ATI_FS_GLGpuProgram.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 4.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 "ps_1_4.h"
31#include "OgreException.h"
32#include "OgreRoot.h"
33#include "OgreRenderSystem.h"
34#include "OgreRenderSystemCapabilities.h"
35#include "OgreLogManager.h"
36#include "ATI_FS_GLGpuProgram.h"
37
38using namespace Ogre;
39
40
41ATI_FS_GLGpuProgram::ATI_FS_GLGpuProgram(ResourceManager* creator, 
42        const String& name, ResourceHandle handle, 
43        const String& group, bool isManual, ManualResourceLoader* loader) :
44    GLGpuProgram(creator, name, handle, group, isManual, loader)
45{
46        mProgramType = GL_FRAGMENT_SHADER_ATI;
47    mProgramID = glGenFragmentShadersATI(1);
48}
49
50ATI_FS_GLGpuProgram::~ATI_FS_GLGpuProgram()
51{
52    // have to call this here reather than in Resource destructor
53    // since calling virtual methods in base destructors causes crash
54    unload(); 
55}
56
57void ATI_FS_GLGpuProgram::bindProgram(void)
58{
59        glEnable(mProgramType);
60        glBindFragmentShaderATI(mProgramID);
61}
62
63void ATI_FS_GLGpuProgram::unbindProgram(void)
64{
65        glDisable(mProgramType);
66}
67
68
69void ATI_FS_GLGpuProgram::bindProgramParameters(GpuProgramParametersSharedPtr params)
70{
71
72        // only supports float constants
73        const GpuLogicalBufferStruct* floatStruct = params->getFloatLogicalBufferStruct();
74
75        for (GpuLogicalIndexUseMap::const_iterator i = floatStruct->map.begin();
76                i != floatStruct->map.end(); ++i)
77        {
78                size_t logicalIndex = i->first;
79                const float* pFloat = params->getFloatPointer(i->second.physicalIndex);
80                // Iterate over the params, set in 4-float chunks (low-level)
81                for (size_t j = 0; j < i->second.currentSize; j+=4)
82                {
83                        glSetFragmentShaderConstantATI(GL_CON_0_ATI + logicalIndex, pFloat);
84                        pFloat += 4;
85                        ++logicalIndex;
86                }
87        }
88
89}
90
91void ATI_FS_GLGpuProgram::bindProgramPassIterationParameters(GpuProgramParametersSharedPtr params)
92{
93        if (params->hasPassIterationNumber())
94        {
95                size_t physicalIndex = params->getPassIterationNumberIndex();
96                size_t logicalIndex = params->getFloatLogicalIndexForPhysicalIndex(physicalIndex);
97                const float* pFloat = params->getFloatPointer(physicalIndex);
98                glSetFragmentShaderConstantATI( GL_CON_0_ATI + (GLuint)logicalIndex, pFloat);
99        }
100}
101
102
103void ATI_FS_GLGpuProgram::unloadImpl(void)
104{
105        glDeleteFragmentShaderATI(mProgramID);
106}
107
108
109void ATI_FS_GLGpuProgram::loadFromSource(void)
110{
111
112    PS_1_4 PS1_4Assembler;
113        // attempt to compile the source
114#ifdef _DEBUG
115        PS1_4Assembler.test(); // run compiler tests in debug mode
116#endif
117
118    bool Error = !PS1_4Assembler.compile(mSource.c_str());
119
120    if(!Error) { 
121                glBindFragmentShaderATI(mProgramID);
122                glBeginFragmentShaderATI();
123                        // compile was successfull so send the machine instructions thru GL to GPU
124                        Error = !PS1_4Assembler.bindAllMachineInstToFragmentShader();
125        glEndFragmentShaderATI();
126
127                // check GL for GPU machine instruction bind erros
128                if (Error)
129                {
130                        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
131                                "Cannot Bind ATI fragment shader :" + mName, mName); 
132                }
133
134    }
135    else
136        {
137                // an error occured when compiling the ps_1_4 source code
138                char buff[50];
139        sprintf(buff,"error on line %d in pixel shader source\n", PS1_4Assembler.mCurrentLine);
140
141                LogManager::getSingleton().logMessage("Warning: atifs compiler reported the following errors:");
142                LogManager::getSingleton().logMessage(buff + mName);
143
144                OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
145                        "Cannot Compile ATI fragment shader : " + mName + "\n\n" + buff , mName);// +
146    }
147
148
149}
150
Note: See TracBrowser for help on using the repository browser.