void D3D10System::LoadPixelShader(Shader *pShader) { if(curPixelShader != pShader) { if(pShader) { D3D10PixelShader *shader = static_cast<D3D10PixelShader*>(pShader); d3d->PSSetShader(shader->pixelShader); d3d->PSSetConstantBuffers(0, 1, &shader->constantBuffer); for(UINT i=0; i<shader->Samplers.Num(); i++) LoadSamplerState(shader->Samplers[i].sampler, i); } else { LPVOID lpNULL = NULL; d3d->PSSetShader(NULL); d3d->PSSetConstantBuffers(0, 1, (ID3D10Buffer**)&lpNULL); for(UINT i=0; i<8; i++) curSamplers[i] = NULL; ID3D10SamplerState *states[8]; zero(states, sizeof(states)); d3d->PSSetSamplers(0, 8, states); } curPixelShader = static_cast<D3D10PixelShader*>(pShader); } }
void D3D10System::UnloadAllData() { LoadVertexShader(NULL); LoadPixelShader(NULL); LoadVertexBuffer(NULL); for(UINT i=0; i<8; i++) { LoadSamplerState(NULL, i); LoadTexture(NULL, i); } UINT zeroVal = 0; LPVOID nullBuff[8]; float bla[4] = {1.0f, 1.0f, 1.0f, 1.0f}; zero(nullBuff, sizeof(nullBuff)); d3d->VSSetConstantBuffers(0, 1, (ID3D10Buffer**)nullBuff); d3d->PSSetConstantBuffers(0, 1, (ID3D10Buffer**)nullBuff); d3d->OMSetDepthStencilState(NULL, 0); d3d->PSSetSamplers(0, 1, (ID3D10SamplerState**)nullBuff); d3d->OMSetBlendState(NULL, bla, 0xFFFFFFFF); d3d->OMSetRenderTargets(1, (ID3D10RenderTargetView**)nullBuff, NULL); d3d->IASetVertexBuffers(0, 8, (ID3D10Buffer**)nullBuff, &zeroVal, &zeroVal); d3d->PSSetShaderResources(0, 8, (ID3D10ShaderResourceView**)nullBuff); d3d->IASetInputLayout(NULL); d3d->PSSetShader(NULL); d3d->VSSetShader(NULL); d3d->RSSetState(NULL); }
HRESULT D3D11Object::CreateSamplerStates() { HRESULT hr = S_OK; LoadSamplerState(&m_pSamplerLinear); GetDeviceContext()->CSSetSamplers( 0, 1, &m_pSamplerLinear ); return hr; }
void DeviceSource::Render(const Vect2 &pos, const Vect2 &size) { if(texture && bReadyToDraw) { Shader *oldShader = GetCurrentPixelShader(); SamplerState *sampler = NULL; if(colorConvertShader) { LoadPixelShader(colorConvertShader); if(bUseChromaKey) { float fSimilarity = float(keySimilarity)/1000.0f; float fBlendVal = float(max(keyBlend, 1)/1000.0f); float fSpillVal = (float(max(keySpillReduction, 1))/1000.0f); Vect2 pixelSize = 1.0f/GetSize(); colorConvertShader->SetColor (colorConvertShader->GetParameterByName(TEXT("keyBaseColor")), Color4(keyBaseColor)); colorConvertShader->SetColor (colorConvertShader->GetParameterByName(TEXT("chromaKey")), Color4(keyChroma)); colorConvertShader->SetVector2(colorConvertShader->GetParameterByName(TEXT("pixelSize")), pixelSize); colorConvertShader->SetFloat (colorConvertShader->GetParameterByName(TEXT("keySimilarity")), fSimilarity); colorConvertShader->SetFloat (colorConvertShader->GetParameterByName(TEXT("keyBlend")), fBlendVal); colorConvertShader->SetFloat (colorConvertShader->GetParameterByName(TEXT("keySpill")), fSpillVal); } } bool bFlip = bFlipVertical; if(colorType != DeviceOutputType_RGB) bFlip = !bFlip; float x, x2; if(bFlipHorizontal) { x2 = pos.x; x = x2+size.x; } else { x = pos.x; x2 = x+size.x; } float fOpacity = float(opacity)*0.01f; DWORD opacity255 = DWORD(fOpacity*255.0f); if(bUsePointFiltering) { SamplerInfo samplerinfo; samplerinfo.filter = GS_FILTER_POINT; sampler = CreateSamplerState(samplerinfo); LoadSamplerState(sampler, 0); } if(bFlip) DrawSprite(texture, (opacity255<<24) | 0xFFFFFF, x, pos.y, x2, pos.y+size.y); else DrawSprite(texture, (opacity255<<24) | 0xFFFFFF, x, pos.y+size.y, x2, pos.y); if(bUsePointFiltering) delete(sampler); if(colorConvertShader) LoadPixelShader(oldShader); } }