static void TessProjectDynamicLights( const shaderCommands_t *input ) { const d3dTessBuffers_t* buffers = &g_DrawState.tessBufs; const d3dImage_t* tex = GetImageRenderInfo( tr.dlightImage ); const d3dGenericStageRenderData_t* resources = &g_DrawState.genericStage; g_pImmediateContext->IASetInputLayout( resources->inputLayoutST ); g_pImmediateContext->VSSetShader( resources->vertexShaderST, nullptr, 0 ); g_pImmediateContext->PSSetShader( resources->pixelShaderST, nullptr, 0 ); g_pImmediateContext->PSSetSamplers( 0, 1, &tex->pSampler ); g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_DrawState.viewRenderData.psConstantBuffer ); g_pImmediateContext->PSSetShaderResources( 0, 1, &tex->pSRV ); ID3D11Buffer* vbufs[2] = { NULL, NULL }; UINT strides[2] = { sizeof(vec2_t), sizeof(color4ub_t) }; UINT offsets[2] = { 0, 0 }; for ( int l = 0 ; l < input->dlightCount ; l++ ) { const dlightProjectionInfo_t* dlInfo = &input->dlightInfo[l]; if ( !dlInfo->numIndexes ) { continue; } vbufs[0] = buffers->dlights[l].texCoords; vbufs[1] = buffers->dlights[l].colors; g_pImmediateContext->IASetIndexBuffer( buffers->dlights[l].indexes, DXGI_FORMAT_R32_UINT, 0 ); g_pImmediateContext->IASetVertexBuffers( 1, 2, vbufs, strides, offsets ); // Select the blend mode if ( dlInfo->additive ) { D3DDrv_SetState( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL ); } else { D3DDrv_SetState( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL ); } UpdateMaterialState(); // Draw the dynamic light g_pImmediateContext->DrawIndexed( dlInfo->numIndexes, 0, 0 ); } }
static void IterateStagesGeneric( const shaderCommands_t *input ) { for ( int stage = 0; stage < MAX_SHADER_STAGES; stage++ ) { shaderStage_t *pStage = input->xstages[stage]; if ( !pStage ) { break; } D3DDrv_SetState( pStage->stateBits ); UpdateMaterialState(); // // do multitexture // if ( pStage->bundle[1].image[0] != 0 ) { TessDrawMultitextured( input, stage ); } else { TessDrawTextured( input, stage ); } // allow skipping out to show just lightmaps during development if ( r_lightmap->integer && ( pStage->bundle[0].isLightmap || pStage->bundle[1].isLightmap || pStage->bundle[0].vertexLightmap ) ) { break; } } }
static void TessDrawFog( const shaderCommands_t* input ) { if ( input->shader->fogPass == FP_EQUAL ) { D3DDrv_SetState( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_DEPTHFUNC_EQUAL ); } else { D3DDrv_SetState( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); } UpdateMaterialState(); const d3dGenericStageRenderData_t* resources = &g_DrawState.genericStage; const d3dTessBuffers_t* buffers = &g_DrawState.tessBufs; const d3dImage_t* tex = GetImageRenderInfo( tr.fogImage ); ID3D11Buffer* vbufs[2] = { buffers->fog.texCoords, buffers->fog.colors }; UINT strides[2] = { sizeof(vec2_t), sizeof(color4ub_t) }; UINT offsets[2] = { 0, 0 }; g_pImmediateContext->IASetInputLayout( resources->inputLayoutST ); g_pImmediateContext->IASetIndexBuffer( buffers->indexes, DXGI_FORMAT_R32_UINT, 0 ); g_pImmediateContext->IASetVertexBuffers( 1, 2, vbufs, strides, offsets ); g_pImmediateContext->VSSetShader( resources->vertexShaderST, nullptr, 0 ); g_pImmediateContext->PSSetShader( resources->pixelShaderST, nullptr, 0 ); g_pImmediateContext->PSSetSamplers( 0, 1, &tex->pSampler ); g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_DrawState.viewRenderData.psConstantBuffer ); g_pImmediateContext->PSSetShaderResources( 0, 1, &tex->pSRV ); g_pImmediateContext->DrawIndexed( input->numIndexes, 0, 0 ); }
//---------------------------------------------------------------------------- // Set the default state //---------------------------------------------------------------------------- void D3DDrv_SetDefaultState() { memset( &g_RunState, 0, sizeof( g_RunState ) ); D3DDrv_SetState( 0 ); }
static void DrawSkyBox( const d3dSkyBoxRenderData_t* sbrd, const skyboxDrawInfo_t* skybox, const float* eye_origin, const float* colorTint ) { D3DDrv_SetState(0); CommitRasterizerState( CT_TWO_SIDED, qfalse, qfalse ); UpdateViewState(); UpdateMaterialState(); // // Update the VS constant buffer // d3dSkyBoxVSConstantBuffer_t* vscb = QD3D::MapDynamicBuffer<d3dSkyBoxVSConstantBuffer_t>( g_pImmediateContext, sbrd->vsConstantBuffer ); memcpy( vscb->eyePos, eye_origin, sizeof(float) * 3 ); g_pImmediateContext->Unmap( sbrd->vsConstantBuffer, 0 ); // // Update the PS constant buffer // d3dSkyBoxPSConstantBuffer_t* pscb = QD3D::MapDynamicBuffer<d3dSkyBoxPSConstantBuffer_t>( g_pImmediateContext, sbrd->psConstantBuffer ); if ( colorTint ) { memcpy( pscb->color, colorTint, sizeof(float) * 3 ); pscb->color[3] = 1; } else { pscb->color[0] = 1; pscb->color[1] = 1; pscb->color[2] = 1; pscb->color[3] = 1; } g_pImmediateContext->Unmap( sbrd->psConstantBuffer, 0 ); // // Draw // UINT stride = sizeof(float) * 5; UINT offset = 0; ID3D11Buffer* vsBuffers[] = { g_DrawState.viewRenderData.vsConstantBuffer, g_DrawState.skyBoxRenderData.vsConstantBuffer }; ID3D11Buffer* psBuffers[] = { g_DrawState.skyBoxRenderData.psConstantBuffer }; g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); g_pImmediateContext->IASetVertexBuffers( 0, 1, &sbrd->vertexBuffer, &stride, &offset ); g_pImmediateContext->IASetInputLayout( sbrd->inputLayout ); g_pImmediateContext->VSSetShader( sbrd->vertexShader, nullptr, 0 ); g_pImmediateContext->VSSetConstantBuffers( 0, _countof( vsBuffers ), vsBuffers ); g_pImmediateContext->PSSetShader( sbrd->pixelShader, nullptr, 0 ); g_pImmediateContext->PSSetConstantBuffers( 0, _countof( psBuffers ), psBuffers ); for ( int i = 0; i < 6; ++i ) { const skyboxSideDrawInfo_t* side = &skybox->sides[i]; if ( !side->image ) continue; const d3dImage_t* image = GetImageRenderInfo( side->image ); g_pImmediateContext->PSSetShaderResources( 0, 1, &image->pSRV ); g_pImmediateContext->PSSetSamplers( 0, 1, &image->pSampler ); g_pImmediateContext->Draw( 6, i * 6 ); } }