1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef D3D8_Direct3DStateBlock8_hpp 16 #define D3D8_Direct3DStateBlock8_hpp 17 18 #include "Unknown.hpp" 19 20 #include <vector> 21 22 #include <d3d8.h> 23 24 namespace D3D8 25 { 26 class Direct3DDevice8; 27 class Direct3DBaseTexture8; 28 class Direct3DVertexBuffer8; 29 class Direct3DIndexBuffer8; 30 31 class Direct3DStateBlock8 : public Unknown 32 { 33 public: 34 Direct3DStateBlock8(Direct3DDevice8 *device, D3DSTATEBLOCKTYPE type); 35 36 ~Direct3DStateBlock8() override; 37 38 // IUnknown methods 39 long __stdcall QueryInterface(const IID &iid, void **object) override; 40 unsigned long __stdcall AddRef() override; 41 unsigned long __stdcall Release() override; 42 43 long __stdcall Apply(); 44 long __stdcall Capture(); 45 long __stdcall GetDevice(IDirect3DDevice8 **device); 46 47 // Internal methods 48 void lightEnable(unsigned long index, int enable); 49 void setClipPlane(unsigned long index, const float *plane); 50 void setCurrentTexturePalette(unsigned int paletteNumber); 51 void setFVF(unsigned long FVF); 52 void setIndices(Direct3DIndexBuffer8 *indexData, unsigned int baseVertexIndex); 53 void setLight(unsigned long index, const D3DLIGHT8 *light); 54 void setMaterial(const D3DMATERIAL8 *material); 55 void setPixelShader(unsigned long shaderHandle); 56 void setPixelShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count); 57 void setRenderState(D3DRENDERSTATETYPE state, unsigned long value); 58 void setScissorRect(const RECT *rect); 59 void setStreamSource(unsigned int stream, Direct3DVertexBuffer8 *data, unsigned int stride); 60 void setTexture(unsigned long stage, Direct3DBaseTexture8 *texture); 61 void setTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value); 62 void setTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix); 63 void setViewport(const D3DVIEWPORT8 *viewport); 64 void setVertexShader(unsigned long shaderHandle); 65 void setVertexShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count); 66 67 private: 68 // Individual states 69 void captureRenderState(D3DRENDERSTATETYPE state); 70 void captureTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type); 71 void captureTransform(D3DTRANSFORMSTATETYPE state); 72 73 // Pixel states 74 void capturePixelRenderStates(); 75 void capturePixelTextureStates(); 76 void capturePixelShaderStates(); 77 78 // Vertex states 79 void captureVertexRenderStates(); 80 void captureVertexTextureStates(); 81 void captureLightStates(); 82 void captureVertexShaderStates(); 83 84 // All (remaining) states 85 void captureTextures(); 86 void captureVertexTextures(); 87 void captureDisplacementTextures(); 88 void captureTexturePalette(); 89 void captureVertexStreams(); 90 void captureIndexBuffer(); 91 void captureViewport(); 92 void captureTransforms(); 93 void captureTextureTransforms(); 94 void captureClippingPlanes(); 95 void captureMaterial(); 96 97 // Creation parameters 98 Direct3DDevice8 *const device; 99 const D3DSTATEBLOCKTYPE type; 100 101 // State data 102 bool vertexShaderCaptured; 103 unsigned long vertexShaderHandle; 104 105 bool pixelShaderCaptured; 106 unsigned long pixelShaderHandle; 107 108 bool indexBufferCaptured; 109 Direct3DIndexBuffer8 *indexBuffer; 110 unsigned int baseVertexIndex; 111 112 bool renderStateCaptured[D3DRS_NORMALORDER + 1]; 113 unsigned long renderState[D3DRS_NORMALORDER + 1]; 114 115 bool textureStageStateCaptured[8][D3DTSS_RESULTARG + 1]; 116 unsigned long textureStageState[8][D3DTSS_RESULTARG + 1]; 117 118 bool streamSourceCaptured[16]; 119 struct StreamSource 120 { 121 Direct3DVertexBuffer8 *vertexBuffer; 122 unsigned int stride; 123 }; 124 StreamSource streamSource[16]; 125 126 bool textureCaptured[8]; 127 Direct3DBaseTexture8 *texture[8]; 128 129 bool transformCaptured[512]; 130 D3DMATRIX transform[512]; 131 132 bool viewportCaptured; 133 D3DVIEWPORT8 viewport; 134 135 bool clipPlaneCaptured[6]; 136 float clipPlane[6][4]; 137 138 bool materialCaptured; 139 D3DMATERIAL8 material; 140 141 bool lightCaptured[8]; // FIXME: Unlimited index 142 D3DLIGHT8 light[8]; 143 144 bool lightEnableCaptured[8]; // FIXME: Unlimited index 145 int lightEnableState[8]; 146 147 float pixelShaderConstant[8][4]; 148 float vertexShaderConstant[256][4]; 149 150 bool scissorRectCaptured; 151 RECT scissorRect; 152 153 bool paletteNumberCaptured; 154 unsigned int paletteNumber; 155 156 void clear(); 157 }; 158 } 159 160 #endif // D3D8_Direct3DStateBlock8_hpp