1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __D3D9GpuProgram_H_
|
---|
26 | #define __D3D9GpuProgram_H_
|
---|
27 |
|
---|
28 | // Precompiler options
|
---|
29 | #include "OgreD3D9Prerequisites.h"
|
---|
30 | #include "OgreGpuProgram.h"
|
---|
31 |
|
---|
32 | namespace Ogre {
|
---|
33 |
|
---|
34 | /** Direct3D implementation of a few things common to low-level vertex & fragment programs. */
|
---|
35 | class D3D9GpuProgram : public GpuProgram
|
---|
36 | {
|
---|
37 | protected:
|
---|
38 | LPDIRECT3DDEVICE9 mpDevice;
|
---|
39 | LPD3DXBUFFER mpExternalMicrocode; // microcode from elsewhere, we do NOT delete this ourselves
|
---|
40 | public:
|
---|
41 | D3D9GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
42 | const String& group, bool isManual, ManualResourceLoader* loader, LPDIRECT3DDEVICE9 pDev);
|
---|
43 |
|
---|
44 |
|
---|
45 | /** Tells the program to load from some externally created microcode instead of a file or source.
|
---|
46 | @remarks
|
---|
47 | It is the callers responsibility to delete the microcode buffer.
|
---|
48 | */
|
---|
49 | void setExternalMicrocode(LPD3DXBUFFER pMicrocode) { mpExternalMicrocode = pMicrocode; }
|
---|
50 | /** Gets the external microcode buffer, if any. */
|
---|
51 | LPD3DXBUFFER getExternalMicrocode(void) { return mpExternalMicrocode; }
|
---|
52 | protected:
|
---|
53 | /** @copydoc Resource::loadImpl */
|
---|
54 | void loadImpl(void);
|
---|
55 | /** Overridden from GpuProgram */
|
---|
56 | void loadFromSource(void);
|
---|
57 | /** Internal method to load from microcode, must be overridden by subclasses. */
|
---|
58 | virtual void loadFromMicrocode(LPD3DXBUFFER microcode) = 0;
|
---|
59 |
|
---|
60 |
|
---|
61 | };
|
---|
62 |
|
---|
63 | /** Direct3D implementation of low-level vertex programs. */
|
---|
64 | class D3D9GpuVertexProgram : public D3D9GpuProgram
|
---|
65 | {
|
---|
66 | protected:
|
---|
67 | LPDIRECT3DVERTEXSHADER9 mpVertexShader;
|
---|
68 | public:
|
---|
69 | D3D9GpuVertexProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
70 | const String& group, bool isManual, ManualResourceLoader* loader, LPDIRECT3DDEVICE9 pDev);
|
---|
71 | ~D3D9GpuVertexProgram();
|
---|
72 | /// Gets the vertex shader
|
---|
73 | LPDIRECT3DVERTEXSHADER9 getVertexShader(void) const { return mpVertexShader; }
|
---|
74 | protected:
|
---|
75 | /** @copydoc Resource::unloadImpl */
|
---|
76 | void unloadImpl(void);
|
---|
77 | void loadFromMicrocode(LPD3DXBUFFER microcode);
|
---|
78 | };
|
---|
79 |
|
---|
80 | /** Direct3D implementation of low-level fragment programs. */
|
---|
81 | class D3D9GpuFragmentProgram : public D3D9GpuProgram
|
---|
82 | {
|
---|
83 | protected:
|
---|
84 | LPDIRECT3DPIXELSHADER9 mpPixelShader;
|
---|
85 | public:
|
---|
86 | D3D9GpuFragmentProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
87 | const String& group, bool isManual, ManualResourceLoader* loader, LPDIRECT3DDEVICE9 pDev);
|
---|
88 | ~D3D9GpuFragmentProgram();
|
---|
89 | /// Gets the pixel shader
|
---|
90 | LPDIRECT3DPIXELSHADER9 getPixelShader(void) const { return mpPixelShader; }
|
---|
91 | protected:
|
---|
92 | /** @copydoc Resource::unloadImpl */
|
---|
93 | void unloadImpl(void);
|
---|
94 | void loadFromMicrocode(LPD3DXBUFFER microcode);
|
---|
95 | };
|
---|
96 | /** Specialisation of SharedPtr to allow SharedPtr to be assigned to D3D9GpuProgramPtr
|
---|
97 | @note Has to be a subclass since we need operator=.
|
---|
98 | We could templatise this instead of repeating per Resource subclass,
|
---|
99 | except to do so requires a form VC6 does not support i.e.
|
---|
100 | ResourceSubclassPtr<T> : public SharedPtr<T>
|
---|
101 | */
|
---|
102 | class _OgreExport D3D9GpuProgramPtr : public SharedPtr<D3D9GpuProgram>
|
---|
103 | {
|
---|
104 | public:
|
---|
105 | D3D9GpuProgramPtr() : SharedPtr<D3D9GpuProgram>() {}
|
---|
106 | explicit D3D9GpuProgramPtr(D3D9GpuProgram* rep) : SharedPtr<D3D9GpuProgram>(rep) {}
|
---|
107 | D3D9GpuProgramPtr(const D3D9GpuProgramPtr& r) : SharedPtr<D3D9GpuProgram>(r) {}
|
---|
108 | D3D9GpuProgramPtr(const ResourcePtr& r) : SharedPtr<D3D9GpuProgram>()
|
---|
109 | {
|
---|
110 | // lock & copy other mutex pointer
|
---|
111 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
|
---|
112 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
|
---|
113 | pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
|
---|
114 | pUseCount = r.useCountPointer();
|
---|
115 | if (pUseCount)
|
---|
116 | {
|
---|
117 | ++(*pUseCount);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | /// Operator used to convert a ResourcePtr to a D3D9GpuProgramPtr
|
---|
122 | D3D9GpuProgramPtr& operator=(const ResourcePtr& r)
|
---|
123 | {
|
---|
124 | if (pRep == static_cast<D3D9GpuProgram*>(r.getPointer()))
|
---|
125 | return *this;
|
---|
126 | release();
|
---|
127 | // lock & copy other mutex pointer
|
---|
128 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
|
---|
129 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
|
---|
130 | pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
|
---|
131 | pUseCount = r.useCountPointer();
|
---|
132 | if (pUseCount)
|
---|
133 | {
|
---|
134 | ++(*pUseCount);
|
---|
135 | }
|
---|
136 | return *this;
|
---|
137 | }
|
---|
138 | };
|
---|
139 |
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | #endif
|
---|