#ifndef __KRenderDevice_H__ #define __KRenderDevice_H__ #include #include "K3DTypes.h" enum K3DFORMAT { K3DFMT_UNKNOWN = 0, K3DFMT_R8G8B8 = 20, K3DFMT_A8R8G8B8 = 21, K3DFMT_X8R8G8B8 = 22, K3DFMT_R5G6B5 = 23, K3DFMT_X1R5G5B5 = 24, K3DFMT_A1R5G5B5 = 25, K3DFMT_A4R4G4B4 = 26, K3DFMT_R3G3B2 = 27, K3DFMT_A8 = 28, K3DFMT_A8R3G3B2 = 29, K3DFMT_X4R4G4B4 = 30, K3DFMT_A2B10G10R10 = 31, K3DFMT_G16R16 = 34, K3DFMT_A8P8 = 40, K3DFMT_P8 = 41, K3DFMT_L8 = 50, K3DFMT_A8L8 = 51, K3DFMT_A4L4 = 52, K3DFMT_V8U8 = 60, K3DFMT_L6V5U5 = 61, K3DFMT_X8L8V8U8 = 62, K3DFMT_Q8W8V8U8 = 63, K3DFMT_V16U16 = 64, K3DFMT_W11V11U10 = 65, K3DFMT_A2W10V10U10 = 67, K3DFMT_UYVY = MAKEFOURCC('U', 'Y', 'V', 'Y'), K3DFMT_YUY2 = MAKEFOURCC('Y', 'U', 'Y', '2'), K3DFMT_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'), K3DFMT_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'), K3DFMT_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'), K3DFMT_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'), K3DFMT_DXT5 = MAKEFOURCC('D', 'X', 'T', '5'), K3DFMT_D16_LOCKABLE = 70, K3DFMT_D32 = 71, K3DFMT_D15S1 = 73, K3DFMT_D24S8 = 75, K3DFMT_D16 = 80, K3DFMT_D24X8 = 77, K3DFMT_D24X4S4 = 79, K3DFMT_VERTEXDATA =100, K3DFMT_INDEX16 =101, K3DFMT_INDEX32 =102, K3DFMT_Q16W16V16U16 =110, K3DFMT_MULTI2_ARGB8 = MAKEFOURCC('M','E','T','1'), // Floating point surface formats // s10e5 formats (16-bits per channel) K3DFMT_R16F = 111, K3DFMT_G16R16F = 112, K3DFMT_A16B16G16R16F = 113, // IEEE s23e8 formats (32-bits per channel) K3DFMT_R32F = 114, K3DFMT_G32R32F = 115, K3DFMT_A32B32G32R32F = 116, K3DFMT_CxV8U8 = 117, K3DFMT_FORCE_DWORD =0x7fffffff }; enum KPOOL { KPOOL_DEFAULT = 0, KPOOL_MANAGED = 1, KPOOL_SYSTEMMEM = 2, KPOOL_SCRATCH = 3, KPOOL_FORCE_DWORD = 0x7fffffff }; enum KUSAGE { KUSAGE_RENDERTARGET = 0x00000001L, KUSAGE_DEPTHSTENCIL = 0x00000002L, KUSAGE_WRITEONLY = 0x00000008L, KUSAGE_SOFTWAREPROCESSING = 0x00000010L, KUSAGE_DONOTCLIP = 0x00000020L, KUSAGE_POINTS = 0x00000040L, KUSAGE_RTPATCHES = 0x00000080L, KUSAGE_NPATCHES = 0x00000100L, KUSAGE_DYNAMIC = 0x00000200L, KUSAGE_FORCE_DWORD = 0x7fffffff }; enum K3DVERTEXFORMAT { K3DFVF_POSITION_MASK = 0x00e, K3DFVF_XYZ = 0x002, K3DFVF_XYZRHW = 0x004, K3DFVF_XYZB1 = 0x006, K3DFVF_XYZB2 = 0x008, K3DFVF_XYZB3 = 0x00a, K3DFVF_XYZB4 = 0x00c, K3DFVF_XYZB5 = 0x00e, K3DFVF_NORMAL = 0x010, K3DFVF_PSIZE = 0x020, K3DFVF_DIFFUSE = 0x040, K3DFVF_SPECULAR = 0x080, K3DFVF_TEXCOUNT_MASK = 0xf00, K3DFVF_TEXCOUNT_SHIFT = 8, K3DFVF_TEX0 = 0x000, K3DFVF_TEX1 = 0x100, K3DFVF_TEX2 = 0x200, K3DFVF_TEX3 = 0x300, K3DFVF_TEX4 = 0x400, K3DFVF_TEX5 = 0x500, K3DFVF_TEX6 = 0x600, K3DFVF_TEX7 = 0x700, K3DFVF_TEX8 = 0x800, K3DFVF_LASTBETA_UBYTE4 = 0x1000, }; enum K3DIMAGE_FILEFORMAT { K3DIFF_BMP = 0, K3DIFF_JPG = 1, K3DIFF_TGA = 2, K3DIFF_PNG = 3, K3DIFF_DDS = 4, K3DIFF_PPM = 5, K3DIFF_DIB = 6, K3DIFF_HDR = 7, K3DIFF_PFM = 8, K3DIFF_FORCE_DWORD = 0x7fffffff }; struct K3DTexel { K3DTexel() {} K3DTexel( float _u, float _v ) { u = _u; v = _v; } float u, v; }; #pragma pack(push, 1) const DWORD K3DFVF_UNLITVERTEX = (K3DFVF_XYZ | K3DFVF_NORMAL | K3DFVF_DIFFUSE | K3DFVF_TEX1); struct K3DUNLITVERTEX { K3DVertex pos; K3DVector normal; KColor diffuse; K3DTexel texel; }; const DWORD K3DFVF_UNLITTEX2VERTEX = (K3DFVF_XYZ | K3DFVF_NORMAL | K3DFVF_DIFFUSE | K3DFVF_TEX2); struct K3DUNLITTEX2VERTEX { K3DVertex pos; K3DVector normal; KColor diffuse; K3DTexel texel; K3DTexel texel2; }; const DWORD K3DFVF_UNLITTEX3VERTEX = (K3DFVF_XYZ | K3DFVF_NORMAL | K3DFVF_DIFFUSE | K3DFVF_TEX3); struct K3DUNLITTEX3VERTEX { K3DVertex pos; K3DVector normal; KColor diffuse; K3DTexel texel; K3DTexel texel2; K3DTexel texel3; }; const DWORD K3DFVF_LITVERTEX = (K3DFVF_XYZ | K3DFVF_DIFFUSE | K3DFVF_SPECULAR | K3DFVF_TEX1 ); struct K3DLITVERTEX { K3DVertex pos; KColor diffuse; KColor specular; K3DTexel texel; }; const DWORD K3DFVF_LITTEX2VERTEX = (K3DFVF_XYZ | K3DFVF_DIFFUSE | K3DFVF_SPECULAR | K3DFVF_TEX2 ); struct K3DLITTEX2VERTEX { K3DVertex pos; KColor diffuse; KColor specular; K3DTexel texel; K3DTexel texel2; }; const DWORD K3DFVF_SPRITE = (K3DFVF_XYZ | K3DFVF_DIFFUSE | K3DFVF_TEX1); struct K3DSPRITEVERTEX { K3DVertex pos; KColor diffuse; K3DTexel texel; }; const DWORD K3DFVF_TERRAIN = (K3DFVF_XYZ | K3DFVF_NORMAL | K3DFVF_DIFFUSE); struct K3DTERRAINVERTEX { K3DVertex pos; K3DVector normal; KColor diffuse; }; /*const DWORD K3DFVF_TERRAIN2 = (K3DFVF_XYZ | K3DFVF_NORMAL | K3DFVF_DIFFUSE | K3DFVF_TEX1); struct K3DTERRAIN2VERTEX { K3DVertex pos; K3DVector normal; KColor diffuse; K3DTexel texel4; };*/ const DWORD K3DFVF_TERRAINATTR = (K3DFVF_XYZ | K3DFVF_TEX1); struct K3DTERRAINATTR { K3DVertex pos; K3DTexel texel; }; //const DWORD K3DFVF_BLEND_TEST = (K3DFVF_XYZ | D3DFVF_NORMAL | K3DFVF_TEX1); //const DWORD K3DFVF_BLEND = (K3DFVF_XYZB2 | D3DFVF_LASTBETA_D3DCOLOR | D3DFVF_NORMAL | D3DFVF_TEX1 ); //const DWORD K3DFVF_BLEND = (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX0); struct K3DBLENDEDVERTEX { D3DXVECTOR3 position; ///< vertex position D3DXVECTOR3 normal; ///< vertex normal KColor color; D3DXVECTOR2 texcoord; // DWORD matrixIndices; D3DXVECTOR2 matrixWeights; }; struct K3DBLENDEDBUMPVERTEX { K3DVertex position; ///< vertex position K3DVector normal; ///< vertex normal KColor color; K3DPoint texcoord; // K3DVector4 tangent; // DWORD matrixIndices; K3DPoint matrixWeights; }; const DWORD K3DFVF_SELECTTARGET = ( K3DFVF_XYZ | K3DFVF_NORMAL | K3DFVF_DIFFUSE | K3DFVF_TEX1 ); /// 그림자 const DWORD K3DFVF_SHADOWSQUARE = (K3DFVF_XYZRHW | K3DFVF_DIFFUSE); struct K3DSHADOWSQUARE { D3DXVECTOR4 p; D3DCOLOR color; }; /// 물, 구름... const DWORD VERTEX_WATER = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; /// [sonador] vertex structure for cloud struct K3DVERTEX_CLOUD { K3DVector position; K3DVector normal; KColor color; K3DPoint texcoord0; /*K3DPoint texcoord1;*/ }; struct K3DVERTEX_WATER { K3DVector p; K3DVector normal; DWORD color; FLOAT tu, tv; FLOAT tu2, tv2; }; struct K3DINDEXED_WATER { WORD a,b,c; }; //const DWORD VERTEX_H_WATER = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX2; //const DWORD VERTEX_H_WATER = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2; const DWORD VERTEX_H_WATER = D3DFVF_XYZW | D3DFVF_DIFFUSE | D3DFVF_TEX2; //const DWORD VERTEX_H_WATER = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX2; //const DWORD VERTEX_H_WATER = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX3; struct K3DVERTEX_H_WATER { K3DVector4 p; KColor color; // K3DVector normal; FLOAT tu, tv; FLOAT tu2, tv2; }; /// 렌즈 플레어 const DWORD VERTEX_LENS = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1; struct K3DVERTEX_LENS { D3DXVECTOR3 p; float rhw; DWORD color; FLOAT tu, tv; }; /// Round Shadow const DWORD VERTEX_SHADOW = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; struct K3DVERTEX_SHADOW { D3DXVECTOR3 p; DWORD color; FLOAT tu, tv; }; #pragma pack(pop) // matrix declaration #define MATRIX_WORLD _T("world_matrix") #define MATRIX_VIEW _T("view_matrix") #define MATRIX_PROJECTION _T("proj_matrix") #define MATRIX_WORLDVIEW _T("world_view_matrix") #define MATRIX_VIEWPROJECTION _T("view_proj_matrix") #define MATRIX_WORLDVIEWPROJECTION _T("world_view_proj_matrix") #define MATRIX_VIEWPROJECTION_SB _T("view_proj_matrix_sb") // constant declaration #define CONSTANT_LIGHTAMBIENT _T("Light_ambient") #define CONSTANT_LIGHTDIFFUSE _T("Light_diffuse") #define CONSTANT_LIGHTSPECULAR _T("Light_specular") #define CONSTANT_LIGHTPOSITION _T("Light_position") #define CONSTANT_CAMERAPOSITION _T("Camera_position") #define CONSTANT_LIGHTDIRECTION _T("Light_direction") #define CONSTANT_HALFWAY _T("Light_halfway") #define CONSTANT_DISTANCEFOGSTART _T("fFogDistStart") #define CONSTANT_DISTANCEFOGEND _T("fFogDistEnd") #define CONSTANT_HEIGHTFOGSTART _T("fFogHeightStart") #define CONSTANT_HEIGHTFOGEND _T("fFogHeightEnd") #define CONSTANT_UVANIMATION _T("fUVAnimation") #define CONSTANT_VISIBILITY _T("fVisibility") #define CONSTANT_TERRAINTEXTUREIBH _T("fTerrainTextureInterpolationByHeight") #define CONSTANT_TERRAINTEXTURECENTER _T("fTerrainTextureCenter") #define CONSTANT_TERRAINTEXTURECENTERDUSK _T("fTerrainTextureCenterDusk") #define CONSTANT_TERRAIN1STTEXTURESCALE _T("fTerrain1stTextureScale") #define CONSTANT_TERRAIN2NDTEXTURESCALE _T("fTerrain2ndTextureScale") #define CONSTANT_TERRAIN3THTEXTURESCALE _T("fTerrain3thTextureScale") #define CONSTANT_TERRAIN4THTEXTURESCALE _T("fTerrain4thTextureScale") #define CONSTANT_TERRAINMODTEXTURESCALE _T("fTerrainModTextureScale") #define CONSTANT_CLOUDSPREADCENTER _T("CloudSpread_Center") #define CONSTANT_CLOUDCORNERDISTANCE _T("CloudSpread_CornerDistance") #define CONSTANT_CLOUDBALANCEHEIGHT _T("CloudSpread_BalanceHeight") #define CONSTANT_SKYMAX_HEIGHT _T("fSky_Max_height") #define CONSTANT_SKYMID_HEIGHT _T("fSky_Mid_height") #define CONSTANT_SKYMIN_HEIGHT _T("fSky_Min_height") #define CONSTANT_SKYCOLORBALANCE_TOP _T("Sky_Light_High") #define CONSTANT_SKYCOLORBALANCE_MID _T("Sky_Light_Mid") #define CONSTANT_SKYCOLORBALANCE_BOTTOM _T("Sky_Light_Low") #define CONSTANT_BLUR_SAMPLEOFFSET _T( "g_vBlurSampleOffset" ) #define CONSTANT_BLUR_SAMPLEWEIGHT _T( "g_fBlurSampleWeight" ) #define CONSTANT_HDR_BLURMIXRATIO _T( "g_fBlurMixRatio" ) #define CONSTANT_HDR_EXPOSURE _T( "g_fSceneExposure" ) #define CONSTANT_HDR_GAMMA _T( "g_fSceneGamma" ) //#define CONSTANT_GLOW_SAMPLEOFFSET _T("g_avGlowSampleOffsets") //#define CONSTANT_GLOW_SAMPLEWEIGHT _T("g_avGlowSampleWeights") //#define CONSTANT_GLOW_COLORDISTORT _T("glow_color_distort") #define CONSTANT_LOCALCOORD_OFFSET _T("LocalCoord_Offset") #define CONSTANT_SELFSHADOW_AMBIENT_FACTOR _T("fSelfShadowAmbientFactor") #define CONSTANT_TERRAIN_SPECULAR_FACTOR _T("fTerrainSpecularFactor") #define CONSTANT_AMBIENT_FACTOR _T("fAmbientFactor") #define CONSTANT_DIFFUSE_FACTOR _T("fDiffuseFactor") #define CONSTANT_SPECULAR_FACTOR _T("fSpecularFactor") #define CONSTANT_SELECT_TARGET_MATRIX _T("select_target_matrix") #define CONSTANT_SKIN_DIFFUSE _T("skin_diffuse") #define CONSTANT_WEATHER_AREA_POSITION _T("WeatherAreaPosition") #define CONSTANT_WEATHER_AREA_VELOCITY _T("WeatherAreaVelocity") #define CONSTANT_SELECT_COLOR _T("selectColor") #define CONSTANT_SELECT_TEX_INV_SIZE _T("selectTexInvSize") /// vertex declaration list enum { VTXDECLARATION_SKINMESH = 0, VTXDECLARATION_BUMPSKINMESH, VTXDECLARATION_OBJECTMESH, VTXDECLARATION_TERRAIN, VTXDECLARATION_WATER, VTXDECLARATION_CLOUD, ///< [sonador] vertex declaration for cloud object VTXDECLARATION_WEATHER, VTXDECLARATION_ALPHATEX, ///< Alpha+texture (+mesh blend) VTXDECLARATION_ENVMAP, VTXDECLARATION_MAX, }; /// technique list enum { TECHNIQUE_SKINMESH = 0, TECHNIQUE_SKINMESH_NOUVANIIN2NDTEX, TECHNIQUE_SKINMESH_SPECULAR, TECHNIQUE_SKINMESH_BUMP_SPECULAR, TECHNIQUE_OBJECTMESH, TECHNIQUE_OBJECTMESH_LIGHTMAP, TECHNIQUE_TERRAIN, TECHNIQUE_TERRAIN_1STPASS, TECHNIQUE_TERRAIN_2NDPASS, TECHNIQUE_TERRAIN_3RDPASS, TECHNIQUE_TERRAIN_4THPASS, TECHNIQUE_TERRAINSHADOW, TECHNIQUE_SKYBOX, TECHNIQUE_CLOUDSPREAD, TECHNIQUE_WEATHER, TECHNIQUE_SHADOWBUFFER, TECHNIQUE_BLURSCREEN, TECHNIQUE_TONEMAPPING, TECHNIQUE_WATER_SPECULAR, TECHNIQUE_SKINMESH_BUMP_SPECULAR_SELFSHADOW, TECHNIQUE_HQWATER, TECHNIQUE_ALPHATEX, TECHNIQUE_ALPHATEX_EDGEENHANCE, TECHNIQUE_ALPHATEX_EDGEENHANCE_BLEND, TECHNIQUE_ENVMAP, TECHNIQUE_TERRAIN_LIGHTMAP, TECHNIQUE_SELECT_TARGET_FX, TECHNIQUE_OUTLINE, TECHNIQUE_OUTLINE_BLEND, TECHNIQUE_NO_TEX, TECHNIQUE_MAX, }; #define MAX_TECHNIQUES 32 #define MAX_RENDERSTATE_BLOCK 100 #define MAX_TEXTURE_STAGE 8 class KPrimitive; class KResource; class K3DVertexBuffer; class K3DIndexBuffer; class K3DTexture; class K3DRenderTarget; class K3DRenderTargetCube; class KFXEffect; #pragma pack( push, 1 ) class K3DMaterial { public: enum { MBM_DEFAULT = 0, MBM_ALPHABLENDTWOPASS, MBM_ALPHABLEND, MBM_ALPHABLEND_NOALPHAUVANI, MBM_ALPHABLEND_NOCOLORUVANI, MBM_BILLBOARD, MBM_SELECT_FX, MBM_LQ_WATER, MBM_HQ_WATER, MBM_CIRCLE_FX, MBM_ALPHATEX, MBM_ALPHATEX_EDGEENHANCE, ///< Alpha-texture without mesh blending MBM_ALPHATEX_EDGEENHANCE_BLEND, ///< Alpha-texture with mesh blending MBM_ALPHATEX_EDGEENHANCE_ADD, MBM_ALPHATEX_EDGEENHANCE_BLEND_ADD, MBM_ENVMAP, MBM_ADDITIVE, MBM_ADDITIVE_NOALPHAUVANI, MBM_ADDITIVE_NOCOLORUVANI, MBM_ADDTIVE_BILLBOARD, MBM_MAX, }; K3DMaterial() { SetDiffuse( K3DColor(1.f,1.f,1.f,1.f) ); SetAmbient( K3DColor(1.f,1.f,1.f,1.f) ); SetSpecular( K3DColor(1.0f,1.0f,1.0f,1.0f) ); Emissive.r = Emissive.g = Emissive.b = Emissive.a = .0f; SetSpecularPower(20); } K3DMaterial( const K3DMaterial &mtl ) { Diffuse = mtl.Diffuse; Ambient = mtl.Ambient; Specular = mtl.Specular; Emissive = mtl.Emissive; Power = mtl.Power; } void SetDiffuse( const K3DColor &diffuse ) { Diffuse = diffuse; } void SetAmbient( const K3DColor &ambient ) { Ambient = ambient; } void SetSpecular( const K3DColor &specular ) { Specular = specular; } void SetEmissive( const K3DColor &emissive ) { Emissive = emissive; } void SetSpecularPower( float pow ) { Power = pow; } void Modulate( float rfac, float gfac, float bfac, float afac ) { Ambient.r *= rfac; Ambient.g *= gfac; Ambient.b *= bfac; Ambient.a *= afac; Diffuse.r *= rfac; Diffuse.g *= gfac; Diffuse.b *= bfac; Diffuse.a *= afac; } void Modulate( const K3DMaterial *mtl ) { Ambient.r *= mtl->Ambient.r; Ambient.g *= mtl->Ambient.g; Ambient.b *= mtl->Ambient.b; Ambient.a *= mtl->Ambient.a; Diffuse.r *= mtl->Diffuse.r; Diffuse.g *= mtl->Diffuse.g; Diffuse.b *= mtl->Diffuse.b; Diffuse.a *= mtl->Diffuse.a; } float GetTransparency() { return Diffuse.a; } void SetTransparency( float vis ) { Diffuse.a = vis; } void Copy( K3DMaterial *mtl ) { mtl->Diffuse = Diffuse; mtl->Ambient = Ambient; mtl->Specular = Specular; mtl->Emissive = Emissive; mtl->Power = Power; } K3DColor Diffuse; ///< Diffuse color RGBA K3DColor Ambient; ///< Ambient color RGB K3DColor Specular; ///< Specular 'shininess' K3DColor Emissive; ///< Emissive color RGB float Power; ///< Sharpness if specular highlight }; struct K3DLight { K3DLight() { memset( this, 0, sizeof(*this) ); } K3DLight( K3DColor _diffuse, K3DColor _specular, K3DColor _ambient, K3DVector _direction ) { memset( this, 0, sizeof(*this) ); type = LT_DIRECTIONAL; diffuse = _diffuse; specular = _specular; ambient = _ambient; direction = _direction; } K3DLight( K3DColor _diffuse, K3DColor _specular, K3DColor _ambient, const K3DVertex& _position, float _range, float _attenuation0, float _attenuation1, float _attenuation2 ) { memset( this, 0, sizeof(*this) ); type = LT_POINT; diffuse = _diffuse; specular = _specular; ambient = _ambient; position = _position; range = _range; attenuation0 = _attenuation0, attenuation1 = _attenuation1, attenuation2 = _attenuation2; } K3DLight( K3DColor _diffuse, K3DColor _specular, K3DColor _ambient, const K3DVertex& _position, float _range, float _falloff, float _theta, float _phi, float _attenuation0, float _attenuation1, float _attenuation2 ) { memset( this, 0, sizeof(*this) ); type = LT_SPOT; diffuse = _diffuse; specular = _specular; ambient = _ambient; position = _position; range = _range; falloff = _falloff, theta = _theta, phi = _phi; attenuation0 = _attenuation0, attenuation1 = _attenuation1, attenuation2 = _attenuation2; } enum { LT_POINT = 1, LT_SPOT = 2, LT_DIRECTIONAL = 3 }; int type; K3DColor diffuse; K3DColor specular; K3DColor ambient; K3DVertex position; K3DVector direction; float range; float attenuation0; float attenuation1; float attenuation2; float falloff; float theta; float phi; }; #pragma pack( pop ) /// interface object class KRenderDevice { public: KRenderDevice() {} virtual ~KRenderDevice() {} virtual HRESULT Render() = 0; }; class K3DRenderDevice : public KRenderDevice { public: K3DRenderDevice() {} virtual ~K3DRenderDevice() {} enum DEVTYPE{ KDEVTYPE_HARDWARE_VTX_PROCESSING, KDEVTYPE_SOFTWARE_VTX_PROCESSING, KDEVTYPE_SOFTWARE_RENDER, }; DEVTYPE GetDevType() { return m_devType; } virtual void ShowCursor( BOOL bShow ) = 0; virtual void SetCursor( K3DTexture *cursor, DWORD dwHotSpotX, DWORD dwHotSpotY ) = 0; virtual void SetCursorPos( int x, int y ) = 0; virtual KFXEffect* CreateFXEffect(KStream& stream) = 0; virtual HRESULT TestCooperativeLevel() = 0; // Vertex Buffer virtual K3DVertexBuffer* CreateVertexBuffer( DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* CreateVertexBufferBlend( DWORD stride, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* CreateVertexBufferSpeedTree( DWORD stride, DWORD Usage, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* CreateVertexBufferSpeedGrass( DWORD stride, DWORD Usage, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* CreateVertexBufferUsePoolDefault( DWORD stride, DWORD vertexformat, DWORD count, DWORD Usage ) = 0; // Vertex Buffer Array virtual bool CreateVertexBufferBlendArray( DWORD array_count, DWORD stride, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* GetFreeVertexBufferBlend( int &nIndex ) = 0; virtual int ReleaseVertexBufferBlend( int nIndex ) = 0; /** "소->대" 는 배열크기가 늘어 나나, "대->소"로 변경시에는 기존 Size를 유지 한다. 어떤 버텍스가 삭제 될지 알 수가 없는 문제때문. */ virtual bool ResizeVertexBufferBlendArray( DWORD array_count, DWORD stride, DWORD vertexformat, DWORD count ) = 0; // Recycle VertexBuffer virtual void AddRecycleVertexBuffer( K3DVertexBuffer* pVtxBuf, DWORD vtxformat, DWORD usage, DWORD stride, DWORD count ) = 0; virtual K3DVertexBuffer* GetRecycleVertexBuffer( DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* GetRecycleVertexBufferBlend( DWORD stride, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* GetRecycleVertexBufferSpeedTree( DWORD stride, DWORD Usage, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* GetRecycleVertexBufferSpeedGrass( DWORD stride, DWORD Usage, DWORD vertexformat, DWORD count ) = 0; virtual K3DVertexBuffer* GetRecycleVertexBufferUsePoolDefault( DWORD stride, DWORD vertexformat, DWORD count, DWORD Usage ) = 0; virtual void AddLostVertexBuffer( K3DVertexBuffer* pVtxBuf ) = 0; virtual void RemoveLostVertexBuffer( K3DVertexBuffer* pVtxBuf ) = 0; // Index Buffer virtual K3DIndexBuffer *CreateIndexBuffer( DWORD count, bool use32bit = false ) = 0; virtual void AddLostIndexBuffer( K3DIndexBuffer* pIdxBuf ) = 0; virtual void RemoveLostIndexBuffer( K3DIndexBuffer* pIdxBuf ) = 0; // Texture virtual K3DTexture *CreateTexture( KStream &stream, int nQuality ) = 0; virtual K3DTexture *CreateTexture( int width, int height, K3DFORMAT format, D3DPOOL pool = D3DPOOL_MANAGED, int nLevel = 1 ) = 0; virtual K3DTexture *CreateTexture( int width, int height, DWORD usage, K3DFORMAT format, D3DPOOL pool = D3DPOOL_DEFAULT ) = 0; //virtual K3DRenderTarget *CreateRenderTarget( int width, int height, UINT nLevels, K3DFORMAT format, bool bUseDepth ) = 0; virtual K3DRenderTarget *CreateRenderTarget( int width, int height, UINT nLevels, K3DFORMAT format, DWORD dwDepthUsage, bool bDepth16Bit=false ) = 0; virtual K3DRenderTargetCube *CreateRenderCube( int size, UINT nLevels, K3DFORMAT format, DWORD dwDepthUsage ) = 0; virtual HRESULT UpdateSurface( K3DTexture * pSrc, const RECT * pSrcRect, K3DTexture * pDst, const POINT * pDstPoint ) = 0; virtual HRESULT StretchRect( K3DTexture * pSrc, const RECT * pSrcRect, K3DTexture * pDst, const RECT * pDstRect ) = 0; virtual K3DFORMAT GetCurrentDisplayModeFormat() = 0; virtual void AddLostTexture( K3DTexture * tex ) = 0; virtual void RemoveTexture( K3DTexture * tex ) = 0; virtual K3DTexture *SetTexture( int stage, K3DTexture *tex ) { K3DTexture *oldtex = m_stageTextures[stage]; m_stageTextures[stage] = tex; return oldtex; } K3DTexture *GetTexture( int stage ) { return m_stageTextures[stage]; } virtual bool SetRenderTarget( K3DRenderTarget *target ) = 0; virtual bool SetRenderTarget( int nLevel, K3DRenderTarget *target ) = 0; virtual void SaveRenderTargetSurface( K3DIMAGE_FILEFORMAT nImageFileFormat = K3DIFF_BMP ) {}; virtual void GetVGAMem( DWORD & dwFree, DWORD & dwTotal ) = 0; /// 큐브 맵용 virtual bool SetRenderTargetCube( K3DRenderTargetCube* pTargetCube, int nCubeFace, int nLevel = 0 ) = 0; // // Light // virtual void EnableLightEffect( bool enable ) { m_bEnableLight = enable; } bool GetEnableLightEffect() { return m_bEnableLight; } virtual void SetLight( int index, const K3DLight *light ) { memcpy( &m_arLights[index], light, sizeof(m_arLights[index]) ); } K3DLight *GetLight( int index ) { return &m_arLights[index]; } virtual void SetLightEnable( int index, bool enable ) { m_bEnLight[index] = enable; } bool GetLightEnable( int index ) { return m_bEnLight[index]; } virtual void SetBright(float bright) { m_fBright = bright; } virtual void SetContrast(int contrast) { m_nContrast = contrast; } virtual void SetGammaRange( const KColor &low, const KColor &high, int contrast = 1, float bright = 1.0f ) { m_lowGamma = low; m_highGamma = high; m_nContrast = contrast; m_fBright = bright; } void GetGammaRange( KColor &low, KColor &high ) { low = m_lowGamma; high = m_highGamma; } int GetContrast() { return m_nContrast; } void ResetGammaRange() { SetGammaRange( KColor(0), KColor(255,255,255,255), 1 , 1.0f); } virtual void SetDefaultGammaRange(){ } enum { RS_DEFAULT, RS_DEFAULT_NORMAL, RS_DEFAULT_SPECULAR, RS_DEFAULT_NORMAL_SPECULAR, RS_NOLIGHT_VTXCOLOR, RS_BILLBOARD, RS_SPRITE, #ifdef _KUI_INVALIDATION // { [sonador] RS_SPRITE_RENDERTARGET, // } #endif RS_TEXT_LAYER, RS_TRANSPARENT_MESH, RS_TRANSPARENT_MESH_NOALPHAUVANI, RS_TRANSPARENT_MESH_NOCOLORUVANI, RS_ALPHABLEND_1STPASS, RS_ALPHABLEND_2NDPASS, RS_MODULATE2X, RS_OBJECTSHADOW_SPECULAR2X, RS_OBJECTSHADOW_LIGHTMAP, RS_ADDITIVE_MESH, RS_ADDITIVE_MESH_NOALPHAUVANI, RS_ADDITIVE_MESH_NOCOLORUVANI, RS_ADDITIVE_MESH_WITHOUT_DEFAULT, RS_ADDITIVE_PARTICLE, RS_TERRAIN_LIGHTMAP_ADDITIVE, RS_TERRAIN_LIGHTMAP_MODULATE, RS_VOLUME_FOG, RS_TERRAIN_SINGLETILE, RS_TERRAIN_3TILE_LERP, RS_TERRAIN_3TILE_WITH_SHADOW, RS_TERRAIN_3TILE_WITH_LIGHTMAP, RS_TERRAIN_FOR_2SAMPLER_1STPASS, RS_TERRAIN_FOR_2SAMPLER_2NDPASS, RS_TERRAIN_FOR_2SAMPLER_3RDPASS, RS_TERRAIN_FOR_2SAMPLER_4THPASS, RS_TERRAIN_ATTRIBUTE, RS_TERRAIN_PROP, RS_WATER, RS_UVWRAP, RS_LENSFLARE, RS_CLOUD, RS_WEATHER, ///< [sonador][2007.03.23] render state for weather RS_SHADOW_PROJECTION, RS_SHADOW_MESH, RS_NO_MIPMAP, RS_SPEED_TREE, RS_SPEED_TREE_NONALPHABLEND, RS_SPEED_TREE_ALPHABLEND, RS_SPEED_GRASS, RS_DISABLE_UVTRANSFORM, ///< 임시 - 사용하고 있음, UV 메트릭스 Disable 시킴 RS_SHADOW_MAP, ///< 쉐도우 맵 RS_JITTER, ///< 쉐도우 맵에서 사용 RS_MESH_SPECULAR, ///< 스페큘러 메쉬 RS_HDR, ///< HDR Rendering RS_SELECT_EFFECT, ///< 선택 이펙트 RS_LQWATER, ///< 저사양 물 RS_LOWSHADOW, ///< 저사양 그림자 RS_ALPHATEX, ///< 강화 이펙트 RS_ALPHATEX_ADD, ///< 강화 이펙트 Additive RS_NO_TEX, /// 오브젝트를 깊이 체크 없이 null texture로 렌더링 할 때 쓰임 RS_SELECT_OUTLINE_MESH, RS_MTE, ///MTE RS_MTE_S1, //MTE stage1 RS_ALPHATEST, }; virtual bool SetRenderState( DWORD stateindex ) { m_idxCurRS = stateindex; return true; } DWORD GetCurRenderState() { return m_idxCurRS; } /// transform stage enum { TS_VIEW = 2, TS_PROJECTION = 3, TS_WORLD1 = 4, TS_WORLD2 = 5, TS_WORLD3 = 6, TS_TEXTURE0 = 16, TS_TEXTURE1 = 17, TS_TEXTURE2 = 18, TS_TEXTURE3 = 19, TS_TEXTURE4 = 20, TS_TEXTURE5 = 21, TS_TEXTURE6 = 22, TS_TEXTURE7 = 23, TS_WORLD = 31, TS_STAGE_MAX = 32, }; virtual void SetTransformIdentity( int stage ) { K3DMatrixIdentity( m_arTransformStages[stage] ); } virtual void SetTransform( int stage, const K3DMatrix *mat, int count = 1 ) { m_arTransformStages[stage] = *mat; } K3DMatrix *GetTransform( int stage ) { return &m_arTransformStages[stage]; } /// material virtual void SetMaterial( const K3DMaterial *mat ) { if ( mat ) memcpy( &m_curMaterial, mat, sizeof(m_curMaterial) ); //else m_curMaterial = NULL; } K3DMaterial *GetMaterial() { return &m_curMaterial; } const KSize &GetScreenSize() const { return m_sizeScreen; } // Bump 관련... SetRenderState Block에서는 안되는 것인데.. 다 좋게 하는 방법은? virtual void SetBumpState( K3DMatrix * BumpMat ) = 0; virtual void SetTextureFactor( DWORD dwFactor ) = 0; virtual void SetTextureFactor( const K3DVector &vFactor ) = 0; // Shader virtual void SetTechnique( int nTechniqueIndex ) = 0; virtual void SetVertexShaderConstant( DWORD Register, CONST void* pConstantData, DWORD ConstantCount ) = 0; virtual void SetVertexShaderLight( const K3DLight *light ) = 0; virtual void SetVertexShaderMaterialLight( const K3DMaterial *mat, const K3DLight *light ) = 0; virtual void SetVertexShaderConstant( const TCHAR *dcl, const float *value, DWORD count ) = 0; virtual void SetVertexShaderDefault() = 0; virtual void SetVertexShader(DWORD decl, DWORD vshader) = 0; virtual void SetVertexShaderMatrix(const TCHAR *dcl, const K3DMatrix *mat) = 0; virtual void SetLocalCoordOffset( K3DVector vOffset ) = 0; virtual K3DVector GetLocalCoordOffset() = 0; // // Drawing // virtual void DrawPoints( int vtxFormat, void* vtx, int vtxCount, int vtxStride ) = 0; virtual void DrawLine( int vtxFormat, void* vtx, int vtxStride ) = 0; virtual void DrawTriangle( int vtxFormat, void* vtx, int vtxStride ) = 0; virtual void DrawLines(int vtxFormat, void* vtx, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangles( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangles( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride, const unsigned short* indexBuf, int indexCount ) = 0; virtual void DrawLineStrip(int vtxFormat, void* vtx, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangleFan( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangleFan_VS( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangleStrip( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangleStrip_VS( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride ) = 0; virtual void DrawTriangleVB(const K3DVertexBuffer *vb, int vtxCount=0 ) = 0; virtual void DrawTriangleFanVB(const K3DVertexBuffer *vb) = 0; virtual void DrawTriangleFanVB_VS(const K3DVertexBuffer *vb, UINT nStartVertex = 0, UINT nPrimitiveCount = 0) = 0; virtual void DrawIndexedTriangleFanVB_VS(const K3DVertexBuffer *vb, const K3DIndexBuffer *ib ) = 0; virtual void DrawTriangleStripVB(const K3DVertexBuffer *vb, int vtxCount=0 ) = 0; virtual void DrawTriangleStripVB_VS(const K3DVertexBuffer *vb, int vtxCount=0 ) = 0; virtual void DrawIndexedTriangleVB(const K3DVertexBuffer *vb, const K3DIndexBuffer *ib) = 0; virtual void DrawIndexedTriangleStripVB(const K3DVertexBuffer *vb, const K3DIndexBuffer *ib, UINT nVtxCnt, UINT nPriCnt ) = 0; //Speed Tree virtual void DrawPrimitiveUP( int vtxFormat, void* vtxBuf,int vtxCount, int vtxStride ) = 0; virtual void DrawIndexedPrimitiveUP( int vtxFormat, void* vtxBuf,int vtxCount, int vtxStride, unsigned short* indexBuf, int indexCount ) = 0; virtual void DrawPrimitiveUP_VS( int vtxFormat, void* vtxBuf,int vtxCount, int vtxStride ) = 0; virtual void DrawIndexedPrimitiveUP_VS( int vtxFormat, void* vtxBuf, int vtxCount, int vtxStride, const unsigned short* indexBuf, int indexCount ) = 0; virtual void DrawIndexedPrimitiveUPLine( int vtxFormt, void* vtxBuf, void* vIdxBuf, int vtxCount, int vtxIdxCount, int vtxStride ) = 0; //Vertex Shader 용~ virtual void DrawIndexedTriangleVB_VS(const K3DVertexBuffer *vb, const K3DIndexBuffer *ib, int primcount = 0, int s_framecount = 1) = 0; virtual void SetMatrixArray( CONST D3DXMATRIX* pMatrix, UINT Count ) = 0; //Occlusion Query virtual void* GetQuerry() { return NULL; } virtual bool IsTestOcclusionCulling() { return false; } /// Render to Screen enum { FILL_COLOR = 1, FILL_DEPTH = 2, FILL_STENCIL = 4, }; virtual void Fill( int flags = FILL_COLOR | FILL_DEPTH | FILL_STENCIL ) = 0; virtual HRESULT Render() = 0; virtual void BeginScene() = 0; virtual void EndScene() = 0; enum { BW_ALPHA = 1L<<3, BW_BLUE = 1L<<2, BW_GREEN = 1L<<1, BW_RED = 1L<<0 }; virtual void SetBackBufferWriteEnable ( DWORD stat = BW_RED | BW_GREEN | BW_BLUE ) { m_backBufferWriteEnable = stat; } DWORD GetBackBufferWriteEnable() { return m_backBufferWriteEnable; } virtual void SetDepthBufferWriteEnable ( bool enable ) { m_depthBufferWriteEnable = enable; } bool GetDepthBufferWriteEnable() { return m_depthBufferWriteEnable; } enum { DCM_NONE = 0, DCM_LESS = 1, DCM_LESSEQUAL = 2, DCM_EQUAL = 3, DCM_GREATEREQUAL = 4, DCM_GREATER = 5, DCM_ALWAYS = 6 }; virtual void SetDepthBufferCompareMode( int depthcmp ) { m_depthCompareMode = depthcmp; } int GetDepthBufferCompareMode() { return m_depthCompareMode; } enum { CPM_USER1 = D3DCLIPPLANE0, CPM_USER2 = D3DCLIPPLANE1, CPM_USER3 = D3DCLIPPLANE2, CPM_USER4 = D3DCLIPPLANE3, CPM_USER5 = D3DCLIPPLANE4, CPM_USER6 = D3DCLIPPLANE5, CPM_ALL = CPM_USER1 | CPM_USER2 | CPM_USER3 | CPM_USER4 | CPM_USER5 | CPM_USER6, CPM_NONE = 0 }; virtual void SetClipPlaneMode( DWORD state ) { m_clipPlaneEnabled = state; } virtual void SetClipPlane( DWORD n, const K3DPlane &plane ) { m_clipPlane[n] = plane; } const K3DPlane &GetClipPlane( DWORD n ) { return m_clipPlane[n]; } enum { FOGM_NONE = 0, FOGM_LINEAR = 1, FOGM_HEIGHT = 2, //FOGM_EXP = 2, //FOGM_EXP2 = 3 }; virtual void SetFogColor(KColor fogcolor) { m_fogColor = fogcolor; } KColor GetFogColor() { return m_fogColor; } virtual void SetFogMode(DWORD fogmode, KColor fogcolor, float p1, float p2, float p3, float p4) { m_fogMode = fogmode; m_fogColor = fogcolor; m_fogFactor1 = p1; m_fogFactor2 = p2; m_fogFactor3 = p3; m_fogFactor4 = p4; } void GetFogMode(DWORD &fogmode, KColor &fogcolor, float &p1, float &p2, float &p3, float &p4) { fogmode = m_fogMode; fogcolor = m_fogColor; p1 = m_fogFactor1; p2 = m_fogFactor2; p3 = m_fogFactor3; p4 = m_fogFactor4; } void SetFillColor( const KColor &color ) { m_colorFill = color; } enum { FM_POINT, FM_WIREFRAME, FM_SOLID }; virtual void SetFillMode(DWORD mode) { m_fillmode = mode; } DWORD GetFillMode() { return m_fillmode; } enum { KCM_NONE, KCM_CW, KCM_CCW, }; virtual void SetCullMode(DWORD mode) { m_cullmode = mode; } DWORD GetCullMode() { return m_cullmode; } virtual void SetSceneAmbientLight( const KColor &color ) { m_sceneambient = color; } const KColor &GetSceneAmbientLight() { return m_sceneambient; } virtual void SetViewport( const KViewportStruct &vp ) { m_viewport = vp; } const KViewportStruct &GetViewport() { return m_viewport; } float GetScreenVertexAspect() { return m_fVertexAspect; } void SetCamPos( K3DVector & pos ) { m_Campos = pos; } virtual void SetMipBias( float fBias ) { m_fMipBias = fBias ; } virtual float GetMipBias() { return m_fMipBias; } virtual void SetAlpharef( DWORD dwAlpharef ) { m_dwAlpharef = dwAlpharef; } static void GetSquareSize( const int nX, const int nY, int & nOutX, int & nOutY ) { float fExpX, fExpY; int nExpX, nExpY; float fLog2 = logf( 2.0f ); fExpX = logf( (float)nX - 1 ) / fLog2; fExpY = logf( (float)nY - 1 ) / fLog2; nExpX = ( int ) fExpX + 1; nExpY = ( int ) fExpY + 1; nOutX = 1 << nExpX; nOutY = 1 << nExpY; } virtual void DelReloadVertexList( class K3DVertexBuffer * ) = 0; void SetPrevDeclaration( DWORD decl = VTXDECLARATION_MAX ) { m_dwPrevDeclaration = decl; } void SetPrevTechnique( DWORD tech = TECHNIQUE_MAX ) { m_dwPrevTechnique = tech; } void ResetPrevDeclarationTechnique() { SetPrevDeclaration(); SetPrevTechnique(); } DWORD GetPrevDeclaration() { return m_dwPrevDeclaration; } DWORD GetPrevTechnique() { return m_dwPrevTechnique; } virtual bool VizQueryIssueBegin() { return false; } virtual bool VizQueryIssueEnd() { return true; } protected: DEVTYPE m_devType; bool m_bEnableLight; bool m_bEnLight[8]; K3DLight m_arLights[8]; DWORD m_idxCurRS; K3DMatrix m_arTransformStages[TS_STAGE_MAX]; K3DTexture* m_stageTextures[MAX_TEXTURE_STAGE]; K3DMaterial m_curMaterial; // rendering state DWORD m_backBufferWriteEnable; bool m_depthBufferWriteEnable; int m_depthCompareMode; DWORD m_clipPlaneEnabled; K3DPlane m_clipPlane[6]; DWORD m_dwAlpharef; float m_fMipBias; DWORD m_fogMode; KColor m_fogColor; float m_fogFactor1; float m_fogFactor2; float m_fogFactor3; float m_fogFactor4; DWORD m_fillmode; DWORD m_cullmode; KColor m_textureFactor; KColor m_sceneambient; KColor m_colorFill; KViewportStruct m_viewport; float m_fVertexAspect; KColor m_lowGamma; KColor m_highGamma; int m_nContrast; float m_fBright; KSize m_sizeScreen; K3DVector m_Campos; DWORD m_dwPrevDeclaration; DWORD m_dwPrevTechnique; }; #endif //__KRenderDevice_H__