Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/RenderSystems/Direct3D9/include/OgreD3D9GpuProgram.h @ 45

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

=hoffentlich gehts jetzt

File size: 5.8 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 __D3D9GpuProgram_H_
30#define __D3D9GpuProgram_H_
31
32// Precompiler options
33#include "OgreD3D9Prerequisites.h"
34#include "OgreGpuProgram.h"
35
36namespace Ogre {
37
38    /** Direct3D implementation of a few things common to low-level vertex & fragment programs. */
39    class D3D9GpuProgram : public GpuProgram
40    {
41    protected:
42        LPDIRECT3DDEVICE9 mpDevice;
43        LPD3DXBUFFER mpExternalMicrocode; // microcode from elsewhere, we do NOT delete this ourselves
44    public:
45        D3D9GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
46            const String& group, bool isManual, ManualResourceLoader* loader, LPDIRECT3DDEVICE9 pDev);
47       
48
49        /** Tells the program to load from some externally created microcode instead of a file or source.
50        @remarks
51            It is the callers responsibility to delete the microcode buffer.
52        */ 
53        void setExternalMicrocode(LPD3DXBUFFER pMicrocode) { mpExternalMicrocode = pMicrocode; }
54        /** Gets the external microcode buffer, if any. */
55        LPD3DXBUFFER getExternalMicrocode(void) { return mpExternalMicrocode; }
56    protected:
57        /** @copydoc Resource::loadImpl */
58        void loadImpl(void);
59        /** Overridden from GpuProgram */
60        void loadFromSource(void);
61        /** Internal method to load from microcode, must be overridden by subclasses. */
62        virtual void loadFromMicrocode(LPD3DXBUFFER microcode) = 0;
63
64
65    };
66
67    /** Direct3D implementation of low-level vertex programs. */
68    class D3D9GpuVertexProgram : public D3D9GpuProgram
69    {
70    protected:
71        LPDIRECT3DVERTEXSHADER9 mpVertexShader;
72    public:
73        D3D9GpuVertexProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
74            const String& group, bool isManual, ManualResourceLoader* loader, LPDIRECT3DDEVICE9 pDev);
75                ~D3D9GpuVertexProgram();
76        /// Gets the vertex shader
77        LPDIRECT3DVERTEXSHADER9 getVertexShader(void) const { return mpVertexShader; }
78    protected:
79        /** @copydoc Resource::unloadImpl */
80        void unloadImpl(void);
81        void loadFromMicrocode(LPD3DXBUFFER microcode);
82    };
83
84    /** Direct3D implementation of low-level fragment programs. */
85    class D3D9GpuFragmentProgram : public D3D9GpuProgram
86    {
87    protected:
88        LPDIRECT3DPIXELSHADER9 mpPixelShader;
89    public:
90        D3D9GpuFragmentProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
91            const String& group, bool isManual, ManualResourceLoader* loader, LPDIRECT3DDEVICE9 pDev);
92                ~D3D9GpuFragmentProgram();
93        /// Gets the pixel shader
94        LPDIRECT3DPIXELSHADER9 getPixelShader(void) const { return mpPixelShader; }
95    protected:
96        /** @copydoc Resource::unloadImpl */
97        void unloadImpl(void);
98        void loadFromMicrocode(LPD3DXBUFFER microcode);
99    };
100    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to D3D9GpuProgramPtr
101    @note Has to be a subclass since we need operator=.
102    We could templatise this instead of repeating per Resource subclass,
103    except to do so requires a form VC6 does not support i.e.
104    ResourceSubclassPtr<T> : public SharedPtr<T>
105    */
106    class _OgreExport D3D9GpuProgramPtr : public SharedPtr<D3D9GpuProgram> 
107    {
108    public:
109        D3D9GpuProgramPtr() : SharedPtr<D3D9GpuProgram>() {}
110        explicit D3D9GpuProgramPtr(D3D9GpuProgram* rep) : SharedPtr<D3D9GpuProgram>(rep) {}
111        D3D9GpuProgramPtr(const D3D9GpuProgramPtr& r) : SharedPtr<D3D9GpuProgram>(r) {} 
112        D3D9GpuProgramPtr(const ResourcePtr& r) : SharedPtr<D3D9GpuProgram>()
113        {
114                        // lock & copy other mutex pointer
115                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
116                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
117            pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
118            pUseCount = r.useCountPointer();
119            if (pUseCount)
120            {
121                ++(*pUseCount);
122            }
123        }
124
125        /// Operator used to convert a ResourcePtr to a D3D9GpuProgramPtr
126        D3D9GpuProgramPtr& operator=(const ResourcePtr& r)
127        {
128            if (pRep == static_cast<D3D9GpuProgram*>(r.getPointer()))
129                return *this;
130            release();
131                        // lock & copy other mutex pointer
132                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
133                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
134            pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
135            pUseCount = r.useCountPointer();
136            if (pUseCount)
137            {
138                ++(*pUseCount);
139            }
140            return *this;
141        }
142    };
143
144}
145
146
147#endif
Note: See TracBrowser for help on using the repository browser.