예제 #1
0
파일: rasterizer.cpp 프로젝트: leuat/gamer
/*    void SetupStars() {



            if (stars!=null && RPold.noStars == m_renderingParams->noStars && RPold.starStrength == m_renderingParams->starStrength && RPold.starSize == m_renderingParams->starSize && m_renderingParams->starSizeSpread == RPold.starSizeSpread)
                if (m_renderingParams->size == stars._width)
                    return;

            stars = new ColorBuffer2D(m_renderingParams->size, m_renderingParams->size);
            stars.RenderStars(m_renderingParams->noStars, m_renderingParams->starSize/100f, m_renderingParams->starSizeSpread/100f,m_renderingParams->starStrength);
            RPold.starSizeSpread = m_renderingParams->starSizeSpread;
            RPold.starSize = m_renderingParams->starSize;
            RPold.noStars = m_renderingParams->noStars;
            RPold.starStrength = m_renderingParams->starStrength;

        }
*/
void Rasterizer::PrepareBuffer()
{
    // Do not changes buffers if rendering!

    if (m_state == State::rendering) {
        qDebug() << "RETURNING STILL RENDERING";
        return;
    }


    int size = m_renderingParams->size();
    if (m_imageBuffer == nullptr || m_imageBuffer->width() != size || m_imageShadowBuffer->width()!=size) {
        ReleaseBuffers();
        m_imageBuffer = new QImage(size,size,QImage::Format_ARGB32);
        m_renderBuffer = new Buffer2D(size);
        m_backBuffer = new Buffer2D(size);
        m_imageShadowBuffer = new QImage(size, size,QImage::Format_ARGB32);
        m_starsBuffer = new Buffer2D(size);

        RenderStars();

    }

    m_imageBuffer->fill(QColor(0,0,0));
    m_backBuffer->fill(QVector3D(0,0,0));
    m_renderBuffer->fill(QVector3D(0,0,0));
    m_imageShadowBuffer->fill(QColor(0,0,0));


}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void RenderToBackBuffer(Renderer* renderer, double fTime, float fElapsedTime, void* pUserContext)
{
	ID3D11DeviceContext* pContext =  GetApp()->GetContext();
	
	// Something's wrong in the shader and the tri size is out by a factor of 2.  Why?!?
	g_pTriSizeVar->SetInt(2 * g_tessellatedTriWidth);

	const bool debugDrawPatches = false;
	g_DebugShowPatchesVar->SetBool(debugDrawPatches);

	const bool debugDrawTiles = false;
	g_DebugShowTilesVar->SetBool(debugDrawTiles);

	const float wireAlpha = 0.01f * (float)80;

	// Below 1.0, we fade the lines out with blending; above 1, we increase line thickness.
	if (wireAlpha < 1)
	{
		g_WireAlphaVar->SetFloat(wireAlpha);
		g_WireWidthVar->SetFloat(1);
	}
	else
	{
		g_WireAlphaVar->SetFloat(1);
		g_WireWidthVar->SetFloat(wireAlpha);
	}

	g_DetailNoiseVar->SetFloat(0.001f * (float)g_DetailNoiseScale);

	float samplesapcing = WORLD_SCALE * g_pTileRings[g_nRings-1]->outerWidth() / (float) COARSE_HEIGHT_MAP_SIZE;
	g_SampleSpacingVar->SetFloat(samplesapcing);

	// If the settings dialog is being shown, then render it instead of rendering the app's scene		

	BaseCamera* pCam = GetApp()->ActiveCam_;
	D3DXMATRIX mProj;
	D3DXMATRIX mView;

	const unsigned int size16 = sizeof(float) * 16;		 
	memcpy(&mView, pCam->getViewMatrix(), size16);
	memcpy(&mProj, pCam->getProjectionMatrix(), size16);


	SetViewport(pContext, g_BackBufferVP);

	D3DXMATRIX mViewCopy = mView;
	mViewCopy._41 = mViewCopy._42 = mViewCopy._43 = 0;
	D3DXMATRIX mWVP = StarWorldMatrix() * mViewCopy * mProj;
	if (!g_CheckForCracks)
		g_Skybox.D3D11Render(&mWVP, pContext);

	RenderStars(pContext, mViewCopy, mProj, g_ScreenSize);

	int vec[3] = { g_RidgeOctaves, g_fBmOctaves, g_TexTwistOctaves };
	g_pFractalOctavesTVar->SetIntVector(vec);

	// I'm still trying to figure out if the detail scale can be derived from any combo of ridge + twist.
	// I don't think this works well (nor does ridge+twist+fBm).  By contrast the relationship with fBm is
	// straightforward.  The -4 is a fudge factor that accounts for the frequency of the coarsest ocatve
	// in the pre-rendered detail map.
	const float DETAIL_UV_SCALE = powf(2.0f, std::max(g_RidgeOctaves, g_TexTwistOctaves) + g_fBmOctaves - 4.0f);
	g_DetailUVVar->SetFloatVector(D3DXVECTOR2(DETAIL_UV_SCALE, 1.0f/DETAIL_UV_SCALE));

	SetUVOffset(g_pUVOffsetTVar);

	/*ID3D11Query* pFreeQuery = FindFreeQuery();
	if (pFreeQuery)
		pContext->Begin(pFreeQuery);*/
		
	RenderTerrain(pContext, mProj, g_BackBufferVP);

	//if (pFreeQuery)
	//	pContext->End(pFreeQuery);

	//for (int i=0; i!=N_QUERIES; ++i)
	//{
	//	if (!g_FreePipelineQueries[i] && g_PipelineQueries[i])	// in use & exists
	//	{
	//		D3D11_QUERY_DATA_PIPELINE_STATISTICS stats;
	//		if (S_OK == pContext->GetData(g_PipelineQueries[i], &stats, sizeof(stats), D3D11_ASYNC_GETDATA_DONOTFLUSH))
	//		{
	//			g_PrimitivesRendered = stats.CInvocations;
	//			g_FreePipelineQueries[i] = g_PipelineQueries[i];	// Put back on free list.
	//		}
	//	}
	//}		
}