source: OGRE/trunk/ogrenew/RenderSystems/Direct3D7/include/d3dutil.h @ 657

Revision 657, 4.2 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1//-----------------------------------------------------------------------
2// File: D3DUtil.h
3//
4// Desc: Helper functions and typing shortcuts for Direct3D programming.
5//
6//
7// Copyright (C) 1997 Microsoft Corporation. All rights reserved
8//-----------------------------------------------------------------------
9
10#ifndef D3DUTIL_H
11#define D3DUTIL_H
12
13#include "OgrePrerequisites.h"
14#include <ddraw.h>
15#include <d3d.h>
16
17
18//-----------------------------------------------------------------------
19// Typing shortcuts for deleting and freeing objects.
20//-----------------------------------------------------------------------
21#define SAFE_DELETE(p)  { if(p) { delete (p);     (p)=NULL; } }
22#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
23
24
25
26
27//-----------------------------------------------------------------------
28// Short cut functions for creating and using DX structures
29//-----------------------------------------------------------------------
30VOID D3DUtil_InitDeviceDesc( D3DDEVICEDESC7& ddDevDesc );
31VOID D3DUtil_InitSurfaceDesc( DDSURFACEDESC2& ddsd, DWORD dwFlags=0,
32                              DWORD dwCaps=0 );
33VOID D3DUtil_InitViewport( D3DVIEWPORT2& vdViewData, DWORD dwWidth=0,
34                           DWORD dwHeight=0 );
35VOID D3DUtil_InitMaterial( D3DMATERIAL& mdMtrlData, FLOAT r=0.0f, FLOAT g=0.0f,
36                           FLOAT b=0.0f );
37VOID D3DUtil_InitLight( D3DLIGHT& ldLightData, D3DLIGHTTYPE ltType,
38                        FLOAT x=0.0f, FLOAT y=0.0f, FLOAT z=0.0f );
39
40
41
42
43//-----------------------------------------------------------------------
44// Miscellaneous helper functions
45//-----------------------------------------------------------------------
46LPDIRECTDRAW7 D3DUtil_GetDirectDrawFromDevice( LPDIRECT3DDEVICE7 pd3dDevice );
47DWORD         D3DUtil_GetDeviceMemoryType( LPDIRECT3DDEVICE7 pd3dDevice );
48DWORD         D3DUtil_GetDisplayDepth( LPDIRECTDRAW7 pDD4=NULL );
49
50
51
52
53//-----------------------------------------------------------------------
54// D3D Matrix functions. For performance reasons, some functions are inline.
55//-----------------------------------------------------------------------
56HRESULT D3DUtil_SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom,
57                               D3DVECTOR& vAt, D3DVECTOR& vUp );
58HRESULT D3DUtil_SetProjectionMatrix( D3DMATRIX& mat, FLOAT fFOV = 1.570795f,
59                                     FLOAT fAspect = 1.0f,
60                                     FLOAT fNearPlane = 1.0f,
61                                     FLOAT fFarPlane = 1000.0f );
62
63inline VOID D3DUtil_SetIdentityMatrix( D3DMATRIX& m )
64{
65    m._12 = m._13 = m._14 = m._21 = m._23 = m._24 = 0.0f;
66    m._31 = m._32 = m._34 = m._41 = m._42 = m._43 = 0.0f;
67    m._11 = m._22 = m._33 = m._44 = 1.0f;
68}
69
70inline VOID D3DUtil_SetTranslateMatrix( D3DMATRIX& m, FLOAT tx, FLOAT ty,
71                                        FLOAT tz )
72{ D3DUtil_SetIdentityMatrix( m ); m._41 = tx; m._42 = ty; m._43 = tz; }
73
74inline VOID D3DUtil_SetTranslateMatrix( D3DMATRIX& m, D3DVECTOR& v )
75{ D3DUtil_SetTranslateMatrix( m, v.x, v.y, v.z ); }
76
77inline VOID D3DUtil_SetScaleMatrix( D3DMATRIX& m, FLOAT sx, FLOAT sy,
78                                    FLOAT sz )
79{ D3DUtil_SetIdentityMatrix( m ); m._11 = sx; m._22 = sy; m._33 = sz; }
80
81inline VOID SetScaleMatrix( D3DMATRIX& m, D3DVECTOR& v )
82{ D3DUtil_SetScaleMatrix( m, v.x, v.y, v.z ); }
83
84VOID    D3DUtil_SetRotateXMatrix( D3DMATRIX& mat, FLOAT fRads );
85VOID    D3DUtil_SetRotateYMatrix( D3DMATRIX& mat, FLOAT fRads );
86VOID    D3DUtil_SetRotateZMatrix( D3DMATRIX& mat, FLOAT fRads );
87VOID    D3DUtil_SetRotationMatrix( D3DMATRIX& mat, D3DVECTOR& vDir,
88                                   FLOAT fRads );
89
90
91
92
93//-----------------------------------------------------------------------
94// Debug printing support
95//-----------------------------------------------------------------------
96
97HRESULT _DbgOut( TCHAR*, DWORD, HRESULT, TCHAR* );
98
99#if defined(DEBUG) | defined(_DEBUG)
100    #define DEBUG_MSG(str)    _DbgOut( __FILE__, (DWORD)__LINE__, 0, str )
101    #define DEBUG_ERR(hr,str) _DbgOut( __FILE__, (DWORD)__LINE__, hr, str )
102#else
103    #define DEBUG_MSG(str)    (0L)
104    #define DEBUG_ERR(hr,str) (hr)
105#endif
106
107
108
109
110#endif // D3DUTIL_H
Note: See TracBrowser for help on using the repository browser.