source: OGRE/trunk/ogrenew/OgreMain/include/OgreHighLevelGpuProgram.h @ 657

Revision 657, 7.0 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#ifndef __HighLevelGpuProgram_H__
26#define __HighLevelGpuProgram_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreGpuProgram.h"
30
31namespace Ogre {
32
33    /** Abstract base class representing a high-level program (a vertex or
34        fragment program).
35    @remarks
36        High-level programs are vertex and fragment programs written in a high-level
37        language such as Cg or HLSL, and as such do not require you to write assembler code
38        like GpuProgram does. However, the high-level program does eventually
39        get converted (compiled) into assembler and then eventually microcode which is
40        what runs on the GPU. As well as the convenience, some high-level languages like Cg allow
41        you to write a program which will operate under both Direct3D and OpenGL, something
42        which you cannot do with just GpuProgram (which requires you to write 2 programs and
43        use each in a Technique to provide cross-API compatibility). Ogre will be creating
44        a GpuProgram for you based on the high-level program, which is compiled specifically
45        for the API being used at the time, but this process is transparent.
46    @par
47        You cannot create high-level programs direct - use HighLevelGpuProgramManager instead.
48        Plugins can register new implementations of HighLevelGpuProgramFactory in order to add
49        support for new languages without requiring changes to the core Ogre API. To allow
50        custom parameters to be set, this class extends StringInterface - the application
51        can query on the available custom parameters and get/set them without having to
52        link specifically with it.
53    */
54    class _OgreExport HighLevelGpuProgram : public GpuProgram
55    {
56    protected:
57        /// Whether the high-level program (and it's parameter defs) is loaded
58        bool mHighLevelLoaded;
59        /// The underlying assembler program
60        GpuProgramPtr mAssemblerProgram;
61
62        /// Internal load high-level portion if not loaded
63        virtual void loadHighLevel(void);
64        /// Internal unload high-level portion if loaded
65        virtual void unloadHighLevel(void);
66        /** Internal load implementation, loads just the high-level portion, enough to
67            get parameters.
68        */
69        virtual void loadHighLevelImpl(void);
70        /** Internal method for creating an appropriate low-level program from this
71        high-level program, must be implemented by subclasses. */
72        virtual void createLowLevelImpl(void) = 0;
73        /// Internal unload implementation, must be implemented by subclasses
74        virtual void unloadHighLevelImpl(void) = 0;
75        /// Populate the passed parameters with name->index map, must be overridden
76        virtual void populateParameterNames(GpuProgramParametersSharedPtr params) = 0;
77        /** @copydoc Resource::loadImpl */
78        void loadImpl();
79        /** @copydoc Resource::unloadImpl */
80        void unloadImpl();
81    public:
82        /** Constructor, should be used only by factory classes. */
83        HighLevelGpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
84            const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
85        ~HighLevelGpuProgram();
86
87
88        /** Creates a new parameters object compatible with this program definition.
89        @remarks
90            Unlike low-level assembly programs, parameters objects are specific to the
91            program and therefore must be created from it rather than by the
92            HighLevelGpuProgramManager. This method creates a new instance of a parameters
93            object containing the definition of the parameters this program understands.
94        */
95        GpuProgramParametersSharedPtr createParameters(void);
96        /** @copydoc GpuProgram::getBindingDelegate */
97        GpuProgram* _getBindingDelegate(void) { return mAssemblerProgram.getPointer(); }
98
99
100
101    };
102
103    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to HighLevelGpuProgramPtr
104    @note Has to be a subclass since we need operator=.
105    We could templatise this instead of repeating per Resource subclass,
106    except to do so requires a form VC6 does not support i.e.
107    ResourceSubclassPtr<T> : public SharedPtr<T>
108    */
109    class _OgreExport HighLevelGpuProgramPtr : public SharedPtr<HighLevelGpuProgram>
110    {
111    public:
112        HighLevelGpuProgramPtr() : SharedPtr<HighLevelGpuProgram>() {}
113        explicit HighLevelGpuProgramPtr(HighLevelGpuProgram* rep) : SharedPtr<HighLevelGpuProgram>(rep) {}
114        HighLevelGpuProgramPtr(const HighLevelGpuProgramPtr& r) : SharedPtr<HighLevelGpuProgram>(r) {}
115        HighLevelGpuProgramPtr(const ResourcePtr& r) : SharedPtr<HighLevelGpuProgram>()
116        {
117                        // lock & copy other mutex pointer
118                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
119                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
120            pRep = static_cast<HighLevelGpuProgram*>(r.getPointer());
121            pUseCount = r.useCountPointer();
122            if (pUseCount)
123            {
124                ++(*pUseCount);
125            }
126        }
127
128        /// Operator used to convert a ResourcePtr to a HighLevelGpuProgramPtr
129        HighLevelGpuProgramPtr& operator=(const ResourcePtr& r)
130        {
131            if (pRep == static_cast<HighLevelGpuProgram*>(r.getPointer()))
132                return *this;
133            release();
134                        // lock & copy other mutex pointer
135                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
136                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
137            pRep = static_cast<HighLevelGpuProgram*>(r.getPointer());
138            pUseCount = r.useCountPointer();
139            if (pUseCount)
140            {
141                ++(*pUseCount);
142            }
143            return *this;
144        }
145                /// Operator used to convert a GpuProgramPtr to a HighLevelGpuProgramPtr
146                HighLevelGpuProgramPtr& operator=(const GpuProgramPtr& r);
147    };
148
149}
150#endif
Note: See TracBrowser for help on using the repository browser.