Esempio n. 1
0
void ShadowRendererD3D11::Enter(NFE_CONTEXT_ARG)
{
    auto pCtx = (RenderContextD3D11*)pContext;

    pCtx->D3DContext->IASetInputLayout(mInputLayout);
    pCtx->D3DContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    ID3D11Buffer* pCBuffers[] = {mGlobalCBuffer, mPerInstanceCBuffer};
    pCtx->D3DContext->VSSetConstantBuffers(0, 2, pCBuffers);
    pCtx->D3DContext->PSSetConstantBuffers(0, 1, pCBuffers);


    pCtx->D3DContext->OMSetDepthStencilState(mDepthStencilState, 0);
    pCtx->D3DContext->RSSetState(mRasterizerState);
    pCtx->D3DContext->PSSetSamplers(0, 1, &mSampler);

    //initialize per instance cbuffer with identity transformation
    //PerInstanceCBufferVS CBufferData;
    //CBufferData.worldMatrix = MatrixIdentity();
    //pCtx->D3DContext->UpdateSubresource(mPerInstanceCBuffer, 0, 0, &CBufferData, 0, 0);

    UINT instancing = INSTANCING;
    pCtx->BindShader(&mShaderVS, &instancing);
    pCtx->BindShader(&mShaderPS, 0);
}
Esempio n. 2
0
void setShaders()
{
	MapObject Tiles = getTileBuffer();
	ImportObj Tee = getTeeBuffer();
	ImportObj Cup = getCupBuffer();
	ImportObj Walls = getWallsBuffer();
	ImportObj Pointer = getPointer();
	GLuint program = LoadShaders("vshader5.glsl", "fshader5.glsl");
	shadertemp = program;
	glUseProgram(program);
	GLuint vPosition, vNormal;

	//Set lighting
	setLighting(program);

	// Retrieve transformation uniform variable locations
	ModelView = glGetUniformLocation(program, "ModelView");
	Projection = glGetUniformLocation(program, "Projection");

	glGenVertexArrays(6, vao);

	BindShader(vao[0], program, Tiles.Vertices, Tiles.Normals, Tiles.Indices);
	BindShader(vao[1], program, Tee.Vertices, Tee.Normals, Tee.Indices);
	BindShader(vao[2], program, Cup.Vertices, Cup.Normals, Cup.Indices);
	BindShader(vao[3], program, GolfBall.Model.Vertices, GolfBall.Model.Normals, GolfBall.Model.Indices);
	BindShader(vao[4], program, Walls.Vertices, Walls.Normals, Walls.Indices);
	BindShader(vao[5], program, Pointer.Vertices, Pointer.Normals, Pointer.Indices);
}
Esempio n. 3
0
void ShadowRendererD3D11::SetDestination(NFE_CONTEXT_ARG, const CameraRenderDesc* pCamera,
        IShadowMap* pShadowMap, uint32 faceID)
{
    auto pCtx = (RenderContextD3D11*)pContext;
    ShadowMapD3D11* pSM = (ShadowMapD3D11*)pShadowMap;

    if (pShadowMap == 0)
        return;

    float clearColor[] = {1.0f, 0.0f, 0.0f, 0.0f};

    D3D11_VIEWPORT viewport;
    viewport.Width = viewport.Height = (float)pShadowMap->GetSize();
    viewport.MaxDepth = 1.0f;
    viewport.MinDepth = 0.0f;
    viewport.TopLeftX = 0.0f;
    viewport.TopLeftY = 0.0f;
    pCtx->D3DContext->RSSetViewports(1, &viewport);


    //bind shadow map
    ID3D11RenderTargetView* pRTV = pSM->RTVs[faceID];
    pCtx->D3DContext->ClearRenderTargetView(pRTV, clearColor);
    pCtx->D3DContext->ClearDepthStencilView(pSM->DSV, D3D11_CLEAR_DEPTH, 1.0f, 0);
    pCtx->D3DContext->OMSetRenderTargets(1, &pRTV, pSM->DSV);

    uint32 macros[2];
    macros[0] = 0;
    macros[1] = (pSM->type == IShadowMap::Type::Cube);
    pCtx->BindShader(&mShaderPS, macros);

    ShadowGlobalCBufferVS CBufferData;
    CBufferData.projMatrix = pCamera->projMatrix;
    CBufferData.viewMatrix = pCamera->viewMatrix;
    CBufferData.viewProjMatrix = pCamera->viewMatrix * pCamera->projMatrix;
    CBufferData.lightPos = pCamera->matrix.r[3];
    pCtx->D3DContext->UpdateSubresource(mGlobalCBuffer, 0, 0, &CBufferData, 0, 0);
}
Esempio n. 4
0
void GuiRendererD3D11::FlushQueue(NFE_CONTEXT_ARG)
{
    auto pCtx = (RenderContextD3D11*)pContext;

    if (mQueuedQuads == 0)
        return;

    D3D11_MAPPED_SUBRESOURCE mappedVB;
    pCtx->D3DContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedVB);
    GuiVertex* pVerticies = (GuiVertex*)mappedVB.pData;

    //build verticies array
    for (UINT i = 0; i < mQueuedQuads; i++)
    {
        pVerticies[i].rect = mQuads[i].rect;
        pVerticies[i].texCoord = mQuads[i].texCoord;
        pVerticies[i].color = mQuads[i].color;
    }

    //copy quads to the GPU
    pCtx->D3DContext->Unmap(mVertexBuffer, 0);

    UINT macros[2] = {0, 0}; // use texture, texture mode
    IRendererTexture* pTexture = NULL;
    bool alphaTexture = false;
    pCtx->BindShader(&mShaderVS, 0);
    pCtx->BindShader(&mShaderPS, 0);
    pCtx->BindShader(&mShaderGS, 0);

    UINT firstQuad = 0;
    UINT packetSize = 0;
    for (UINT i = 0; i < mQueuedQuads; i++)
    {
        if ((mQuads[i].pTexture != pTexture) || (mQuads[i].alphaTexture != alphaTexture))
        {
            //flush quads
            pCtx->D3DContext->Draw(packetSize, firstQuad);
            packetSize = 0;
            firstQuad = i;

            //change texture & shader
            pTexture = mQuads[i].pTexture;
            alphaTexture = mQuads[i].alphaTexture;
            macros[0] = (pTexture != NULL);
            macros[1] = (int)alphaTexture;
            pCtx->BindShader(&mShaderPS, macros);

            if (pTexture != NULL)
            {
                RendererTextureD3D11* pTextureD3D11 = dynamic_cast<RendererTextureD3D11*>(pTexture);
                pCtx->D3DContext->PSSetShaderResources(0, 1, &pTextureD3D11->SRV);
            }
        }

        packetSize++;
    }

    if (packetSize)
    {
        pCtx->D3DContext->Draw(packetSize, firstQuad);
    }

    mQueuedQuads = 0;
}