00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00022
00023
#ifndef __M3DCORE_DEVICE_H__
00024
#define __M3DCORE_DEVICE_H__
00025
00026
#include "../m3dbase.h"
00027
#include "../m3dtypes.h"
00028
00030 class CMuli3DDevice :
public IBase
00031 {
00032
protected:
00033
~CMuli3DDevice();
00034
00035
friend class CMuli3D;
00039
CMuli3DDevice(
class CMuli3D *i_pParent,
00040
const m3ddeviceparameters *i_pDeviceParameters );
00041
00047
result Create();
00048
00049
public:
00050
class CMuli3D *
pGetMuli3D();
00051
00052
const m3ddeviceparameters &
GetDeviceParameters();
00053
00054
00055
00063
result Present(
class CMuli3DRenderTarget *i_pRenderTarget );
00064
00072
result DrawPrimitive(
m3dprimitivetype i_PrimitiveType,
00073
uint32 i_iStartVertex,
uint32 i_iPrimitiveCount );
00074
00085
result DrawIndexedPrimitive(
m3dprimitivetype i_PrimitiveType,
00086
int32 i_iBaseVertexIndex,
uint32 i_iMinIndex,
00087
uint32 i_iNumVertices,
uint32 i_iStartIndex,
uint32 i_iPrimitiveCount );
00088
00095
result DrawDynamicPrimitive(
uint32 i_iStartVertex,
uint32 i_iNumVertices );
00096
00097
00098
00106
result CreateVertexFormat(
class CMuli3DVertexFormat **o_ppVertexFormat,
00107
const m3dvertexelement *i_pVertexDeclaration,
00108
uint32 i_iVertexDeclSize );
00109
00117
result CreateIndexBuffer(
class CMuli3DIndexBuffer **o_ppIndexBuffer,
00118
uint32 i_iLength,
m3dformat i_fmtFormat );
00119
00126
result CreateVertexBuffer(
class CMuli3DVertexBuffer **o_ppVertexBuffer,
00127
uint32 i_iLength );
00128
00137
result CreateSurface(
class CMuli3DSurface **o_ppSurface,
uint32 i_iWidth,
00138
uint32 i_iHeight,
m3dformat i_fmtFormat );
00139
00149
result CreateTexture(
class CMuli3DTexture **o_ppTexture,
uint32 i_iWidth,
00150
uint32 i_iHeight,
uint32 i_iMipLevels,
m3dformat i_fmtFormat );
00151
00160
result CreateCubeTexture(
class CMuli3DCubeTexture **o_ppCubeTexture,
00161
uint32 i_iEdgeLength,
uint32 i_iMipLevels,
m3dformat i_fmtFormat );
00162
00172
result CreateVolume(
class CMuli3DVolume **o_ppVolume,
uint32 i_iWidth,
00173
uint32 i_iHeight,
uint32 i_iDepth,
m3dformat i_fmtFormat );
00174
00185
result CreateVolumeTexture(
class CMuli3DVolumeTexture **o_ppVolumeTexture,
00186
uint32 i_iWidth,
uint32 i_iHeight,
uint32 i_iDepth,
00187
uint32 i_iMipLevels,
m3dformat i_fmtFormat );
00188
00194
result CreateRenderTarget(
class CMuli3DRenderTarget **o_ppVertexFormat );
00195
00196
00202
result SetRenderState(
m3drenderstate i_RenderState,
uint32 i_iValue );
00203
00209
result GetRenderState(
m3drenderstate i_RenderState,
uint32 &o_iValue );
00210
00214
result SetVertexFormat(
class CMuli3DVertexFormat *i_pVertexFormat );
00215
class CMuli3DVertexFormat *
pGetVertexFormat();
00216
00219
void SetPrimitiveAssembler(
class IMuli3DPrimitiveAssembler *i_pPrimitiveAssembler );
00220
class IMuli3DPrimitiveAssembler *
pGetPrimitiveAssembler();
00221
00226
result SetVertexShader(
class IMuli3DVertexShader *i_pVertexShader );
00227
class IMuli3DVertexShader *
pGetVertexShader();
00228
00231
void SetTriangleShader(
class IMuli3DTriangleShader *i_pTriangleShader );
00232
class IMuli3DTriangleShader *
pGetTriangleShader();
00233
00238
result SetPixelShader(
class IMuli3DPixelShader *i_pPixelShader );
00239
class IMuli3DPixelShader *
pGetPixelShader();
00240
00244
result SetIndexBuffer(
class CMuli3DIndexBuffer *i_pIndexBuffer );
00245
class CMuli3DIndexBuffer *
pGetIndexBuffer();
00246
00254
result SetVertexStream(
uint32 i_iStreamNumber,
00255
class CMuli3DVertexBuffer *i_pVertexBuffer,
uint32 i_iOffset,
00256
uint32 i_iStride );
00257
00265
result GetVertexStream(
uint32 i_iStreamNumber,
00266
class CMuli3DVertexBuffer **o_ppVertexBuffer,
uint32 *o_pOffset,
00267
uint32 *o_pStride );
00268
00274
result SetTexture(
uint32 i_iSamplerNumber,
00275
class IMuli3DBaseTexture *i_pTexture );
00276
00282
result GetTexture(
uint32 i_iSamplerNumber,
00283
class IMuli3DBaseTexture **o_ppTexture );
00284
00291
result SetTextureSamplerState(
uint32 i_iSamplerNumber,
00292
m3dtexturesamplerstate i_TextureSamplerState,
uint32 i_iState );
00293
00300
result GetTextureSamplerState(
uint32 i_iSamplerNumber,
00301
m3dtexturesamplerstate i_TextureSamplerState,
uint32 &o_iState );
00302
00313
result SampleTexture( vector4 &o_vColor,
uint32 i_iSamplerNumber,
00314
float32 i_fU,
float32 i_fV,
float32 i_fW,
00315
const vector4 *i_pXGradient,
const vector4 *i_pYGradient );
00316
00319
void SetRenderTarget(
class CMuli3DRenderTarget *i_pRenderTarget );
00320
class CMuli3DRenderTarget *
pGetRenderTarget();
00321
00326
result SetScissorRect(
const m3drect &i_ScissorRect );
00327
m3drect GetScissorRect();
00328
00334
result SetDepthBounds(
float32 i_fMinZ,
float32 i_fMaxZ );
00335
void GetDepthBounds(
float32 &o_fMinZ,
float32 &o_fMaxZ );
00336
00341
result SetClippingPlane(
m3dclippingplanes i_eIndex,
const plane *i_pPlane );
00342
00343
00348
result GetClippingPlane(
m3dclippingplanes i_eIndex, plane &o_plane );
00349
00350
uint32 iGetRenderedPixels();
00351
00352
private:
00353
void SetDefaultRenderStates();
00354
void SetDefaultTextureSamplerStates();
00355
void SetDefaultClippingPlanes();
00356
00361
result PreRender();
00362
00364
void PostRender();
00365
00372
result DecodeVertexStream(
m3dvsinput &o_VertexShaderInput,
00373
uint32 i_iVertex );
00374
00379
result FetchVertex(
m3dvertexcacheentry **io_ppVertex,
uint32 i_iVertex );
00380
00385
void ProcessTriangle(
const m3dvsoutput *i_pVSOutput0,
00386
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00387
00393
void InterpolateVertexShaderInput(
m3dvsinput *o_pVSInput,
00394
const m3dvsinput *i_pVSInputA,
const m3dvsinput *i_pVSInputB,
00395
float32 i_fInterpolation );
00396
00402
void InterpolateVertexShaderOutput(
m3dvsoutput *o_pVSOutput,
00403
const m3dvsoutput *i_pVSOutputA,
const m3dvsoutput *i_pVSOutputB,
00404
float32 i_fInterpolation );
00405
00410
void MultiplyVertexShaderOutputRegisters(
m3dvsoutput *o_pDest,
const m3dvsoutput *i_pSrc,
float32 i_fVal );
00411
00417
void SubdivideTriangle_Simple(
uint32 i_iSubdivisionLevel,
00418
const m3dvsoutput *i_pVSOutput0,
const m3dvsoutput *i_pVSOutput1,
00419
const m3dvsoutput *i_pVSOutput2 );
00420
00426
void SubdivideTriangle_Smooth(
uint32 i_iSubdivisionLevel,
00427
const m3dvsoutput *i_pVSOutput0,
const m3dvsoutput *i_pVSOutput1,
00428
const m3dvsoutput *i_pVSOutput2 );
00429
00434
void SubdivideTriangle_Adaptive(
const m3dvsoutput *i_pVSOutput0,
00435
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00436
00442
void SubdivideTriangle_Adaptive_SubdivideEdges(
uint32 i_iSubdivisionLevel,
00443
const m3dvsoutput *i_pVSOutputEdge0,
const m3dvsoutput *i_pVSOutputEdge1,
00444
const m3dvsoutput *i_pVSOutputCenter );
00445
00451
void SubdivideTriangle_Adaptive_SubdivideInnerPart(
00452
uint32 i_iSubdivisionLevel,
const m3dvsoutput *i_pVSOutput0,
00453
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00454
00461
uint32 iClipToPlane(
uint32 i_iNumVertices,
uint32 i_iStage,
00462
const plane &i_plane,
bool i_bHomogenous );
00463
00468
void DrawTriangle(
const m3dvsoutput *i_pVSOutput0,
00469
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00470
00475
bool bCullTriangle(
const m3dvsoutput *i_pVSOutput0,
00476
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00477
00480
void ProjectVertex(
m3dvsoutput *io_pVSOutput );
00481
00486
void CalculateTriangleGradients(
const m3dvsoutput *i_pVSOutput0,
00487
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00488
00493
void SetVSOutputFromGradient(
m3dvsoutput *o_pVSOutput,
float32 i_fX,
float32 i_fY );
00494
00497
void StepXVSOutputFromGradient(
m3dvsoutput *io_pVSOutput );
00498
00503
void RasterizeTriangle(
const m3dvsoutput *i_pVSOutput0,
00504
const m3dvsoutput *i_pVSOutput1,
const m3dvsoutput *i_pVSOutput2 );
00505
00509
void RasterizeLine(
const m3dvsoutput *i_pVSOutput0,
const m3dvsoutput *i_pVSOutput1 );
00510
00516
void RasterizeScanline_ColorOnly(
uint32 i_iY,
00517
uint32 i_iX,
uint32 i_iX2,
m3dvsoutput *io_pVSOutput );
00518
00524
void RasterizeScanline_ColorOnly_MightKillPixels(
uint32 i_iY,
00525
uint32 i_iX,
uint32 i_iX2,
m3dvsoutput *io_pVSOutput );
00526
00533
void RasterizeScanline_ColorDepth(
uint32 i_iY,
00534
uint32 i_iX,
uint32 i_iX2,
m3dvsoutput *io_pVSOutput );
00535
00540
void DrawPixel_ColorOnly(
uint32 i_iX,
00541
uint32 i_iY,
const m3dvsoutput *i_pVSOutput );
00542
00548
void DrawPixel_ColorDepth(
uint32 i_iX,
00549
uint32 i_iY,
const m3dvsoutput *i_pVSOutput );
00550
00551
private:
00552
class CMuli3D *m_pParent;
00553
m3ddeviceparameters m_DeviceParameters;
00554
class IMuli3DPresentTarget *m_pPresentTarget;
00555
00556
uint32 m_iRenderStates[m3drs_numrenderstates];
00557
00558
class CMuli3DVertexFormat *m_pVertexFormat;
00559
class IMuli3DPrimitiveAssembler *m_pPrimitiveAssembler;
00560
class IMuli3DVertexShader *m_pVertexShader;
00561
class IMuli3DTriangleShader *m_pTriangleShader;
00562
class IMuli3DPixelShader *m_pPixelShader;
00563
class CMuli3DIndexBuffer *m_pIndexBuffer;
00564
00567
struct vertexstream
00568 {
00569
class CMuli3DVertexBuffer *pVertexBuffer;
00570
uint32 iOffset;
00571
uint32 iStride;
00572 } m_VertexStreams[
c_iMaxVertexStreams];
00573
00576
struct texturesampler
00577 {
00578
class IMuli3DBaseTexture *pTexture;
00579
uint32 iTextureSamplerStates[m3dtss_numtexturesamplerstates];
00580
m3dtexsampleinput TextureSampleInput;
00581 } m_TextureSamplers[
c_iMaxTextureSamplers];
00582
00583
class CMuli3DRenderTarget *m_pRenderTarget;
00584
00585
m3drect m_ScissorRect;
00586
00587
struct m3drenderinfo
00588 {
00589
m3dshaderregtype VSInputs[
c_iVertexShaderRegisters];
00590
m3dshaderregtype VSOutputs[
c_iPixelShaderRegisters];
00591
00592
float32 *pFrameData;
00593
uint32 iColorFloats;
00594
uint32 iColorBufferPitch;
00595
bool bColorWrite;
00596
00597
float32 *pDepthData;
00598
uint32 iDepthBufferPitch;
00599
m3dcmpfunc DepthCompare;
00600
bool bDepthWrite;
00601
00602 void (CMuli3DDevice::*fpRasterizeScanline)(
uint32,
uint32,
uint32,
00603
m3dvsoutput * );
00604
00605 void (CMuli3DDevice::*fpDrawPixel)(
uint32,
uint32,
const m3dvsoutput * );
00606
00607
uint32 iRenderedPixels;
00608
00609
m3drect ViewportRect;
00610
00611 plane ClippingPlanes[m3dcp_numplanes];
00612
bool bClippingPlaneEnabled[m3dcp_numplanes];
00613 plane ScissorPlanes[4];
00614
00615 } m_RenderInfo;
00616
00617
m3dtriangleinfo m_TriangleInfo;
00618
00619
uint32 m_iNumValidCacheEntries;
00620
uint32 m_iFetchedVertices;
00621
m3dvertexcacheentry m_VertexCache[
c_iVertexCacheSize];
00622
00623
m3dvsoutput m_ClipVertices[20];
00624
uint32 m_iNextFreeClipVertex;
00625
m3dvsoutput *m_pClipVertices[2][20];
00626 };
00627
00628
#endif // __M3DCORE_DEVICE_H__