Ejemplo n.º 1
0
void CHdmvSub::Render(SubPicDesc& spd, REFERENCE_TIME rt, RECT& bbox)
{
	bbox.left	= LONG_MAX;
	bbox.top	= LONG_MAX;
	bbox.right	= 0;
	bbox.bottom	= 0;

	POSITION pos = m_pObjects.GetHeadPosition();
	while (pos) {
		CompositionObject* pObject = m_pObjects.GetAt (pos);

		if (pObject && rt >= pObject->m_rtStart && rt < pObject->m_rtStop) {
			if (pObject->GetRLEDataSize() && pObject->m_width > 0 && pObject->m_height > 0 &&
					m_VideoDescriptor.nVideoWidth >= (pObject->m_horizontal_position + pObject->m_width) &&
					m_VideoDescriptor.nVideoHeight >= (pObject->m_vertical_position + pObject->m_height)) {

				if (g_bForcedSubtitle && !pObject->m_forced_on_flag) {
					TRACE_HDMVSUB(_T("CHdmvSub::Render() : skip non forced subtitle - forced = %d, %I64d = %s"), pObject->m_forced_on_flag, rt, ReftimeToString(rt));
					return;
				}

				if (!pObject->HavePalette() && m_DefaultCLUT.Palette) {
					pObject->SetPalette(m_DefaultCLUT.pSize, m_DefaultCLUT.Palette, m_VideoDescriptor.nVideoWidth > 720);
				}

				if (!pObject->HavePalette()) {
					TRACE_HDMVSUB(_T("CHdmvSub::Render() : The palette is missing - cancel rendering\n"));
					return;
				}

				bbox.left	= min(pObject->m_horizontal_position, bbox.left);
				bbox.top	= min(pObject->m_vertical_position, bbox.top);
				bbox.right	= max(pObject->m_horizontal_position + pObject->m_width, bbox.right);
				bbox.bottom	= max(pObject->m_vertical_position + pObject->m_height, bbox.bottom);

				bbox.left	= bbox.left > 0 ? bbox.left : 0;
				bbox.top	= bbox.top > 0 ? bbox.top : 0;
				if (m_VideoDescriptor.nVideoWidth > spd.w) {
					bbox.left	= MulDiv(bbox.left, spd.w, m_VideoDescriptor.nVideoWidth);
					bbox.right	= MulDiv(bbox.right, spd.w, m_VideoDescriptor.nVideoWidth);
				}
				if (m_VideoDescriptor.nVideoHeight > spd.h) {
					bbox.top	= MulDiv(bbox.top, spd.h, m_VideoDescriptor.nVideoHeight);
					bbox.bottom	= MulDiv(bbox.bottom, spd.h, m_VideoDescriptor.nVideoHeight);
				}

				TRACE_HDMVSUB(_T("CHdmvSub::Render() : size = %ld, ObjRes = %dx%d, SPDRes = %dx%d, %I64d = %s\n"),
								pObject->GetRLEDataSize(),
								pObject->m_width, pObject->m_height, spd.w, spd.h,
								rt, ReftimeToString(rt));

				InitSpd(spd, m_VideoDescriptor.nVideoWidth, m_VideoDescriptor.nVideoHeight);
				pObject->RenderHdmv(spd, m_bResizedRender ? &m_spd : NULL);
			}
		}

		m_pObjects.GetNext(pos);
	}

	FinalizeRender(spd);
}
Ejemplo n.º 2
0
void CFXAPISample::Render ()
{
    PrepareRender ();

    static int frameNumber = 0;
    frameNumber++;

    deviceContext_->OMSetDepthStencilState (depthStencilState_.Get (), 0);
    deviceContext_->VSSetShader (vertexShader_.Get (), nullptr, 0);
    deviceContext_->PSSetShader (pixelShader_.Get (), nullptr, 0);
    deviceContext_->IASetIndexBuffer (indexBuffer_.Get (), DXGI_FORMAT_R32_UINT, 0);

    ID3D11Buffer* vertexBuffers[] = { vertexBuffer_.Get () };
    UINT strides[] = { sizeof (Vertex) };
    UINT offsets[] = { 0 };
    deviceContext_->IASetVertexBuffers (0, 1, vertexBuffers, strides, offsets);

    deviceContext_->IASetInputLayout (inputLayout_.Get ());
    deviceContext_->IASetPrimitiveTopology (D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    /**
    What happens here is:

    * On every odd frame, render an increasingly red color into texture_
    * In every frame, blit texture into the back buffer
    */

    if (cfxEnabled_) {
        // We're starting to use texture_, notify the API. Notice that we need
        // to notify even if we don't actually write to it in this frame.
        agsDriverExtensions_NotifyResourceBeginAllAccess (agsContext_, texture_.Get ());
    }

    if ((frameNumber & 1) == 1) {
        const float clearColor[] = {
            (frameNumber % 256) / 256.0f, 0.042f, 0.042f,
            1
        };

        D3D11_VIEWPORT viewports[1];
        viewports[0].Height = 1080;
        viewports[0].Width = 1920;
        viewports[0].MinDepth = 0;
        viewports[0].MaxDepth = 1;
        viewports[0].TopLeftX = 0;
        viewports[0].TopLeftY = 0;
        deviceContext_->RSSetViewports (1, viewports);

        ID3D11ShaderResourceView* psSRVs[] = {
            uploadTextureSRV_.Get ()
        };

        ID3D11RenderTargetView* renderTargetViews[] = {
            textureRTV_.Get ()
        };
        deviceContext_->OMSetRenderTargets (1, renderTargetViews, nullptr);

        deviceContext_->PSSetShaderResources (0, 1, psSRVs);
        deviceContext_->UpdateSubresource (uploadTexture_.Get (),
                                           0, nullptr, clearColor, sizeof (float) * 4, sizeof (float) * 4);
        deviceContext_->DrawIndexed (6, 0, 0);

        if (cfxEnabled_) {
            // We're done with writes to texture_, notify the API so it can
            // start copying
            agsDriverExtensions_NotifyResourceEndWrites (agsContext_, texture_.Get (),
                    nullptr, nullptr, 0);
        }
    }

    D3D11_VIEWPORT viewports[1];
    viewports[0].Height = 1080;
    viewports[0].Width = 1920;
    viewports[0].MinDepth = 0;
    viewports[0].MaxDepth = 1;
    viewports[0].TopLeftX = 0;
    viewports[0].TopLeftY = 0;
    deviceContext_->RSSetViewports (1, viewports);

    ID3D11RenderTargetView* renderTargetViews[] = {
        renderTargetView_.Get ()
    };

    deviceContext_->OMSetRenderTargets (1, renderTargetViews, nullptr);
    ID3D11ShaderResourceView* psSRVs[] = {
        textureSRV_.Get ()
    };

    deviceContext_->PSSetShaderResources (0, 1, psSRVs);
    deviceContext_->DrawIndexed (6, 0, 0);

    if (cfxEnabled_) {
        // We're done using texture_ for this frame, notify the API
        agsDriverExtensions_NotifyResourceEndAllAccess (agsContext_, texture_.Get ());
    }

    ID3D11ShaderResourceView* psNullSRVs[] = {
        nullptr
    };
    deviceContext_->PSSetShaderResources (0, 1, psNullSRVs);

    FinalizeRender ();
}