OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreD3D9GpuProgram.h
Go to the documentation of this file.
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-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __D3D9GpuProgram_H_
29 #define __D3D9GpuProgram_H_
30 
31 // Precompiler options
32 #include "OgreD3D9Prerequisites.h"
33 #include "OgreGpuProgram.h"
34 #include "OgreD3D9Resource.h"
35 
36 namespace Ogre {
37 
40  {
41  public:
44  {
45  public:
46  String doGet(const void* target) const;
47  void doSet(void* target, const String& val);
48  };
51  {
52  public:
53  String doGet(const void* target) const;
54  void doSet(void* target, const String& val);
55  };
56  protected:
59  public:
60  D3D9GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
61  const String& group, bool isManual, ManualResourceLoader* loader);
62  ~D3D9GpuProgram();
63 
64 
66  void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
68  bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
69 
72  void setExternalMicrocode(const void* pMicrocode, size_t size);
77  void setExternalMicrocode(ID3DXBuffer* pMicrocode);
79  LPD3DXBUFFER getExternalMicrocode(void);
80  protected:
82  void loadImpl(void);
84  void loadImpl(IDirect3DDevice9* d3d9Device);
86  void unloadImpl(void);
88  void loadFromSource(void);
90  void loadFromSource(IDirect3DDevice9* d3d9Device);
92  virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
93 
94 
102  virtual GpuProgramParametersSharedPtr createParameters(void);
103  protected:
105  ID3DXBuffer* mExternalMicrocode;
106 
107  void getMicrocodeFromCache( IDirect3DDevice9* d3d9Device );
108  void compileMicrocode( IDirect3DDevice9* d3d9Device );
109  };
110 
113  {
114  public:
115  D3D9GpuVertexProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
116  const String& group, bool isManual, ManualResourceLoader* loader);
118 
120  IDirect3DVertexShader9* getVertexShader(void);
121 
122  // Called immediately after the Direct3D device has been created.
123  virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
124 
125  // Called before the Direct3D device is going to be destroyed.
126  virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
127 
128  protected:
130  void unloadImpl(void);
131  void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
132 
133  protected:
135  typedef DeviceToVertexShaderMap::iterator DeviceToVertexShaderIterator;
136 
138  };
139 
142  {
143  public:
144  D3D9GpuFragmentProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
145  const String& group, bool isManual, ManualResourceLoader* loader);
148  IDirect3DPixelShader9* getPixelShader(void);
149 
150  // Called immediately after the Direct3D device has been created.
151  virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
152 
153  // Called before the Direct3D device is going to be destroyed.
154  virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
155 
156  protected:
158  void unloadImpl(void);
159  void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
160 
161  protected:
163  typedef DeviceToPixelShaderMap::iterator DeviceToPixelShaderIterator;
164 
166  };
173  class _OgreExport D3D9GpuProgramPtr : public SharedPtr<D3D9GpuProgram>
174  {
175  public:
180  {
181  // lock & copy other mutex pointer
182  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
183  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
184  pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
185  pUseCount = r.useCountPointer();
186  if (pUseCount)
187  {
188  ++(*pUseCount);
189  }
190  }
191 
194  {
195  if (pRep == static_cast<D3D9GpuProgram*>(r.getPointer()))
196  return *this;
197  release();
198  // lock & copy other mutex pointer
199  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
200  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
201  pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
202  pUseCount = r.useCountPointer();
203  if (pUseCount)
204  {
205  ++(*pUseCount);
206  }
207  return *this;
208  }
209  };
210 
211 }
212 
213 
214 #endif
static CmdExternalMicrocode msCmdExternalMicrocode
map< IDirect3DDevice9 *, IDirect3DVertexShader9 * >::type DeviceToVertexShaderMap
Direct3D implementation of low-level vertex programs.
T * getPointer() const
DeviceToVertexShaderMap mMapDeviceToVertexShader
#define _OgreExport
Definition: OgrePlatform.h:233
bool getColumnMajorMatrices(void) const
Gets whether matrix packed in column-major order.
Command object for setting matrix packing in column-major order.
Defines a program which runs on the GPU such as a vertex or fragment program.
Specialisation of SharedPtr to allow SharedPtr to be assigned to D3D9GpuProgramPtr.
Interface describing a manual resource loader.
Definition: OgreResource.h:513
map< IDirect3DDevice9 *, IDirect3DPixelShader9 * >::type DeviceToPixelShaderMap
D3D9GpuProgramPtr(const D3D9GpuProgramPtr &r)
Direct3D implementation of a few things common to low-level vertex & fragment programs.
Direct3D implementation of low-level fragment programs.
DeviceToPixelShaderMap::iterator DeviceToPixelShaderIterator
ID3DXBuffer * mExternalMicrocode
D3D9GpuProgramPtr & operator=(const ResourcePtr &r)
Operator used to convert a ResourcePtr to a D3D9GpuProgramPtr.
#define _OgreD3D9Export
DeviceToPixelShaderMap mMapDeviceToPixelShader
Command object for getting/setting external micro code (void*)
void setColumnMajorMatrices(bool columnMajor)
Sets whether matrix packing in column-major order.
unsigned long long int ResourceHandle
Definition: OgreResource.h:40
#define OGRE_LOCK_MUTEX(name)
DeviceToVertexShaderMap::iterator DeviceToVertexShaderIterator
Defines a generic resource handler.
D3D9GpuProgramPtr(const ResourcePtr &r)
unsigned int * useCountPointer() const
_StringBase String
#define OGRE_COPY_AUTO_SHARED_MUTEX(from)
D3D9GpuProgramPtr(D3D9GpuProgram *rep)
Abstract class which is command object which gets/sets parameters.
static CmdColumnMajorMatrices msCmdColumnMajorMatrices
Represents a Direct3D rendering resource.