Home | History | Annotate | Download | only in D3D8
      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 #include "Direct3DStateBlock8.hpp"
     16 
     17 #include "Direct3DDevice8.hpp"
     18 #include "Direct3DBaseTexture8.hpp"
     19 #include "Direct3DVertexBuffer8.hpp"
     20 #include "Direct3DIndexBuffer8.hpp"
     21 #include "Debug.hpp"
     22 
     23 #include <assert.h>
     24 
     25 namespace D3D8
     26 {
     27 	Direct3DStateBlock8::Direct3DStateBlock8(Direct3DDevice8 *device, D3DSTATEBLOCKTYPE type) : device(device), type(type)
     28 	{
     29 		vertexShaderHandle = 0;
     30 		pixelShaderHandle = 0;
     31 		indexBuffer = 0;
     32 
     33 		for(int stream = 0; stream < 16; stream++)
     34 		{
     35 			streamSource[stream].vertexBuffer = 0;
     36 		}
     37 
     38 		for(int stage = 0; stage < 8; stage++)
     39 		{
     40 			texture[stage] = 0;
     41 		}
     42 
     43 		clear();
     44 
     45 		if(type == D3DSBT_PIXELSTATE || type == D3DSBT_ALL)
     46 		{
     47 			capturePixelRenderStates();
     48 			capturePixelTextureStates();
     49 			capturePixelShaderStates();
     50 		}
     51 
     52 		if(type == D3DSBT_VERTEXSTATE || type == D3DSBT_ALL)
     53 		{
     54 			captureVertexRenderStates();
     55 			captureVertexTextureStates();
     56 			captureLightStates();
     57 			captureVertexShaderStates();
     58 		}
     59 
     60 		if(type == D3DSBT_ALL)   // Capture remaining states
     61 		{
     62 			captureTextures();
     63 			captureVertexTextures();
     64 			captureDisplacementTextures();
     65 			captureTexturePalette();
     66 			captureVertexStreams();
     67 			captureIndexBuffer();
     68 			captureViewport();
     69 			captureTransforms();
     70 			captureTextureTransforms();
     71 			captureClippingPlanes();
     72 			captureMaterial();
     73 		}
     74 	}
     75 
     76 	Direct3DStateBlock8::~Direct3DStateBlock8()
     77 	{
     78 		clear();
     79 	}
     80 
     81 	long Direct3DStateBlock8::QueryInterface(const IID &iid, void **object)
     82 	{
     83 		TRACE("");
     84 
     85 		ASSERT(false);   // Internal object
     86 
     87 		return NOINTERFACE(iid);
     88 	}
     89 
     90 	unsigned long Direct3DStateBlock8::AddRef()
     91 	{
     92 		TRACE("");
     93 
     94 		return Unknown::AddRef();
     95 	}
     96 
     97 	unsigned long Direct3DStateBlock8::Release()
     98 	{
     99 		TRACE("");
    100 
    101 		return Unknown::Release();
    102 	}
    103 
    104 	long Direct3DStateBlock8::Apply()
    105 	{
    106 		TRACE("");
    107 
    108 		if(vertexShaderCaptured)
    109 		{
    110 			device->SetVertexShader(vertexShaderHandle);
    111 		}
    112 
    113 		if(pixelShaderCaptured)
    114 		{
    115 			device->SetPixelShader(pixelShaderHandle);
    116 		}
    117 
    118 		if(indexBufferCaptured)
    119 		{
    120 			device->SetIndices(indexBuffer, baseVertexIndex);
    121 		}
    122 
    123 		for(int state = 0; state < D3DRS_NORMALORDER + 1; state++)
    124 		{
    125 			if(renderStateCaptured[state])
    126 			{
    127 				device->SetRenderState((D3DRENDERSTATETYPE)state, renderState[state]);
    128 			}
    129 		}
    130 
    131 		for(int stage = 0; stage < 8; stage++)
    132 		{
    133 			for(int state = 0; state < D3DTSS_RESULTARG + 1; state++)
    134 			{
    135 				if(textureStageStateCaptured[stage][state])
    136 				{
    137 					device->SetTextureStageState(stage, (D3DTEXTURESTAGESTATETYPE)state, textureStageState[stage][state]);
    138 				}
    139 			}
    140 		}
    141 
    142 		for(int stream = 0; stream < 16; stream++)
    143 		{
    144 			if(streamSourceCaptured[stream])
    145 			{
    146 				device->SetStreamSource(stream, streamSource[stream].vertexBuffer, streamSource[stream].stride);
    147 			}
    148 		}
    149 
    150 		for(int stage = 0; stage < 8; stage++)
    151 		{
    152 			if(textureCaptured[stage])
    153 			{
    154 				device->SetTexture(stage, texture[stage]);
    155 			}
    156 		}
    157 
    158 		for(int state = 0; state < 512; state++)
    159 		{
    160 			if(transformCaptured[state])
    161 			{
    162 				device->SetTransform((D3DTRANSFORMSTATETYPE)state, &transform[state]);
    163 			}
    164 		}
    165 
    166 		if(viewportCaptured)
    167 		{
    168 			device->SetViewport(&viewport);
    169 		}
    170 
    171 		for(int index = 0; index < 6; index++)
    172 		{
    173 			if(clipPlaneCaptured[index])
    174 			{
    175 				device->SetClipPlane(index, clipPlane[index]);
    176 			}
    177 		}
    178 
    179 		return D3D_OK;
    180 	}
    181 
    182 	long Direct3DStateBlock8::Capture()
    183 	{
    184 		TRACE("");
    185 
    186 		if(vertexShaderCaptured)
    187 		{
    188 			device->GetVertexShader(&vertexShaderHandle);
    189 		}
    190 
    191 		if(pixelShaderCaptured)
    192 		{
    193 			device->GetPixelShader(&pixelShaderHandle);
    194 		}
    195 
    196 		if(indexBufferCaptured)
    197 		{
    198 			if(indexBuffer)
    199 			{
    200 				indexBuffer->Release();
    201 			}
    202 
    203 			device->GetIndices(reinterpret_cast<IDirect3DIndexBuffer8**>(&indexBuffer), &baseVertexIndex);
    204 		}
    205 
    206 		for(int state = 0; state < D3DRS_NORMALORDER + 1; state++)
    207 		{
    208 			if(renderStateCaptured[state])
    209 			{
    210 				device->GetRenderState((D3DRENDERSTATETYPE)state, &renderState[state]);
    211 			}
    212 		}
    213 
    214 		for(int stage = 0; stage < 8; stage++)
    215 		{
    216 			for(int state = 0; state < D3DTSS_RESULTARG + 1; state++)
    217 			{
    218 				if(textureStageStateCaptured[stage][state])
    219 				{
    220 					device->GetTextureStageState(stage, (D3DTEXTURESTAGESTATETYPE)state, &textureStageState[stage][state]);
    221 				}
    222 			}
    223 		}
    224 
    225 		for(int stream = 0; stream < 16; stream++)
    226 		{
    227 			if(streamSourceCaptured[stream])
    228 			{
    229 				if(streamSource[stream].vertexBuffer)
    230 				{
    231 					streamSource[stream].vertexBuffer->Release();
    232 				}
    233 
    234 				device->GetStreamSource(stream, reinterpret_cast<IDirect3DVertexBuffer8**>(&streamSource[stream].vertexBuffer), &streamSource[stream].stride);
    235 			}
    236 		}
    237 
    238 		for(int stage = 0; stage < 8; stage++)
    239 		{
    240 			if(textureCaptured[stage])
    241 			{
    242 				if(texture[stage])
    243 				{
    244 					texture[stage]->Release();
    245 				}
    246 
    247 				device->GetTexture(stage, reinterpret_cast<IDirect3DBaseTexture8**>(&texture[stage]));
    248 			}
    249 		}
    250 
    251 		for(int state = 0; state < 512; state++)
    252 		{
    253 			if(transformCaptured[state])
    254 			{
    255 				device->GetTransform((D3DTRANSFORMSTATETYPE)state, &transform[state]);
    256 			}
    257 		}
    258 
    259 		if(viewportCaptured)
    260 		{
    261 			device->GetViewport(&viewport);
    262 		}
    263 
    264 		for(int index = 0; index < 6; index++)
    265 		{
    266 			if(clipPlaneCaptured[index])
    267 			{
    268 				device->GetClipPlane(index, clipPlane[index]);
    269 			}
    270 		}
    271 
    272 		return D3D_OK;
    273 	}
    274 
    275 	long Direct3DStateBlock8::GetDevice(IDirect3DDevice8 **device)
    276 	{
    277 		TRACE("");
    278 
    279 		if(!device)
    280 		{
    281 			return INVALIDCALL();
    282 		}
    283 
    284 		this->device->AddRef();
    285 		*device = this->device;
    286 
    287 		return D3D_OK;
    288 	}
    289 
    290 	void Direct3DStateBlock8::lightEnable(unsigned long index, int enable)
    291 	{
    292 		UNIMPLEMENTED();
    293 	}
    294 
    295 	void Direct3DStateBlock8::setClipPlane(unsigned long index, const float *plane)
    296 	{
    297 		clipPlaneCaptured[index] = true;
    298 		clipPlane[index][0] = plane[0];
    299 		clipPlane[index][1] = plane[1];
    300 		clipPlane[index][2] = plane[2];
    301 		clipPlane[index][3] = plane[3];
    302 	}
    303 
    304 	void Direct3DStateBlock8::setCurrentTexturePalette(unsigned int paletteNumber)
    305 	{
    306 		UNIMPLEMENTED();
    307 	}
    308 
    309 	void Direct3DStateBlock8::setFVF(unsigned long FVF)
    310 	{
    311 		UNIMPLEMENTED();
    312 	}
    313 
    314 	void Direct3DStateBlock8::setIndices(Direct3DIndexBuffer8 *indexData, unsigned int baseVertexIndex)
    315 	{
    316 		if(indexData) indexData->AddRef();
    317 
    318 		indexBufferCaptured = true;
    319 		indexBuffer = indexData;
    320 		this->baseVertexIndex = baseVertexIndex;
    321 	}
    322 
    323 	void Direct3DStateBlock8::setLight(unsigned long index, const D3DLIGHT8 *light)
    324 	{
    325 		UNIMPLEMENTED();
    326 	}
    327 
    328 	void Direct3DStateBlock8::setMaterial(const D3DMATERIAL8 *material)
    329 	{
    330 		UNIMPLEMENTED();
    331 	}
    332 
    333 	void Direct3DStateBlock8::setPixelShader(unsigned long shaderHandle)
    334 	{
    335 		pixelShaderCaptured = true;
    336 		pixelShaderHandle = shaderHandle;
    337 	}
    338 
    339 	void Direct3DStateBlock8::setPixelShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count)
    340 	{
    341 		UNIMPLEMENTED();
    342 	}
    343 
    344 	void Direct3DStateBlock8::setRenderState(D3DRENDERSTATETYPE state, unsigned long value)
    345 	{
    346 		renderStateCaptured[state] = true;
    347 		renderState[state] = value;
    348 	}
    349 
    350 	void Direct3DStateBlock8::setScissorRect(const RECT *rect)
    351 	{
    352 		UNIMPLEMENTED();
    353 	}
    354 
    355 	void Direct3DStateBlock8::setStreamSource(unsigned int stream, Direct3DVertexBuffer8 *data, unsigned int stride)
    356 	{
    357 		if(data) data->AddRef();
    358 
    359 		streamSourceCaptured[stream] = true;
    360 		streamSource[stream].vertexBuffer = data;
    361 		streamSource[stream].stride = stride;
    362 	}
    363 
    364 	void Direct3DStateBlock8::setTexture(unsigned long stage, Direct3DBaseTexture8 *texture)
    365 	{
    366 		if(texture) texture->AddRef();
    367 
    368 		textureCaptured[stage] = true;
    369 		this->texture[stage] = texture;
    370 	}
    371 
    372 	void Direct3DStateBlock8::setTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value)
    373 	{
    374 		textureStageStateCaptured[stage][type] = true;
    375 		textureStageState[stage][type] = value;
    376 	}
    377 
    378 	void Direct3DStateBlock8::setTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
    379 	{
    380 		transformCaptured[state] = true;
    381 		transform[state] = *matrix;
    382 	}
    383 
    384 	void Direct3DStateBlock8::setViewport(const D3DVIEWPORT8 *viewport)
    385 	{
    386 		viewportCaptured = true;
    387 		this->viewport = *viewport;
    388 	}
    389 
    390 	void Direct3DStateBlock8::setVertexShader(unsigned long shaderHandle)
    391 	{
    392 		vertexShaderCaptured = true;
    393 		vertexShaderHandle = shaderHandle;
    394 	}
    395 
    396 	void Direct3DStateBlock8::setVertexShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count)
    397 	{
    398 		UNIMPLEMENTED();
    399 	}
    400 
    401 	void Direct3DStateBlock8::clear()
    402 	{
    403 		// Erase capture flags
    404 		vertexShaderCaptured = false;
    405 		pixelShaderCaptured = false;
    406 		indexBufferCaptured = false;
    407 
    408 		for(int state = 0; state < D3DRS_NORMALORDER + 1; state++)
    409 		{
    410 			renderStateCaptured[state] = false;
    411 		}
    412 
    413 		for(int stage = 0; stage < 8; stage++)
    414 		{
    415 			for(int state = 0; state < D3DTSS_RESULTARG + 1; state++)
    416 			{
    417 				textureStageStateCaptured[stage][state] = false;
    418 			}
    419 		}
    420 
    421 		for(int stream = 0; stream < 16; stream++)
    422 		{
    423 			streamSourceCaptured[stream] = false;
    424 		}
    425 
    426 		for(int stage = 0; stage < 8; stage++)
    427 		{
    428 			textureCaptured[stage] = false;
    429 		}
    430 
    431 		for(int state = 0; state < 512; state++)
    432 		{
    433 			transformCaptured[state] = false;
    434 		}
    435 
    436 		viewportCaptured = false;
    437 
    438 		for(int index = 0; index < 6; index++)
    439 		{
    440 			clipPlaneCaptured[index] = false;
    441 		}
    442 
    443 		// Release resources
    444 		vertexShaderHandle = 0;
    445 		pixelShaderHandle = 0;
    446 
    447 		if(indexBuffer)
    448 		{
    449 			indexBuffer->Release();
    450 			indexBuffer = 0;
    451 		}
    452 
    453 		for(int stream = 0; stream < 16; stream++)
    454 		{
    455 			if(streamSource[stream].vertexBuffer)
    456 			{
    457 				streamSource[stream].vertexBuffer->Release();
    458 				streamSource[stream].vertexBuffer = 0;
    459 			}
    460 		}
    461 
    462 		for(int stage = 0; stage < 8; stage++)
    463 		{
    464 			if(texture[stage])
    465 			{
    466 				texture[stage]->Release();
    467 				texture[stage] = 0;
    468 			}
    469 		}
    470 	}
    471 
    472 	void Direct3DStateBlock8::captureRenderState(D3DRENDERSTATETYPE state)
    473 	{
    474 		device->GetRenderState(state, &renderState[state]);
    475 		renderStateCaptured[state] = true;
    476 	}
    477 
    478 	void Direct3DStateBlock8::captureTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type)
    479 	{
    480 		device->GetTextureStageState(stage, type, &textureStageState[stage][type]);
    481 		textureStageStateCaptured[stage][type] = true;
    482 	}
    483 
    484 	void Direct3DStateBlock8::captureTransform(D3DTRANSFORMSTATETYPE state)
    485 	{
    486 		device->GetTransform(state, &transform[state]);
    487 		transformCaptured[state] = true;
    488 	}
    489 
    490 	void Direct3DStateBlock8::capturePixelRenderStates()
    491 	{
    492 		captureRenderState(D3DRS_ZENABLE);
    493 		captureRenderState(D3DRS_FILLMODE);
    494 		captureRenderState(D3DRS_SHADEMODE);
    495 		captureRenderState(D3DRS_ZWRITEENABLE);
    496 		captureRenderState(D3DRS_ALPHATESTENABLE);
    497 		captureRenderState(D3DRS_LASTPIXEL);
    498 		captureRenderState(D3DRS_SRCBLEND);
    499 		captureRenderState(D3DRS_DESTBLEND);
    500 		captureRenderState(D3DRS_ZFUNC);
    501 		captureRenderState(D3DRS_ALPHAREF);
    502 		captureRenderState(D3DRS_ALPHAFUNC);
    503 		captureRenderState(D3DRS_DITHERENABLE);
    504 		captureRenderState(D3DRS_FOGSTART);
    505 		captureRenderState(D3DRS_FOGEND);
    506 		captureRenderState(D3DRS_FOGDENSITY);
    507 		captureRenderState(D3DRS_ALPHABLENDENABLE);
    508 		captureRenderState(D3DRS_ZBIAS);
    509 		captureRenderState(D3DRS_STENCILENABLE);
    510 		captureRenderState(D3DRS_STENCILFAIL);
    511 		captureRenderState(D3DRS_STENCILZFAIL);
    512 		captureRenderState(D3DRS_STENCILPASS);
    513 		captureRenderState(D3DRS_STENCILFUNC);
    514 		captureRenderState(D3DRS_STENCILREF);
    515 		captureRenderState(D3DRS_STENCILMASK);
    516 		captureRenderState(D3DRS_STENCILWRITEMASK);
    517 		captureRenderState(D3DRS_TEXTUREFACTOR);
    518 		captureRenderState(D3DRS_WRAP0);
    519 		captureRenderState(D3DRS_WRAP1);
    520 		captureRenderState(D3DRS_WRAP2);
    521 		captureRenderState(D3DRS_WRAP3);
    522 		captureRenderState(D3DRS_WRAP4);
    523 		captureRenderState(D3DRS_WRAP5);
    524 		captureRenderState(D3DRS_WRAP6);
    525 		captureRenderState(D3DRS_WRAP7);
    526 		captureRenderState(D3DRS_COLORWRITEENABLE);
    527 		captureRenderState(D3DRS_BLENDOP);
    528 	}
    529 
    530 	void Direct3DStateBlock8::capturePixelTextureStates()
    531 	{
    532 		for(int stage = 0; stage < 8; stage++)
    533 		{
    534 			captureTextureStageState(stage, D3DTSS_COLOROP);
    535 			captureTextureStageState(stage, D3DTSS_COLORARG1);
    536 			captureTextureStageState(stage, D3DTSS_COLORARG2);
    537 			captureTextureStageState(stage, D3DTSS_ALPHAOP);
    538 			captureTextureStageState(stage, D3DTSS_ALPHAARG1);
    539 			captureTextureStageState(stage, D3DTSS_ALPHAARG2);
    540 			captureTextureStageState(stage, D3DTSS_BUMPENVMAT00);
    541 			captureTextureStageState(stage, D3DTSS_BUMPENVMAT01);
    542 			captureTextureStageState(stage, D3DTSS_BUMPENVMAT10);
    543 			captureTextureStageState(stage, D3DTSS_BUMPENVMAT11);
    544 			captureTextureStageState(stage, D3DTSS_TEXCOORDINDEX);
    545 			captureTextureStageState(stage, D3DTSS_BUMPENVLSCALE);
    546 			captureTextureStageState(stage, D3DTSS_BUMPENVLOFFSET);
    547 			captureTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS);
    548 			captureTextureStageState(stage, D3DTSS_COLORARG0);
    549 			captureTextureStageState(stage, D3DTSS_ALPHAARG0);
    550 			captureTextureStageState(stage, D3DTSS_RESULTARG);
    551 
    552 			captureTextureStageState(stage, D3DTSS_ADDRESSU);
    553 			captureTextureStageState(stage, D3DTSS_ADDRESSV);
    554 			captureTextureStageState(stage, D3DTSS_ADDRESSW);
    555 			captureTextureStageState(stage, D3DTSS_BORDERCOLOR);
    556 			captureTextureStageState(stage, D3DTSS_MAGFILTER);
    557 			captureTextureStageState(stage, D3DTSS_MINFILTER);
    558 			captureTextureStageState(stage, D3DTSS_MIPFILTER);
    559 			captureTextureStageState(stage, D3DTSS_MIPMAPLODBIAS);
    560 			captureTextureStageState(stage, D3DTSS_MAXMIPLEVEL);
    561 			captureTextureStageState(stage, D3DTSS_MAXANISOTROPY);
    562 		}
    563 	}
    564 
    565 	void Direct3DStateBlock8::capturePixelShaderStates()
    566 	{
    567 		pixelShaderCaptured = true;
    568 		device->GetPixelShader(&pixelShaderHandle);
    569 
    570 		device->GetPixelShaderConstant(0, pixelShaderConstant, 8);
    571 	}
    572 
    573 	void Direct3DStateBlock8::captureVertexRenderStates()
    574 	{
    575 		captureRenderState(D3DRS_CULLMODE);
    576 		captureRenderState(D3DRS_FOGENABLE);
    577 		captureRenderState(D3DRS_FOGCOLOR);
    578 		captureRenderState(D3DRS_FOGTABLEMODE);
    579 		captureRenderState(D3DRS_FOGSTART);
    580 		captureRenderState(D3DRS_FOGEND);
    581 		captureRenderState(D3DRS_FOGDENSITY);
    582 		captureRenderState(D3DRS_RANGEFOGENABLE);
    583 		captureRenderState(D3DRS_AMBIENT);
    584 		captureRenderState(D3DRS_COLORVERTEX);
    585 		captureRenderState(D3DRS_FOGVERTEXMODE);
    586 		captureRenderState(D3DRS_CLIPPING);
    587 		captureRenderState(D3DRS_LIGHTING);
    588 		captureRenderState(D3DRS_LOCALVIEWER);
    589 		captureRenderState(D3DRS_EMISSIVEMATERIALSOURCE);
    590 		captureRenderState(D3DRS_AMBIENTMATERIALSOURCE);
    591 		captureRenderState(D3DRS_DIFFUSEMATERIALSOURCE);
    592 		captureRenderState(D3DRS_SPECULARMATERIALSOURCE);
    593 		captureRenderState(D3DRS_VERTEXBLEND);
    594 		captureRenderState(D3DRS_CLIPPLANEENABLE);
    595 		captureRenderState(D3DRS_POINTSIZE);
    596 		captureRenderState(D3DRS_POINTSIZE_MIN);
    597 		captureRenderState(D3DRS_POINTSPRITEENABLE);
    598 		captureRenderState(D3DRS_POINTSCALEENABLE);
    599 		captureRenderState(D3DRS_POINTSCALE_A);
    600 		captureRenderState(D3DRS_POINTSCALE_B);
    601 		captureRenderState(D3DRS_POINTSCALE_C);
    602 		captureRenderState(D3DRS_MULTISAMPLEANTIALIAS);
    603 		captureRenderState(D3DRS_MULTISAMPLEMASK);
    604 		captureRenderState(D3DRS_PATCHEDGESTYLE);
    605 		captureRenderState(D3DRS_POINTSIZE_MAX);
    606 		captureRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE);
    607 		captureRenderState(D3DRS_TWEENFACTOR);
    608 		captureRenderState(D3DRS_NORMALIZENORMALS);
    609 		captureRenderState(D3DRS_SPECULARENABLE);
    610 		captureRenderState(D3DRS_SHADEMODE);
    611 	}
    612 
    613 	void Direct3DStateBlock8::captureVertexTextureStates()
    614 	{
    615 		for(int stage = 0; stage < 8; stage++)
    616 		{
    617 			captureTextureStageState(stage, D3DTSS_TEXCOORDINDEX);
    618 			captureTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS);
    619 		}
    620 	}
    621 
    622 	void Direct3DStateBlock8::captureLightStates()
    623 	{
    624 		for(int index = 0; index < 8; index++)   // FIXME: Support unlimited index
    625 		{
    626 			device->GetLight(index, &light[index]);
    627 			lightCaptured[index] = true;
    628 		}
    629 
    630 		for(int index = 0; index < 8; index++)   // FIXME: Support unlimited index
    631 		{
    632 			lightEnableState[index] = false;
    633 			device->GetLightEnable(index, &lightEnableState[index]);
    634 			lightEnableCaptured[index] = true;
    635 		}
    636 	}
    637 
    638 	void Direct3DStateBlock8::captureVertexShaderStates()
    639 	{
    640 		vertexShaderCaptured = true;
    641 		device->GetVertexShader(&vertexShaderHandle);
    642 
    643 		device->GetVertexShaderConstant(0, vertexShaderConstant[0], 256);
    644 	}
    645 
    646 	void Direct3DStateBlock8::captureTextures()
    647 	{
    648 		for(int sampler = 0; sampler < 8; sampler++)
    649 		{
    650 			textureCaptured[sampler] = true;
    651 			device->GetTexture(sampler, reinterpret_cast<IDirect3DBaseTexture8**>(&texture[sampler]));
    652 
    653 			if(texture[sampler])
    654 			{
    655 				texture[sampler]->bind();
    656 				texture[sampler]->Release();
    657 			}
    658 		}
    659 	}
    660 
    661 	void Direct3DStateBlock8::captureVertexTextures()
    662 	{
    663 		// FIXME
    664 	}
    665 
    666 	void Direct3DStateBlock8::captureDisplacementTextures()
    667 	{
    668 		// FIXME
    669 	}
    670 
    671 	void Direct3DStateBlock8::captureTexturePalette()
    672 	{
    673 		paletteNumberCaptured = true;
    674 		device->GetCurrentTexturePalette(&paletteNumber);
    675 	}
    676 
    677 	void Direct3DStateBlock8::captureVertexStreams()
    678 	{
    679 		for(int stream = 0; stream < 16; stream++)
    680 		{
    681 			streamSourceCaptured[stream] = true;
    682 			device->GetStreamSource(stream, reinterpret_cast<IDirect3DVertexBuffer8**>(&streamSource[stream].vertexBuffer),  &streamSource[stream].stride);
    683 
    684 			if(streamSource[stream].vertexBuffer)
    685 			{
    686 				streamSource[stream].vertexBuffer->bind();
    687 				streamSource[stream].vertexBuffer->Release();
    688 			}
    689 		}
    690 	}
    691 
    692 	void Direct3DStateBlock8::captureIndexBuffer()
    693 	{
    694 		indexBufferCaptured = true;
    695 		device->GetIndices(reinterpret_cast<IDirect3DIndexBuffer8**>(&indexBuffer), &baseVertexIndex);
    696 
    697 		if(indexBuffer)
    698 		{
    699 			indexBuffer->bind();
    700 			indexBuffer->Release();
    701 		}
    702 	}
    703 
    704 	void Direct3DStateBlock8::captureViewport()
    705 	{
    706 		device->GetViewport(&viewport);
    707 		viewportCaptured = true;
    708 	}
    709 
    710 	void Direct3DStateBlock8::captureTransforms()
    711 	{
    712 		captureTransform(D3DTS_VIEW);
    713 		captureTransform(D3DTS_PROJECTION);
    714 		captureTransform(D3DTS_WORLD);
    715 	}
    716 
    717 	void Direct3DStateBlock8::captureTextureTransforms()
    718 	{
    719 		captureTransform(D3DTS_TEXTURE0);
    720 		captureTransform(D3DTS_TEXTURE1);
    721 		captureTransform(D3DTS_TEXTURE2);
    722 		captureTransform(D3DTS_TEXTURE3);
    723 		captureTransform(D3DTS_TEXTURE4);
    724 		captureTransform(D3DTS_TEXTURE5);
    725 		captureTransform(D3DTS_TEXTURE6);
    726 		captureTransform(D3DTS_TEXTURE7);
    727 	}
    728 
    729 	void Direct3DStateBlock8::captureClippingPlanes()
    730 	{
    731 		for(int index = 0; index < 6; index++)
    732 		{
    733 			device->GetClipPlane(index, (float*)&clipPlane[index]);
    734 			clipPlaneCaptured[index] = true;
    735 		}
    736 	}
    737 
    738 	void Direct3DStateBlock8::captureMaterial()
    739 	{
    740 		device->GetMaterial(&material);
    741 		materialCaptured = true;
    742 	}
    743 }