1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://ogre.sourceforge.net/
|
---|
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 __D3DRENDERSYSTEM_H__
|
---|
26 | #define __D3DRENDERSYSTEM_H__
|
---|
27 |
|
---|
28 | // Precompiler options
|
---|
29 | #include "OgreD3D7Prerequisites.h"
|
---|
30 | #include "OgreString.h"
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | #include "OgreRenderSystem.h"
|
---|
35 | #include "OgreD3D7HardwareBufferManager.h"
|
---|
36 |
|
---|
37 | namespace Ogre {
|
---|
38 |
|
---|
39 | class DDDriverList;
|
---|
40 | class DDDriver;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | Implementation of DirectX as a rendering system.
|
---|
44 | */
|
---|
45 | class D3DRenderSystem : public RenderSystem
|
---|
46 | {
|
---|
47 | private:
|
---|
48 | // Direct3D rendering device
|
---|
49 | // Only created after top-level window created
|
---|
50 | LPDIRECT3DDEVICE7 mlpD3DDevice;
|
---|
51 | D3DDEVICEDESC7 mD3DDeviceDesc;
|
---|
52 |
|
---|
53 | // List of DD drivers installed (video cards)
|
---|
54 | // Enumerates itself
|
---|
55 | DDDriverList* mDriverList;
|
---|
56 | // Currently active driver
|
---|
57 | DDDriver* mActiveDDDriver;
|
---|
58 |
|
---|
59 |
|
---|
60 | HINSTANCE mhInstance;
|
---|
61 | bool mDeviceLost;
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | // Stored options
|
---|
66 | ConfigOptionMap mOptions;
|
---|
67 |
|
---|
68 | // Private utilities
|
---|
69 | DDDriverList* getDirectDrawDrivers(void);
|
---|
70 | void refreshDDSettings(void);
|
---|
71 |
|
---|
72 | /// enum identifying D3D9 tex. types
|
---|
73 | enum eD3DTexType
|
---|
74 | {
|
---|
75 | /// standard texture
|
---|
76 | D3D_TEX_TYPE_NORMAL,
|
---|
77 | /// cube texture
|
---|
78 | D3D_TEX_TYPE_CUBE,
|
---|
79 | /// volume texture
|
---|
80 | D3D_TEX_TYPE_VOLUME
|
---|
81 | };
|
---|
82 |
|
---|
83 | /// return the D3DtexType equivalent of a Ogre tex. type
|
---|
84 | eD3DTexType _ogreTexTypeToD3DTexType(TextureType ogreTexType)
|
---|
85 | {
|
---|
86 | eD3DTexType ret;
|
---|
87 | switch (ogreTexType)
|
---|
88 | {
|
---|
89 | case TEX_TYPE_1D :
|
---|
90 | case TEX_TYPE_2D :
|
---|
91 | ret = D3D_TEX_TYPE_NORMAL;
|
---|
92 | break;
|
---|
93 | case TEX_TYPE_CUBE_MAP :
|
---|
94 | ret = D3D_TEX_TYPE_CUBE;
|
---|
95 | break;
|
---|
96 | default :
|
---|
97 | OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "Invalid tex.type", "D3D9RenderSystem::_ogreTexTypeToD3DTexType" );
|
---|
98 | break;
|
---|
99 | }
|
---|
100 | return ret;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /// structure holding texture unit settings for every stage
|
---|
104 | struct sD3DTextureStageDesc
|
---|
105 | {
|
---|
106 | /// the type of the texture
|
---|
107 | eD3DTexType texType;
|
---|
108 | /// wich texCoordIndex to use
|
---|
109 | size_t coordIndex;
|
---|
110 | /// type of auto tex. calc. used
|
---|
111 | TexCoordCalcMethod autoTexCoordType;
|
---|
112 | /// Frustum, used with the above in projective texturing
|
---|
113 | const Frustum* frustum;
|
---|
114 | /// texture, if it's 0/NULL the tex layer is disabled
|
---|
115 | LPDIRECTDRAWSURFACE7 pTex;
|
---|
116 | } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
|
---|
117 |
|
---|
118 |
|
---|
119 | // Matrix conversion
|
---|
120 | D3DMATRIX makeD3DMatrix(const Matrix4& mat);
|
---|
121 | Matrix4 convertD3DMatrix(const D3DMATRIX& mat);
|
---|
122 |
|
---|
123 | void initConfigOptions(void);
|
---|
124 | void initInputDevices(void);
|
---|
125 | void processInputDevices(void);
|
---|
126 | void setD3DLight(size_t index, Light* light);
|
---|
127 |
|
---|
128 | D3DCMPFUNC convertCompareFunction(CompareFunction func);
|
---|
129 | D3DSTENCILOP convertStencilOp(StencilOperation op);
|
---|
130 |
|
---|
131 | // state management methods, very primitive !!!
|
---|
132 | HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value);
|
---|
133 | HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
|
---|
134 |
|
---|
135 |
|
---|
136 | D3DTEXTURESTAGESTATETYPE _getFilterCode(FilterType ft) const;
|
---|
137 | DWORD _getFilter(FilterType ft, FilterOptions fo) const;
|
---|
138 | DWORD _getCurrentAnisotropy(size_t unit);
|
---|
139 |
|
---|
140 | HardwareBufferManager* mHardwareBufferManager;
|
---|
141 | GpuProgramManager* mGpuProgramManager;
|
---|
142 |
|
---|
143 |
|
---|
144 | unsigned short mCurrentLights;
|
---|
145 | Matrix4 mViewMatrix;
|
---|
146 | // saved scene blending factors
|
---|
147 | SceneBlendFactor mSavedSrcFactor, mSavedDestFactor;
|
---|
148 |
|
---|
149 |
|
---|
150 | public:
|
---|
151 | // Default constructor / destructor
|
---|
152 | D3DRenderSystem(HINSTANCE hInstance);
|
---|
153 | ~D3DRenderSystem();
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 | // ----------------------------------
|
---|
158 | // Overridden RenderSystem functions
|
---|
159 | // ----------------------------------
|
---|
160 | /** See
|
---|
161 | RenderSystem
|
---|
162 | */
|
---|
163 | const String& getName(void) const;
|
---|
164 | /** See
|
---|
165 | RenderSystem
|
---|
166 | */
|
---|
167 | ConfigOptionMap& getConfigOptions(void);
|
---|
168 | /** See
|
---|
169 | RenderSystem
|
---|
170 | */
|
---|
171 | void setConfigOption(const String &name, const String &value);
|
---|
172 | /** See
|
---|
173 | RenderSystem
|
---|
174 | */
|
---|
175 | String validateConfigOptions(void);
|
---|
176 | /** See
|
---|
177 | RenderSystem
|
---|
178 | */
|
---|
179 | RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
|
---|
180 | /** See
|
---|
181 | RenderSystem
|
---|
182 | */
|
---|
183 | void reinitialise(void); // Used if settings changed mid-rendering
|
---|
184 | /** See
|
---|
185 | RenderSystem
|
---|
186 | */
|
---|
187 | void shutdown(void);
|
---|
188 |
|
---|
189 | /** See
|
---|
190 | RenderSystem
|
---|
191 | */
|
---|
192 | void setAmbientLight(float r, float g, float b);
|
---|
193 | /** See
|
---|
194 | RenderSystem
|
---|
195 | */
|
---|
196 | void setShadingType(ShadeOptions so);
|
---|
197 | /** See
|
---|
198 | RenderSystem
|
---|
199 | */
|
---|
200 | void setLightingEnabled(bool enabled);
|
---|
201 |
|
---|
202 | /// @copydoc RenderSystem::createRenderWindow
|
---|
203 | RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
|
---|
204 | bool fullScreen, const NameValuePairList *miscParams = 0);
|
---|
205 |
|
---|
206 | /// @copydoc RenderSystem::createRenderTexture
|
---|
207 | RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
|
---|
208 | TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8,
|
---|
209 | const NameValuePairList *miscParams = 0 );
|
---|
210 |
|
---|
211 | /** See
|
---|
212 | RenderSystem
|
---|
213 | */
|
---|
214 | void destroyRenderWindow(RenderWindow* pWin);
|
---|
215 |
|
---|
216 | /** See
|
---|
217 | RenderSystem
|
---|
218 | */
|
---|
219 | String getErrorDescription(long errorNumber) const;
|
---|
220 |
|
---|
221 | /** See
|
---|
222 | RenderSystem
|
---|
223 | */
|
---|
224 | void convertColourValue(const ColourValue& colour, uint32* pDest);
|
---|
225 |
|
---|
226 | /// Notify of a device lost
|
---|
227 | void _notifyDeviceLost(void);
|
---|
228 | /// Attempt to restore a device
|
---|
229 | void _restoreLostDevice(void);
|
---|
230 | /// Restore all surfaces
|
---|
231 | void _restoreSurfaces(void);
|
---|
232 | /// Recreate the primary context
|
---|
233 | void _recreateContext(void);
|
---|
234 |
|
---|
235 | // -----------------------------
|
---|
236 | // Low-level overridden members
|
---|
237 | // -----------------------------
|
---|
238 | /** See
|
---|
239 | RenderSystem
|
---|
240 | */
|
---|
241 | void _useLights(const LightList& lights, unsigned short limit);
|
---|
242 | /** See
|
---|
243 | RenderSystem
|
---|
244 | */
|
---|
245 | void _setWorldMatrix(const Matrix4 &m);
|
---|
246 | /** See
|
---|
247 | RenderSystem
|
---|
248 | */
|
---|
249 | void _setViewMatrix(const Matrix4 &m);
|
---|
250 | /** See
|
---|
251 | RenderSystem
|
---|
252 | */
|
---|
253 | void _setProjectionMatrix(const Matrix4 &m);
|
---|
254 | /** See
|
---|
255 | RenderSystem
|
---|
256 | */
|
---|
257 | void _setSurfaceParams(const ColourValue &ambient,
|
---|
258 | const ColourValue &diffuse, const ColourValue &specular,
|
---|
259 | const ColourValue &emissive, Real shininess, TrackVertexColourType tracking);
|
---|
260 | /** See
|
---|
261 | RenderSystem
|
---|
262 | */
|
---|
263 | void _setTexture(size_t unit, bool enabled, const String &texname);
|
---|
264 | /** See
|
---|
265 | RenderSystem
|
---|
266 | */
|
---|
267 | void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm);
|
---|
268 | /** See
|
---|
269 | RenderSystem
|
---|
270 | */
|
---|
271 | void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam);
|
---|
272 | /** See
|
---|
273 | RenderSystem
|
---|
274 | */
|
---|
275 | void _setTextureMatrix(size_t unit, const Matrix4& xform);
|
---|
276 | /** See
|
---|
277 | RenderSystem
|
---|
278 | */
|
---|
279 | void _setTextureCoordSet( size_t unit, size_t index );
|
---|
280 | /** See
|
---|
281 | RenderSystem
|
---|
282 | */
|
---|
283 | void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
|
---|
284 | const Frustum* frustum = 0);
|
---|
285 | /** See
|
---|
286 | RenderSystem
|
---|
287 | */
|
---|
288 | void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
|
---|
289 | /** See
|
---|
290 | RenderSystem
|
---|
291 | */
|
---|
292 | void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
|
---|
293 | /** See
|
---|
294 | RenderSystem
|
---|
295 | */
|
---|
296 | void _setViewport(Viewport *vp);
|
---|
297 | /** See
|
---|
298 | RenderSystem
|
---|
299 | */
|
---|
300 | void _beginFrame(void);
|
---|
301 | /** See
|
---|
302 | RenderSystem
|
---|
303 | */
|
---|
304 | void _render(const RenderOperation& op);
|
---|
305 | /** See
|
---|
306 | RenderSystem
|
---|
307 | */
|
---|
308 | void _endFrame(void);
|
---|
309 | /** See
|
---|
310 | RenderSystem
|
---|
311 | */
|
---|
312 | void _setCullingMode(CullingMode mode);
|
---|
313 | /** See
|
---|
314 | RenderSystem
|
---|
315 | */
|
---|
316 | void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
|
---|
317 | /** See
|
---|
318 | RenderSystem
|
---|
319 | */
|
---|
320 | void _setDepthBufferCheckEnabled(bool enabled = true);
|
---|
321 | /** See
|
---|
322 | RenderSystem
|
---|
323 | */
|
---|
324 | void _setDepthBufferWriteEnabled(bool enabled = true);
|
---|
325 | /** See
|
---|
326 | RenderSystem
|
---|
327 | */
|
---|
328 | void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
|
---|
329 | /** See
|
---|
330 | RenderSystem
|
---|
331 | */
|
---|
332 | void _setDepthBias(ushort bias);
|
---|
333 | /** See RenderSystem
|
---|
334 | @remarks
|
---|
335 | Direct3D7 DOES NOT SUPPORT COLOUR WRITE MASKING! This feature is
|
---|
336 | emulated by using a null scene blend which will only work as long
|
---|
337 | as setSceneBlend is called before it.
|
---|
338 | */
|
---|
339 | void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
|
---|
340 |
|
---|
341 | /** See
|
---|
342 | RenderSystem
|
---|
343 | */
|
---|
344 | void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
|
---|
345 | /** See
|
---|
346 | RenderSystem
|
---|
347 | */
|
---|
348 | void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane,
|
---|
349 | Real farPlane, Matrix4& dest, bool forGpuProgram = false);
|
---|
350 | /** See
|
---|
351 | RenderSystem
|
---|
352 | */
|
---|
353 | void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
|
---|
354 | Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
|
---|
355 | /** See
|
---|
356 | RenderSystem
|
---|
357 | */
|
---|
358 | void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
|
---|
359 | Matrix4& dest, bool forGpuProgram = false);
|
---|
360 | /** See
|
---|
361 | RenderSystem
|
---|
362 | */
|
---|
363 | void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
|
---|
364 | bool forGpuProgram);
|
---|
365 | /** See
|
---|
366 | RenderSystem
|
---|
367 | */
|
---|
368 | void _setRasterisationMode(SceneDetailLevel level);
|
---|
369 | /** See
|
---|
370 | RenderSystem
|
---|
371 | */
|
---|
372 | void setStencilCheckEnabled(bool enabled);
|
---|
373 | /** See
|
---|
374 | RenderSystem
|
---|
375 | */
|
---|
376 | void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
|
---|
377 | uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
|
---|
378 | StencilOperation stencilFailOp = SOP_KEEP,
|
---|
379 | StencilOperation depthFailOp = SOP_KEEP,
|
---|
380 | StencilOperation passOp = SOP_KEEP,
|
---|
381 | bool twoSidedOperation = false);
|
---|
382 | void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
|
---|
383 | /** See
|
---|
384 | RenderSystem
|
---|
385 | */
|
---|
386 | void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
|
---|
387 | /** See
|
---|
388 | RenderSystem
|
---|
389 | */
|
---|
390 | void setVertexDeclaration(VertexDeclaration* decl);
|
---|
391 | /** See
|
---|
392 | RenderSystem
|
---|
393 | */
|
---|
394 | void setVertexBufferBinding(VertexBufferBinding* binding);
|
---|
395 | /** See
|
---|
396 | RenderSystem
|
---|
397 | */
|
---|
398 | void setNormaliseNormals(bool normalise);
|
---|
399 | /** See
|
---|
400 | RenderSystem
|
---|
401 | */
|
---|
402 | void bindGpuProgram(GpuProgram* prg) { /* do nothing */}
|
---|
403 | /** See
|
---|
404 | RenderSystem
|
---|
405 | */
|
---|
406 | void unbindGpuProgram(GpuProgramType gptype){ /* do nothing */}
|
---|
407 | /** See
|
---|
408 | RenderSystem
|
---|
409 | */
|
---|
410 | void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) { /* do nothing */}
|
---|
411 | /** See
|
---|
412 | RenderSystem
|
---|
413 | */
|
---|
414 | void setClipPlanes(const PlaneList& clipPlanes);
|
---|
415 | /** See
|
---|
416 | RenderSystem
|
---|
417 | */
|
---|
418 | void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600)
|
---|
419 | { /* do nothing, d3d7 does not support scissor rect */ }
|
---|
420 | /** See
|
---|
421 | RenderSystem
|
---|
422 | */
|
---|
423 | void clearFrameBuffer(unsigned int buffers,
|
---|
424 | const ColourValue& colour = ColourValue::Black,
|
---|
425 | Real depth = 1.0f, unsigned short stencil = 0);
|
---|
426 |
|
---|
427 | void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
|
---|
428 | void enableClipPlane (ushort index, bool enable);
|
---|
429 | /** See
|
---|
430 | RenderSystem
|
---|
431 | */
|
---|
432 | HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
|
---|
433 | Real getHorizontalTexelOffset(void);
|
---|
434 | Real getVerticalTexelOffset(void);
|
---|
435 | Real getMinimumDepthInputValue(void);
|
---|
436 | Real getMaximumDepthInputValue(void);
|
---|
437 | // ----------------------------------
|
---|
438 | // End Overridden members
|
---|
439 | // ----------------------------------
|
---|
440 | };
|
---|
441 | }
|
---|
442 | #endif
|
---|
443 |
|
---|