OgreD3D9GpuProgram.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __D3D9GpuProgram_H_
    00029 #define __D3D9GpuProgram_H_
    00030
    00031 // Precompiler options
    00032 #include "OgreD3D9Prerequisites.h"
    00033 #include "OgreGpuProgram.h"
    00034 #include "OgreD3D9Resource.h"
    00035
    00036 namespace Ogre {
    00037
    00039     class _OgreD3D9Export D3D9GpuProgram : public GpuProgram, public D3D9Resource
    00040     {
    00041     public:
    00043         class CmdColumnMajorMatrices : public ParamCommand
    00044         {
    00045         public:
    00046             String doGet(const void* target) const;
    00047             void doSet(void* target, const String& val);
    00048         };
    00050         class CmdExternalMicrocode : public ParamCommand
    00051         {
    00052         public:
    00053             String doGet(const void* target) const;
    00054             void doSet(void* target, const String& val);
    00055         };
    00056     protected:
    00057         static CmdColumnMajorMatrices msCmdColumnMajorMatrices;
    00058         static CmdExternalMicrocode msCmdExternalMicrocode;
    00059     public:
    00060         D3D9GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    00061             const String& group, bool isManual, ManualResourceLoader* loader);
    00062         ~D3D9GpuProgram();
    00063
    00064
    00066         void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
    00068         bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
    00069
    00072         void setExternalMicrocode(const void* pMicrocode, size_t size);
    00077         void setExternalMicrocode(ID3DXBuffer* pMicrocode);
    00079         LPD3DXBUFFER getExternalMicrocode(void);
    00080     protected:
    00082         void loadImpl(void);
    00084         void loadImpl(IDirect3DDevice9* d3d9Device);
    00086         void unloadImpl(void);
    00088         void loadFromSource(void);
    00090         void loadFromSource(IDirect3DDevice9* d3d9Device);
    00092         virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
    00093
    00094
    00102         virtual GpuProgramParametersSharedPtr createParameters(void);
    00103     protected:
    00104         bool mColumnMajorMatrices;
    00105         ID3DXBuffer* mExternalMicrocode;
    00106
    00107         void getMicrocodeFromCache( IDirect3DDevice9* d3d9Device );
    00108         void compileMicrocode( IDirect3DDevice9* d3d9Device );
    00109     };
    00110
    00112     class _OgreD3D9Export D3D9GpuVertexProgram : public D3D9GpuProgram
    00113     {
    00114     public:
    00115         D3D9GpuVertexProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    00116             const String& group, bool isManual, ManualResourceLoader* loader);
    00117         ~D3D9GpuVertexProgram();
    00118
    00120         IDirect3DVertexShader9* getVertexShader(void);
    00121
    00122         // Called immediately after the Direct3D device has been created.
    00123         virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
    00124
    00125         // Called before the Direct3D device is going to be destroyed.
    00126         virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
    00127
    00128     protected:
    00130         void unloadImpl(void);
    00131         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
    00132
    00133     protected:
    00134         typedef map<IDirect3DDevice9*, IDirect3DVertexShader9*>::type   DeviceToVertexShaderMap;
    00135         typedef DeviceToVertexShaderMap::iterator                       DeviceToVertexShaderIterator;
    00136
    00137         DeviceToVertexShaderMap     mMapDeviceToVertexShader;
    00138     };
    00139
    00141     class _OgreD3D9Export D3D9GpuFragmentProgram : public D3D9GpuProgram
    00142     {
    00143     public:
    00144         D3D9GpuFragmentProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
    00145             const String& group, bool isManual, ManualResourceLoader* loader);
    00146         ~D3D9GpuFragmentProgram();
    00148         IDirect3DPixelShader9* getPixelShader(void);
    00149
    00150         // Called immediately after the Direct3D device has been created.
    00151         virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
    00152
    00153         // Called before the Direct3D device is going to be destroyed.
    00154         virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
    00155
    00156     protected:
    00158         void unloadImpl(void);
    00159         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
    00160
    00161     protected:
    00162         typedef map<IDirect3DDevice9*, IDirect3DPixelShader9*>::type    DeviceToPixelShaderMap;
    00163         typedef DeviceToPixelShaderMap::iterator                        DeviceToPixelShaderIterator;
    00164
    00165         DeviceToPixelShaderMap      mMapDeviceToPixelShader;
    00166     };
    00173     class _OgreExport D3D9GpuProgramPtr : public SharedPtr<D3D9GpuProgram>
    00174     {
    00175     public:
    00176         D3D9GpuProgramPtr() : SharedPtr<D3D9GpuProgram>() {}
    00177         explicit D3D9GpuProgramPtr(D3D9GpuProgram* rep) : SharedPtr<D3D9GpuProgram>(rep) {}
    00178         D3D9GpuProgramPtr(const D3D9GpuProgramPtr& r) : SharedPtr<D3D9GpuProgram>(r) {}
    00179         D3D9GpuProgramPtr(const ResourcePtr& r) : SharedPtr<D3D9GpuProgram>()
    00180         {
    00181             // lock & copy other mutex pointer
    00182             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00183             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00184             pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
    00185             pUseCount = r.useCountPointer();
    00186             if (pUseCount)
    00187             {
    00188                 ++(*pUseCount);
    00189             }
    00190         }
    00191
    00193         D3D9GpuProgramPtr& operator=(const ResourcePtr& r)
    00194         {
    00195             if (pRep == static_cast<D3D9GpuProgram*>(r.getPointer()))
    00196                 return *this;
    00197             release();
    00198             // lock & copy other mutex pointer
    00199             OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
    00200             OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
    00201             pRep = static_cast<D3D9GpuProgram*>(r.getPointer());
    00202             pUseCount = r.useCountPointer();
    00203             if (pUseCount)
    00204             {
    00205                 ++(*pUseCount);
    00206             }
    00207             return *this;
    00208         }
    00209     };
    00210
    00211 }
    00212
    00213
    00214 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21