D3DViewportRenderer.h
#ifndef D3DViewportRenderer_h_
#define D3DViewportRenderer_h_
#include <maya/MImage.h>
#include <maya/MViewportRenderer.h>
#include <maya/MDagPath.h>
#include <maya/MObjectHandle.h>
#include <maya/MMessage.h>
#include <maya/MStringArray.h>
#include <maya/MMatrix.h>
#include <list>
#include <D3DResourceManager.h>
#if defined(D3D9_SUPPORTED)
#define WIN32_LEAN_AND_MEAN
#include <d3d9.h>
#include <d3dx9.h>
#endif
#if defined(D3D9_SUPPORTED)
struct PlainVertex
{
float x, y, z;
enum FVF
{
FVF_Flags = D3DFVF_XYZ
};
};
#endif
class MBoundingBox;
class MDagPath;
class MObject;
#pragma warning (disable:4324)
#pragma warning (disable:4239)
#pragma warning (disable:4701)
class D3DViewportRenderer : public MViewportRenderer
{
public:
D3DViewportRenderer();
virtual ~D3DViewportRenderer();
virtual MStatus initialize();
virtual MStatus uninitialize();
virtual MStatus render( const MRenderingInfo &renderInfo );
virtual bool nativelySupports( MViewportRenderer::RenderingAPI api,
float version );
virtual bool override( MViewportRenderer::RenderingOverride override );
protected:
RenderingAPI m_API;
float m_Version;
unsigned int m_renderWidth;
unsigned int m_renderHeight;
#if defined(D3D9_SUPPORTED)
public:
bool buildRenderTargets(unsigned int width, unsigned int height);
bool translateCamera( const MRenderingInfo &renderInfo );
bool setupMatrices( const MRenderingInfo &renderInfo );
bool renderToTarget( const MRenderingInfo &renderInfo );
bool drawScene( const MRenderingInfo &renderInfo );
bool drawBounds(const MMatrix &matrix, const MBoundingBox &box, bool filled, bool useDummyGeometry,
float color[3],
LPDIRECT3DVERTEXBUFFER9 buffer = NULL);
bool drawCube(float minVal[3], float maxVal[3], bool filled, bool useDummyGeometry,
float color[3],
LPDIRECT3DVERTEXBUFFER9 buffer = NULL);
bool drawSurface( const MDagPath &dagPath, bool active, bool templated);
bool setSurfaceMaterial( const MDagPath &dagPath );
bool setSurfaceMaterialShader( const MDagPath &dagPath, D3DGeometry* Geometry,
const D3DXMATRIXA16 &objectToWorld,
const D3DXMATRIXA16 &objectToWorldInvTranspose,
const D3DXMATRIXA16 &worldViewProjection,
const D3DXVECTOR4 &worldEyePosition);
bool initializePostEffects(LPDIRECT3DDEVICE9 D3D);
void drawFullScreenQuad(float leftU, float topV,
float rightU, float bottomV,
float targetWidth, float targetHeight,
LPDIRECT3DDEVICE9 D3D);
bool postRenderToTarget();
bool readFromTargetToSystemMemory();
const D3DResourceManager& resourceManager() const { return m_resourceManager; }
void clearResources(bool onlyInvalidItems, bool clearShaders);
protected:
HWND m_hWnd;
LPDIRECT3D9 m_pD3D;
LPDIRECT3DDEVICE9 m_pD3DDevice;
bool m_wantFloatingPointTargets;
D3DFORMAT m_intermediateTargetFormat;
D3DFORMAT m_outputTargetFormat;
LPDIRECT3DTEXTURE9 m_pTextureInterm;
LPDIRECT3DSURFACE9 m_pTextureIntermSurface;
LPDIRECT3DTEXTURE9 m_pTextureOutput;
LPDIRECT3DSURFACE9 m_pTextureOutputSurface;
LPDIRECT3DTEXTURE9 m_pTexturePost;
D3DFORMAT m_depthStencilFormat;
bool m_requireDepthStencilReadback;
LPDIRECT3DSURFACE9 m_pDepthStencilSurface;
LPDIRECT3DSURFACE9 m_SystemMemorySurface;
D3DXMATRIXA16 m_matWorld;
MImage m_readBackBuffer;
LPDIRECT3DVERTEXBUFFER9 m_pBoundsBuffer;
LPD3DXMESH m_pGeometry;
D3DResourceManager m_resourceManager;
D3DXMATRIXA16 m_currentViewMatrix;
MMatrix mm_currentViewMatrix;
D3DXMATRIXA16 m_currentProjectionMatrix;
#endif
};
#endif