Ejemplo n.º 1
0
void DimArea(float x, float y, float w, float h, float alpha)
{
	// Menu/console/scoreboard backgrounds
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_ALPHA_TEST);

	// Blending to darken the area
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);

	glColor4f(0, 0, 0, alpha);
	DrawQuad(x, y, w, h);

	glColor4f(1, 1, 1, 1);
	glEnable(GL_ALPHA_TEST);
	glEnable(GL_TEXTURE_2D);
}
Ejemplo n.º 2
0
	void Transform(
		const Ptr<ShaderResourceView> & src,
		const Ptr<RenderTargetView> & dst,
		const Vector<ColorWriteMask, 4> & colorWriteMask,
		const float4 & srcRect,
		const float4 & dstRect,
		const Ptr<class Sampler> & sampler,
		const Ptr<DepthStencilView> & dsv )
	{
		auto rc = Global::GetRenderEngine()->GetRenderContext();

		std::map<String, String> macros;
		for (int32_t i = 0; i < 4; ++i)
		{
			auto & writeMask = colorWriteMask[i];
			String writeChannel = std::to_string(static_cast<uint32_t>(std::log2(static_cast<uint32_t>(writeMask))));
			macros["COLOR_CHANNEL_" + std::to_string(i)] = writeChannel;
		}

		auto transformPS = Shader::FindOrCreate<TransformPS>(macros);
		transformPS->SetSampler("transformSampler", sampler ? sampler : SamplerTemplate<>::Get());
		transformPS->SetSRV("srcTex", src);
		transformPS->Flush();

		auto srcTex = src->GetResource()->Cast<Texture>();
		float topLeftU = srcRect.x() / static_cast<float>(srcTex->GetDesc().width);
		float topLeftV = srcRect.y() / static_cast<float>(srcTex->GetDesc().height);
		float uvWidth  = srcRect.z() / static_cast<float>(srcTex->GetDesc().width);
		float uvHeight = srcRect.w() / static_cast<float>(srcTex->GetDesc().height);

		if (uvWidth == 0.0f)
			uvWidth = 1.0f;
		if (uvHeight == 0.0f)
			uvHeight = 1.0f;

		DrawQuad({ dst },
			dstRect.x(),
			dstRect.y(),
			dstRect.z(),
			dstRect.w(),
			topLeftU,
			topLeftV,
			uvWidth,
			uvHeight, 
			dsv);
	}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------
// @ Player::Render()
//-------------------------------------------------------------------------------
// Render stuff
//-------------------------------------------------------------------------------
void 
Player::Render()                                    
{   
    // Draw backdrop quad, which must also write the depth buffer
    IvRenderer::mRenderer->SetDepthWrite(true);
    IvRenderer::mRenderer->SetDepthTest(kLessEqualDepthTest);

    DrawQuad();

    // build 4x4 matrix for left (non-depth-buffered) teapot
    IvMatrix44 transform(mRotate);

    transform(0,0) *= mScale;
    transform(1,0) *= mScale;
    transform(2,0) *= mScale;
    transform(0,1) *= mScale;
    transform(1,1) *= mScale;
    transform(2,1) *= mScale;
    transform(0,2) *= mScale;
    transform(1,2) *= mScale;
    transform(2,2) *= mScale;
    transform(0,3) = mTranslate.x;
    transform(1,3) = mTranslate.y + 4.0f;
    transform(2,3) = mTranslate.z;
    
    IvSetWorldMatrix(transform);

    // draw non-depth-buffered teapot
    IvRenderer::mRenderer->SetDepthWrite(false);
    IvRenderer::mRenderer->SetDepthTest(kDisableDepthTest);
    
    IvDrawTeapot(kRed);
    
    // same as other teapot, but on the right side
    transform(1,3) = mTranslate.y - 4.0f;

    IvSetWorldMatrix(transform);
    
    // draw depth-buffered teapot
    IvRenderer::mRenderer->SetDepthWrite(true);
    IvRenderer::mRenderer->SetDepthTest(kLessEqualDepthTest);

    IvDrawTeapot(kBlue);
    
}   // End of Player::Render()
Ejemplo n.º 4
0
void Box::Draw()
{
	glPushMatrix();
	glMultMatrixf(GetTransform().Ref());
	glColor(Vec4(1, 1, 1, 1));
	DrawQuad(0, 1, 2, 3);
	DrawQuad(4, 5, 6, 7);
	DrawQuad(0, 1, 5, 4);
	DrawQuad(1, 2, 6, 5);
	DrawQuad(2, 3, 7, 6);
	DrawQuad(3, 0, 4, 7);
	glPopMatrix();
}
Ejemplo n.º 5
0
	PooledTextureRef SSR::BuildHZB(const Ptr<Texture> & depthTex)
	{
		auto texDesc = depthTex->GetDesc();
		texDesc.format = RENDER_FORMAT_R16_FLOAT;
		texDesc.bindFlag = TEXTURE_BIND_SHADER_RESOURCE | TEXTURE_BIND_RENDER_TARGET;
		texDesc.mipLevels = 0;

		auto hzb0Ref = TexturePool::Instance().FindFree({ TEXTURE_2D, texDesc });
		auto hzb1Ref = TexturePool::Instance().FindFree({ TEXTURE_2D, texDesc });

		auto hzb0 = hzb0Ref->Get()->Cast<Texture>();
		auto hzb1 = hzb1Ref->Get()->Cast<Texture>();

		Transform(
			depthTex->GetShaderResourceView(0, 1, 0, 1, false, RENDER_FORMAT_R24_UNORM_X8_TYPELESS), 
			hzb0Ref->Get()->Cast<Texture>()->GetRenderTargetView(0, 0, 1));

		auto rc = Global::GetRenderEngine()->GetRenderContext();

		auto ps = Shader::FindOrCreate<HZBBuildPS>();

		for (int32_t mipLevel = 1; mipLevel < hzb0->GetDesc().mipLevels; ++mipLevel)
		{
			auto & mipSize = hzb0->GetMipSize(mipLevel - 1);
			auto w = mipSize.x();
			auto h = mipSize.y();
			float4 screenSize = float4((float)w, (float)h, 1.0f / (float)w, 1.0f / (float)h);

			ps->SetScalar("screenSize", screenSize);
			ps->SetScalar("mipLevel", (float)(mipLevel - 1));
			ps->SetSRV("depthTex", hzb0->GetShaderResourceView());
			ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get());

			ps->Flush();

			auto & targetMipSize = hzb0->GetMipSize(mipLevel);

			DrawQuad({ hzb1->GetRenderTargetView(mipLevel, 0, 1) });

			hzb1->CopyTo(hzb0, mipLevel, 0, 0, 0, 0, mipLevel, 0);
		}

		return hzb0Ref;
	}
Ejemplo n.º 6
0
	void Fill(
		const float4 & color,
		const std::vector< Ptr<class RenderTargetView> > & rtvs,
		float topLeftX,
		float topLeftY,
		float width,
		float height,
		float topLeftU,
		float topLeftV,
		float uvWidth,
		float uvHeight,
		const Ptr<class DepthStencilView> & dsv)
	{
		auto ps = Shader::FindOrCreate<FillPS>();
		ps->SetScalar("fillColor", color);
		ps->Flush();

		DrawQuad(rtvs, topLeftX, topLeftY, width, height, topLeftU, topLeftV, uvWidth, uvHeight, dsv);
	}
Ejemplo n.º 7
0
	void ToneMapping::DoToneMapping(
		const Ptr<Texture> & scene,
		const Ptr<Texture> & bloomTex,
		const Ptr<Texture> & adaptedExposureScale,
		const Ptr<Texture> & lut,
		const Ptr<RenderTargetView> & target)
	{
		auto ps = Shader::FindOrCreate<ToneMappingPS>();
		ps->SetScalar("gamma", Global::GetRenderEngine()->GetGamma());
		ps->SetSRV("sceneTex", scene->GetShaderResourceView());
		ps->SetSRV("bloomTex", bloomTex->GetShaderResourceView());
		ps->SetSRV("adaptedExposureScale", adaptedExposureScale->GetShaderResourceView());
		ps->SetSRV("toneMappingLUT", lut->GetShaderResourceView());
		ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get());
		ps->SetSampler("linearSampler", SamplerTemplate<>::Get());
		ps->Flush();

		DrawQuad({ target });
	}
Ejemplo n.º 8
0
void winL::DrawLoose()
{
     glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR) ;
     glEnable(GL_BLEND);
     
     glPushMatrix();
     
     extern float rotN, rotM;
     
     glRotatef(-rotN,1,0,0);
     glRotatef(-rotM,0,1,0);     
     
     glTranslatef(0,20,0);
     
     loose.Bind();
     DrawQuad(60,40);
     glPopMatrix();
     
     glDisable(GL_BLEND);
}
Ejemplo n.º 9
0
	PooledTextureRef PostProcessVolumetricLight::Setup(const Ptr<Texture> & sceneTex, const Ptr<Texture> & linearDepthTex)
	{
		auto texDesc = sceneTex->GetDesc();
		texDesc.width /= 2;
		texDesc.height /= 2;
		auto resultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, texDesc });
		auto resultTex = resultTexRef->Get()->Cast<Texture>();

		auto ps = Shader::FindOrCreate<PPVolumeSetupPS>();

		ps->SetSRV("sceneTex", sceneTex->GetShaderResourceView());
		ps->SetSRV("linearDepthTex", linearDepthTex->GetShaderResourceView());

		ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get());

		ps->Flush();

		DrawQuad({ resultTex->GetRenderTargetView(0, 0, 1) });

		return resultTexRef;
	}
Ejemplo n.º 10
0
//---------------------------------------------------------------------------//
// Draw
//
//---------------------------------------------------------------------------//
void CFXImagen::Draw(CDisplayDevice *pDD, int iTextureTgt)
{
  pDD->SetRenderTarget(iTextureTgt);

  // Si la imagen no se cargó bien, salimos
  if (m_Imagen.iIDTex < 0) return;

  CTextura *pTex = g_pGestorMateriales->GetTextura(m_Imagen.iIDTex);
  TVector2  vPos = m_Imagen.vPos;
  TVector2  vSize;

  // Tamaño
  int iW = pDD->ViewportWidth ();
  int iH = pDD->ViewportHeight();
  switch (m_Imagen.iStretchMode)
  {
    case STRETCH_FILL:
      vSize.x = (float)iW;
      vSize.y = (float)iH;
      break;
    case STRETCH_TOW:
      vSize.x = (float)iW;
      vSize.y = (float)iW * pTex->GetHeight() / (float)pTex->GetWidth();
      break;
    case STRETCH_TOH:
      vSize.x = (float)iH * pTex->GetWidth () / (float)pTex->GetHeight();
      vSize.y = (float)iH;
      break;
  }
  
  // Quad con textura
  LPDIRECT3DDEVICE9 pD3D = pDD->GetD3DDevice();
  g_pGestorMateriales->SetTextura(m_Imagen.iIDTex, 0);

  // RenderStates especificos
  pDD->ApplyBasicShader();
  pDD->SetBilinearFiltering(false,false);

  DrawQuad(pDD, TVector2(vPos.x, vPos.y), TVector2(vPos.x+vSize.x, vPos.y+vSize.y));
}
Ejemplo n.º 11
0
void Render(void)
{
    glViewport(0, 0, winWidth, winHeight);
    
    if(hasError) {
        // If an OpenGL error has been encountered the screen will render solid green
        // Check the console output for error details
        glClearColor(0.0f, 1.0f, 0.0f, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    } else if(invalidFramebuffer) {
        // If the framebuffer is invalid but no OpenGL errors are indicated, the screen will render solid red
        glClearColor(1.0f, 0.0f, 0.0f, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    } else if(maxSizeReached) {
        // Render blue if we've successfully allocated a buffer of the maximum reported size without error
        glClearColor(0.0f, 0.0f, 1.0f, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    } else {
        // Steadily grow the multisample buffer size.
        // This is expected to fail at some point, since we should eventually hit memory or other limits.
        buffer->Resize(buffer->width * 1.2, buffer->height * 1.2);
        
        if(!hasError) {
            // Check the framebuffer to ensure it's valid and can be drawn to
            if(!buffer->Test()) {
                printf("Framebuffer appears to be invalid but no GL errors have been indicated. Should not get here!\n");
                invalidFramebuffer = true;
            }
            
            // Draws a quad into the center of the multisample buffer
            DrawQuad(buffer);
            
            // Draws the contents of the multisample buffer to the screen
            DrawBuffer(buffer);
        }
    }
    
    glutSwapBuffers();
    glutPostRedisplay();
}
Ejemplo n.º 12
0
	PooledTextureRef ToneMapping::BrightPass(const Ptr<Texture> & sceneTex, const Ptr<Texture> & adaptedExposureScale)
	{
		auto texDesc = sceneTex->GetDesc();
		texDesc.mipLevels = 1;
		texDesc.format = RENDER_FORMAT_R11G11B10_FLOAT;
		texDesc.bindFlag = TEXTURE_BIND_SHADER_RESOURCE | TEXTURE_BIND_RENDER_TARGET | TEXTURE_BIND_GENERATE_MIPS;
		auto brightPassTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, texDesc });
		auto brightPassTex = brightPassTexRef->Get()->Cast<Texture>();

		auto ps = Shader::FindOrCreate<BrightPassPS>();

		ps->SetScalar("brightPassThreshold", _brightPassThreshold);
		ps->SetSRV("sceneTex", sceneTex->GetShaderResourceView());
		ps->SetSRV("adaptedExposureScale", adaptedExposureScale->GetShaderResourceView());
		ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get());

		ps->Flush();

		DrawQuad({ brightPassTex->GetRenderTargetView(0, 0, 1) });

		return brightPassTexRef;
	}
Ejemplo n.º 13
0
	PooledTextureRef PostProcessVolumetricLight::RenderVolumetricLight(const float2 & lightPosUV, const Ptr<Texture> & setupTex)
	{
		auto resultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, setupTex->GetDesc() });
		auto resultTex = resultTexRef->Get()->Cast<Texture>();

		auto ps = Shader::FindOrCreate<RadialBlurPS>();

		ps->SetScalar("lightPosUV", lightPosUV);
		ps->SetScalar("density", _density);
		ps->SetScalar("intensity", _intensity);
		ps->SetScalar("decay", _decay);
		ps->SetScalar("frameCount", (uint32_t)Global::GetInfo()->frameCount);

		ps->SetSRV("sceneTex", setupTex->GetShaderResourceView());

		ps->SetSampler("linearSampler", SamplerTemplate<>::Get());

		ps->Flush();

		DrawQuad({ resultTex->GetRenderTargetView(0, 0, 1) });

		return resultTexRef;
	}
Ejemplo n.º 14
0
	void BilateralUpSampling(
		const Ptr<ShaderResourceView> & src,
		const Ptr<RenderTargetView> & dst,
		const Ptr<ShaderResourceView> & lowResDepthTex,
		const Ptr<ShaderResourceView> & highResDepthTex,
		float depthDiffThreshold)
	{
		auto srcTex = src->GetResource()->Cast<Texture>();

		auto ps = Shader::FindOrCreate<BilateralUpSamplingPS>();
		ps->SetScalar("texSize", srcTex->GetTexSize());
		ps->SetScalar("depthDiffThreshold", depthDiffThreshold);

		ps->SetSRV("lowResDepthTex", lowResDepthTex);
		ps->SetSRV("highResDepthTex", highResDepthTex);
		ps->SetSRV("upSamplingInTex", src);

		ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get());

		ps->Flush();

		DrawQuad({ dst });
	}
void Intialize()
{
	Velocity = CreatePPSurface(g_iWidth, g_iHeight, 2);
	Density = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Pressure = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Temperature = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Divergence = CreateSurface(g_iWidth, g_iHeight, 3);

	/*Velocity2 = CreatePPSurface(g_iWidth, g_iHeight, 2);
	Density2 = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Pressure2 = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Temperature2 = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Divergence2 = CreateSurface(g_iWidth, g_iHeight, 3);*/

	InitOps();
	DrawProgram = CreateProgram("Vertex.ver","Visualize.frag");
	Boundaries = CreateSurface(g_iWidth, g_iHeight, 3);
	CreateBoundaries(Boundaries, g_iWidth, g_iHeight);
	VertexQuad = DrawQuad();
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	ClearSurface(Temperature.Ping, AmbientTemperature);
	/*ClearSurface(Temperature2.Ping, AmbientTemperature);*/

}
Ejemplo n.º 16
0
	void RenderCommand::Execute( void ) const {
		switch ( type ) {

		case CommandType::DrawQuad: {
			DrawQuad( drawQuad );
		} break;

		case CommandType::DrawModel: {
			DrawModel( drawModel );
		} break;

		case CommandType::DrawParticles: {
			DrawParticles( drawParticles );
		} break;

		case CommandType::Screenshot: {
			Screenshot( screenshot );
		} break;

		default: {
		} break;

		}
	}
Ejemplo n.º 17
0
void osd_xenon_update_video(render_primitive_list &primlist) {
	currList = &primlist;
	pre_render();

	int minwidth, minheight;
	int newwidth, newheight;

	XenosSurface * fb = Xe_GetFramebufferSurface(g_pVideoDevice);

	// make that the size of our target
	xenos_target->set_bounds(fb->width, fb->height);

	xenos_target->compute_visible_area(fb->width, fb->height, (float) fb->width / (float) fb->height, xenos_target->orientation(), newwidth, newheight);

	n = 0;

	render_primitive *prim;
	for (prim = currList->first(); prim != NULL; prim = prim->next()) {
		switch (prim->type) {
			case render_primitive::LINE:
				DrawLine(prim);
				break;

			case render_primitive::QUAD:
				DrawQuad(prim);                        
				break;

			default:
				throw emu_fatalerror("Unexpected render_primitive type");
		}

		n++;
	}

	render();
}
Ejemplo n.º 18
0
void DrawTint()
{
	// Draw player redscreen, berserk, pickup
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glDisable(GL_ALPHA_TEST);

	extern int st_palette;

	glColor4f(0, 0, 0, 0);

	if(st_palette >= STARTREDPALS && st_palette < STARTREDPALS+NUMREDPALS)
		glColor4f(1, 0, 0, (st_palette-STARTREDPALS)/(float)NUMREDPALS);
	else if(st_palette >= STARTBONUSPALS && st_palette < STARTBONUSPALS+NUMBONUSPALS)
		glColor4f(0.5, 0.5, 0, 0.5f*(st_palette-STARTBONUSPALS)/(float)NUMBONUSPALS);
	else if(st_palette == RADIATIONPAL)
		glColor4f(0, 1, 0, 0.5f);

	DrawQuad(0, 0, 1, 1);

	glColor4f(1, 1, 1, 1);
	glEnable(GL_ALPHA_TEST);
	glEnable(GL_TEXTURE_2D);
}
Ejemplo n.º 19
0
void CGizmoTransformMove::Draw()
{
	ComputeScreenFactor();

	if (m_pMatrix)
	{
		CRenderingContext c(Manipulator()->GetRenderer(), true);
		c.UseProgram("model");
		c.SetUniform("bDiffuse", false);

		//glDisable(GL_DEPTH_TEST);
		tvector3 orig = m_pMatrix->GetTranslation();

		tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);


        if (mLocation == LOCATE_LOCAL)
        {
            axeX.TransformVector(*m_pMatrix);
		    axeY.TransformVector(*m_pMatrix);
		    axeZ.TransformVector(*m_pMatrix);
		    axeX.Normalize();
		    axeY.Normalize();
		    axeZ.Normalize();
        }




		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XZ), axeX, axeZ);
		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XY), axeX, axeY);
		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_YZ), axeY, axeZ);

		axeX*=GetScreenFactor();
		axeY*=GetScreenFactor();
		axeZ*=GetScreenFactor();

		// plan1
		if (m_MoveTypePredict != MOVE_X)
			DrawAxis(&c, orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1));
		else
			DrawAxis(&c, orig,axeX,axeY,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

		//plan2
		if (m_MoveTypePredict != MOVE_Y)
			DrawAxis(&c, orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(0,1,0,1));
		else
			DrawAxis(&c, orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

		//plan3
		if (m_MoveTypePredict != MOVE_Z)
			DrawAxis(&c, orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(0,0,1,1));
		else
			DrawAxis(&c, orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(1,1,1,1));
#if 0
#ifdef WIN32
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    GDD->GetD3D9Device()->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE );
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ZENABLE , D3DZB_TRUE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHATESTENABLE , FALSE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
#endif
	extern RenderingState_t GRenderingState;
	GRenderingState.mAlphaTestEnable = 0;
	GRenderingState.mZWriteEnable = 1;
	GRenderingState.mBlending = 0;
	GRenderingState.mCulling = 0;
	GRenderingState.mZTestType = 1;
#endif
/*

PSM_LVERTEX svVts[2];
	svVts[0].x = ptd.x;
    svVts[0].y = ptd.y;
    svVts[0].z = ptd.z;
    svVts[0].diffuse = 0xFFFFFFFF;

	svVts[1].x = ptd.x+10;
    svVts[1].y = ptd.y+10;
    svVts[1].z = ptd.z+10;
    svVts[1].diffuse = 0xFFFFFFFF;


    IDirect3DDevice9 *pDev = ((PSM_D3D9RenderDevice*)PSM_D3D9RenderDevice::GetInterfacePtr())->d3dDevice;
	pDev->DrawPrimitiveUP(D3DPT_LINESTRIP , 1, svVts, sizeof(PSM_LVERTEX));
    */
}
/*
		// debug
		glPointSize(20);
		glBegin(GL_POINTS);
		glVertex3fv(&ptd.x);
		glEnd();

		glEnable(GL_DEPTH_TEST);
*/

}
Ejemplo n.º 20
0
void RenderScreenGlowLowEnd(void)
{

     // check to see if we can render it.
	if (IEngineStudio.IsHardware() != 1){
		return;
	}

/*	AJH - This is redundant as the function now returns if r_glow!=2
	//check the cvar for the glow is on.
     if (CVAR_GET_FLOAT("r_glow") == 0)
          return;
*/
	 //check the mode is low-end
	if (CVAR_GET_FLOAT("r_glow") != 2)	//AJH don't need r_glowmode, use r_glow 0/1/2 instead
		return;

	if (!bGlowLowEndInitialised)
		InitScreenGlowLowEnd();

	if (!bGlowLowEndInitialised){ //if the initialisation dosent work for some reason
		gEngfuncs.Cvar_SetValue( "r_glow", 0 ); //AJH may as well set this here too.
		return;
	}
    // enable some OpenGL stuff
    glEnable(GL_TEXTURE_RECTANGLE_NV);
    glColor3f(1,1,1);
    glDisable(GL_DEPTH_TEST);

    // STEP 1: Grab the screen and put it into a texture
    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth, ScreenHeight, 0);

    // STEP 2: Set up an orthogonal projection
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, 1, 1, 0, 0.1, 100);

	// STEP 3: Render the current scene to a new, lower-res texture, darkening non-bright areas of the scene
    // by multiplying it with itself a few times.
    glViewport(0, 0, ScreenWidth/4, ScreenHeight/4);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);

    glBlendFunc(GL_DST_COLOR, GL_ZERO);

    glDisable(GL_BLEND);

    DrawQuad(ScreenWidth, ScreenHeight);

    glEnable(GL_BLEND);

    for (int i = 0; i < CVAR_GET_FLOAT("r_glowdark"); i++)
		DrawQuad(ScreenWidth, ScreenHeight);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiGlowTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

    // STEP 4: Blur the now darkened scene in the horizontal direction.
    float blurAlpha = 1 / (CVAR_GET_FLOAT("r_glowblur")*2 + 1);

    glColor4f(1,1,1,blurAlpha);

    glBlendFunc(GL_SRC_ALPHA, GL_ZERO);

    DrawQuad(ScreenWidth/4, ScreenHeight/4);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    for (i = 0; i <= CVAR_GET_FLOAT("r_glowblur"); i++) {
	    DrawQuad(ScreenWidth/4, ScreenHeight/4, -i, 0);
		DrawQuad(ScreenWidth/4, ScreenHeight/4, i, 0);
    }

    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

    // STEP 5: Blur the horizontally blurred image in the vertical direction.
    glBlendFunc(GL_SRC_ALPHA, GL_ZERO);

    DrawQuad(ScreenWidth/4, ScreenHeight/4);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    for (i = 0; i <= CVAR_GET_FLOAT("r_glowblur"); i++) {
		DrawQuad(ScreenWidth/4, ScreenHeight/4, 0, -i);
		DrawQuad(ScreenWidth/4, ScreenHeight/4, 0, i);
    }

    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

    // STEP 6: Combine the blur with the original image.
    glViewport(0, 0, ScreenWidth, ScreenHeight);

    glDisable(GL_BLEND);

    DrawQuad(ScreenWidth/4, ScreenHeight/4);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);

    for (i = 0; i < CVAR_GET_FLOAT("r_glowstrength"); i++) {
		DrawQuad(ScreenWidth/4, ScreenHeight/4);
    }

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);

    DrawQuad(ScreenWidth, ScreenHeight);

    // STEP 7: Restore the original projection and modelview matrices and disable rectangular textures.
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glDisable(GL_TEXTURE_RECTANGLE_NV);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
	glClear(GL_DEPTH_BUFFER_BIT);
}
Ejemplo n.º 21
0
void RenderScreenGlowShader(void)
{
	// check to see if we can render it.
	if (IEngineStudio.IsHardware() != 1){
		return;
	}
/*	AJH - This is redundant as the function now returns if r_glow!=1
	//check the cvar for the glow is on.
    if (CVAR_GET_FLOAT("r_glow") == 0)
         return;
*/
	//if the mode isn't shader then return.
	if (CVAR_GET_FLOAT("r_glow") != 1)
		  return;

    if (!bGlowShaderInitialised)
		InitScreenGlowShader();

	if (!bGlowShaderInitialised){ //if the initialisation dosent work for some reason
		gEngfuncs.Cvar_SetValue( "r_glow", 0 );
		return;
	}

    // STEP 1: Grab the screen and put it into a texture
    pglActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_NV);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth, ScreenHeight, 0);

    // STEP 2: Set up an orthogonal projection
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, 1, 1, 0, 0.1, 100);

    glColor3f(1,1,1);

    // STEP 3: Initialize Cg programs and parameters for darken
    cgGLEnableProfile(g_cgVertProfile);
    cgGLEnableProfile(g_cgFragProfile);

    cgGLBindProgram(g_cgVP_GlowDarken);
    cgGLBindProgram(g_cgFP_GlowDarken);

    cgGLSetStateMatrixParameter(g_cgpVP0_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

    // STEP 4: Render the current scene texture to a new, lower-res texture, darkening non-bright areas of the scene
    glViewport(0, 0, ScreenWidth/4, ScreenHeight/4);
    pglActiveTextureARB(GL_TEXTURE0_ARB);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex);

    DrawQuad(ScreenWidth, ScreenHeight);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiBlurTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

	// STEP 5: Initialise Cg programs and parameters for blurring
	cgGLBindProgram(g_cgVP_GlowBlur);
	cgGLBindProgram(g_cgFP_GlowBlur);

	cgGLSetStateMatrixParameter(g_cgpVP1_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

    // STEP 6: Apply blur
    int iNumBlurSteps = CVAR_GET_FLOAT("r_glowblur"); //use new CVAR --FragBait0
    for (int i = 0; i < iNumBlurSteps; i++) {
         DoBlur(g_uiBlurTex, g_uiBlurTex, ScreenWidth/4, ScreenHeight/4, ScreenWidth/4, ScreenHeight/4, 1, 0);
         DoBlur(g_uiBlurTex, g_uiBlurTex, ScreenWidth/4, ScreenHeight/4, ScreenWidth/4, ScreenHeight/4, 0, 1);
    }

    // STEP 7: Set up Cg for combining blurred glow with original scene
    cgGLBindProgram(g_cgVP_GlowCombine);
    cgGLBindProgram(g_cgFP_GlowCombine);

    cgGLSetStateMatrixParameter(g_cgpVP2_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

    pglActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_NV);
    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex);

    pglActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_NV);
    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiBlurTex);

    // STEP 8: Do the combination, rendering to the screen without grabbing it to a texture
    glViewport(0, 0, ScreenWidth, ScreenHeight);

	DrawQuad(ScreenWidth/4, ScreenHeight/4);

    // STEP 9: Restore the original projection and modelview matrices and disable rectangular textures on all units
	glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    cgGLDisableProfile(g_cgVertProfile);
    cgGLDisableProfile(g_cgFragProfile);

    pglActiveTextureARB(GL_TEXTURE0_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE2_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE3_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE0_ARB);
	glClear(GL_DEPTH_BUFFER_BIT);
}
Ejemplo n.º 22
0
	void Update( real64_t dt ) {
		const vector4 clearColour = {
			r_clear->GetReal32( 0 ),
			r_clear->GetReal32( 1 ),
			r_clear->GetReal32( 2 ),
			r_clear->GetReal32( 3 )
		};

		Backend::SetBlendFunction( Backend::BlendFunc::SourceAlpha, Backend::BlendFunc::OneMinusSourceAlpha );

		for ( auto *view : views ) {
			if ( r_skipRender->GetInt32() & (1 << static_cast<uint32_t>( view->is2D )) ) {
				continue;
			}

			// bind the view's FBO
			view->Bind();

			Backend::ClearBuffer( true, true, vector4{ 0.0f, 0.0f, 0.0f, 0.0f } );

			view->PreRender( dt );
			while ( !view->renderCommands.empty() ) {
				const auto &cmd = view->renderCommands.front();

				cmd.Execute();

				view->renderCommands.pop();
			}
			view->PostRender( dt );
		}

		Framebuffer::BindDefault();
		Backend::ClearBuffer( true, true, clearColour );
		Backend::SetBlendFunction( Backend::BlendFunc::SourceAlpha, Backend::BlendFunc::OneMinusSourceAlpha );

		for ( const auto &view : views ) {
			Material compositeMaterial = {};
			compositeMaterial.shaderProgram = compositeShader;

			Material::SamplerBinding colourBinding = {};
				colourBinding.unit = 0;
				colourBinding.uniform = "u_sceneTexture";
				colourBinding.texture = const_cast<Texture *>( view->fbo->colourTextures[0] );
			compositeMaterial.samplerBindings.push_back( colourBinding );

			DrawQuadCommand cmd = {};
				cmd.pos[0] = -1.0f;
				cmd.pos[1] = 1.0f;
				cmd.size[0] = 2.0f;
				cmd.size[1] = -2.0f;
				cmd.st1[0] = 0.0f;
				cmd.st1[1] = 1.0f;
				cmd.st2[0] = 1.0f;
				cmd.st2[1] = 0.0f;
				cmd.material = &compositeMaterial;
				cmd.colour = vector4{ 1.0f, 1.0f, 1.0f, 1.0f };
			DrawQuad( cmd );
		}

		GLenum lastError = glGetError();
		if ( lastError != GL_NO_ERROR ) {
			console.Print( PrintLevel::Developer, "Unhandled OpenGL errors for this frame:\n", lastError );
			int i = 1;
			do {
				console.Print( PrintLevel::Developer, "  %i: %i\n", i++, lastError );
				lastError = glGetError();
			} while ( lastError );
		}

		SDL_GL_SwapWindow( window );
	}
Ejemplo n.º 23
0
	void PrelightPipeline::Execute(const std::shared_ptr<SceneManager> &sceneManager)
	{
		// pre
		m_DrawCall = 0;
		m_CurrentCamera = nullptr;
		m_CurrentShader = nullptr;
		SortPassByIndex();

		// find visible nodes, 1 cam 1 query
		std::unordered_map<std::string, RenderQuery::Ptr> queries;

		for (auto pair : m_PassMap)
		{
			auto pass = pair.second;
			auto camNode = pass->GetCameraNode();

			if (camNode == nullptr)
			{
				LOGW << "Camera for pass " + pass->GetName() + " not found!";
				continue;
			}

			auto it = queries.find(camNode->GetName());
			if (it != queries.end())
				continue;

			RenderQuery::Ptr query = RenderQuery::Create();

			sceneManager->GetRenderQuery(camNode->GetComponent<Camera>()->GetFrustum(), query);
			query->Sort(camNode->GetWorldPosition(), false);

			queries.emplace(camNode->GetName(), query);
		}

		// draw passes

		for (unsigned int i = 0; i < m_SortedPasses.size(); i++)
		{
			auto passName = m_SortedPasses[i];
			auto pass = m_PassMap[passName];

			auto drawMode = pass->GetDrawMode();

			m_CurrentCamera = pass->GetCameraNode();
			m_CurrentShader = pass->GetFirstShader();

			if (m_CurrentCamera == nullptr)
				continue;

			auto query = queries[m_CurrentCamera->GetName()];

			pass->Bind();

			if (drawMode == DrawMode::RENDERABLE)
			{
				for (const auto &node : query->OpaqueNodes)
					DrawRenderable(pass, node);
			}
			else if (drawMode == DrawMode::LIGHT)
			{
				glDepthMask(GL_FALSE);

				for (const auto &node : query->LightNodes)
					DrawLight(pass, node);

				glDepthMask(GL_TRUE);
				glEnable(GL_DEPTH_TEST);
				glCullFace(GL_BACK);
			}
			else 
			{
				DrawQuad(pass);
			}

			pass->UnBind();
		}

		// post
		m_CurrentCamera = nullptr;
		m_CurrentShader = nullptr;
	}
Ejemplo n.º 24
0
void C2DRenderUtils::RenderTest_Text( float fTime, const ColorF& color )
{
    IFFont *deffont = gEnv->pCryFont->GetFont("default");
    SetFont(deffont);

    ColorF colAligned = color;
    colAligned.a = 1.0f;
    // wchar wrapped
    const float maxWidth = 25.0f;
    ColorF trans = color;
    trans.a *= 0.5;

    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "TLWRAPPED", trans, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP );
    DrawWrappedText( 800.f,   0.f, maxWidth, 20.f, 20.f, "TRWRAPPED", trans, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP );
    DrawWrappedText( 400.f,   0.f, maxWidth, 20.f, 20.f, "TCWRAPPED", trans, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawWrappedText( 800.f, 600.f, maxWidth, 20.f, 20.f, "BRWRAPPED", trans, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText(   0.f, 600.f, maxWidth, 20.f, 20.f, "BLWRAPPED", trans, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText( 400.f, 600.f, maxWidth, 20.f, 20.f, "BCWRAPPED", trans, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText( 800.f, 300.f, maxWidth, 20.f, 20.f, "MRWRAPPED", trans, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText(   0.f, 300.f, maxWidth, 20.f, 20.f, "MLWRAPPED", trans, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText( 400.f, 300.f, maxWidth, 20.f, 20.f, "MCWRAPPED", trans, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "TLWRAPPEDA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "TRWRAPPEDA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "TCWRAPPEDA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "BRWRAPPEDA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "BLWRAPPEDA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "BCWRAPPEDA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "MRWRAPPEDA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "MLWRAPPEDA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER );
    DrawWrappedText(   0.f,   0.f, maxWidth, 20.f, 20.f, "MCWRAPPEDA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER );

    // char
    /*
    DrawText(   0.f,   0.f, 20.f, 20.f, "TLDT", color, UIDRAWHORIZONTAL_LEFT, UIDRAWVERTICAL_TOP );
    DrawText( 800.f,   0.f, 20.f, 20.f, "TRDT", color, UIDRAWHORIZONTAL_RIGHT, UIDRAWVERTICAL_TOP );
    DrawText( 400.f,   0.f, 20.f, 20.f, "TopCenterDT", color, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawText( 800.f, 600.f, 20.f, 20.f, "BRDT", color, UIDRAWHORIZONTAL_RIGHT, UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f, 600.f, 20.f, 20.f, "BLDT", color, UIDRAWHORIZONTAL_LEFT, UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f, 300.f, 20.f, 20.f, "BottomCenterDT", color, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawText( 800.f, 300.f, 20.f, 20.f, "MRDT", color, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f, 300.f, 20.f, 20.f, "MLDT", color, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawText( 400.f, 300.f, 20.f, 20.f, "MiddleCenterDT", color, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    */
    float posx = 0.0f, posy = 0.f;
    DrawText(   posx,   posy, 20.f, 20.f, "TLDTA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP );
    DrawText(   posx,   posy, 20.f, 20.f, "TRDTA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP );
    DrawText(   posx,   posy+20.0f, 20.f, 20.f, "TopCenterDTA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawText(   posx,   posy, 20.f, 20.f, "BRDTA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawText(   posx,   posy, 20.f, 20.f, "BLDTA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawText(   posx,   posy-20.0f, 20.f, 20.f, "BottomCenterDTA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawText(   posx,   posy, 20.f, 20.f, "MRDTA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER );
    DrawText(   posx,   posy, 20.f, 20.f, "MLDTA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER );
    DrawText(   posx,   posy+20.0f, 20.f, 20.f, "MiddleCenterDTA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER );

    posx = 800.0f/3.0f;
    posy = 600.0f/3.0f;

    {
        ColorF dbgColour(1.f, 1.f, 1.f, 0.2f);
        CUIManager* pHud = g_pGame->GetUI();
        ScreenLayoutManager* pLayoutManager = pHud->GetLayoutManager();
        ScreenLayoutStates prevStates = pLayoutManager->GetState();
        gEnv->pRenderer->SetState(GS_NODEPTHTEST);
        DrawQuad(  posx,    0.f,   1.f,  600.f, dbgColour); // T2B
        DrawQuad(     0.f, posy, 800.f,    1.f, dbgColour); // L2R
        pLayoutManager->SetState(prevStates);
    }

    // pivot align
    DrawText(   posx,   posy, 20.f, 20.f, "TLDTPA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP );
    DrawText(   posx,   posy, 20.f, 20.f, "TRDTAPA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,  UIDRAWVERTICAL_TOP );
    posy+=20.0f;
    DrawText(   posx,   posy, 20.f, 20.f, "MRDTPA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_LEFT,  UIDRAWVERTICAL_TOP );
    DrawText(   posx,   posy, 20.f, 20.f, "MLDTPA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP  );
    posy+=20.0f;
    DrawText(   posx,   posy, 20.f, 20.f, "BRDTPA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_LEFT,  UIDRAWVERTICAL_TOP  );
    DrawText(   posx,   posy, 20.f, 20.f, "BLDTPA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP  );
    posy+=20.0f;
    DrawText(   posx,   posy,       20.f, 20.f, "TopCenterDTAPA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT, UIDRAWVERTICAL_TOP );
    DrawText(   posx,   posy+20.f,  20.f, 20.f, "MiddleCenterDTPA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_LEFT, UIDRAWVERTICAL_TOP  );
    DrawText(   posx,   posy+40.0f, 20.f, 20.f, "BottomCenterDTPA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_LEFT, UIDRAWVERTICAL_TOP  );

    // screen align
    DrawText(   0.f,   0.f, 20.f, 20.f, "TLDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP );
    DrawText(   0.f,   0.f, 20.f, 20.f, "TRDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP );
    DrawText(   0.f,   0.f, 20.f, 20.f, "TopCenterDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawText(   0.f,   0.f, 20.f, 20.f, "BRDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "BLDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "BottomCenterDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "MRDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER );
    DrawText(   0.f,   0.f, 20.f, 20.f, "MLDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER );
    DrawText(   0.f,   0.f, 20.f, 20.f, "MiddleCenterDTSA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER );

    // wchar
    DrawText(   0.f,   0.f, 20.f, 20.f, "TLDW", color, UIDRAWHORIZONTAL_LEFT,  UIDRAWVERTICAL_TOP );
    DrawText( 800.f,   0.f, 20.f, 20.f, "TRDW", color, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP );
    DrawText( 400.f,   0.f, 20.f, 20.f, "TCDW", color, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawText( 800.f, 600.f, 20.f, 20.f, "BRDW", color, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f, 600.f, 20.f, 20.f, "BLDW", color, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawText( 400.f, 600.f, 20.f, 20.f, "BCDW", color, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawText( 800.f, 300.f, 20.f, 20.f, "MRDW", trans, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f, 300.f, 20.f, 20.f, "MLDW", trans, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawText( 400.f, 300.f, 20.f, 20.f, "MCDW", trans, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "TLDWA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_TOP );
    DrawText(   0.f,   0.f, 20.f, 20.f, "TRDWA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_TOP );
    DrawText(   0.f,   0.f, 20.f, 20.f, "TCDWA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP,    UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP );
    DrawText(   0.f,   0.f, 20.f, 20.f, "BRDWA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "BLDWA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "BCDWA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_BOTTOM );
    DrawText(   0.f,   0.f, 20.f, 20.f, "MRDWA", colAligned, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_RIGHT,  UIDRAWVERTICAL_CENTER );
    DrawText(   0.f,   0.f, 20.f, 20.f, "MLDWA", colAligned, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_LEFT,   UIDRAWVERTICAL_CENTER );
    DrawText(   0.f,   0.f, 20.f, 20.f, "MCDWA", colAligned, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_CENTER );

    for( int i=0; i<gEnv->pRenderer->GetWidth(); i+=10)
    {
        for( int j=0; j<gEnv->pRenderer->GetHeight(); j+=10)
        {
            ColorF mcColor( (float)i/(float)gEnv->pRenderer->GetWidth(), (float)j/(float)gEnv->pRenderer->GetHeight(),1.0f,0.2f );
            DrawText( (float)i, (float)j, 20.f, 20.f, "ixjabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", mcColor );
        }
    }
}
Ejemplo n.º 25
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES3AlphaBlend::RenderScene()
{
	// Do our clear
	glClear(GL_COLOR_BUFFER_BIT);

	// Use the loaded shader program
	glUseProgram(m_ShaderProgram.uiId);

	// Draws the background
	glDisable(GL_BLEND);
	DrawQuad(-1, -1, +1, +1, m_uiTexBackground);

	/*
		Prepares to draw the different blend modes, activate blending.
		Now we can use glBlendFunc() to specify the blending mode wanted.
	*/
	glEnable(GL_BLEND);

	// Prepares the variables used to divide the screen in NUM_BLEND x NUM_BLEND rectangles
	float fX1 = -1;
	float fX2 = +1;
	float fY1 = -1;
	float fY2 = +.85f;
	float fPosX = fX1;
	float fPosY = fY1;
	float fMarginX = .25f;
	float fMarginY = .25f;
	float fBlockWidth = ((fX2-fX1) - fMarginX * 3.0f) * 0.5f;
	float fBlockHeight= ((fY2-fY1) - fMarginY * 3.0f) * 0.5f;

	//Position and draw the first quad (Transparency)
	fPosY = fY2 - fBlockHeight - fMarginY;
	fPosX += fMarginX;

	//Set up the blend function for this quad
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	DrawQuad(fPosX, fPosY, fPosX + fBlockWidth, fPosY + fBlockHeight, m_uiTexForeground);

	//Draw the text for this quad to the screen.
	m_Print3D.Print3D(18,12, 0.6f, 0xff00ffff, "Transparency");
	m_Print3D.Print3D(7,16, 0.6f, 0xff00ffff, "(SRC_ALPHA, 1 - SRC_ALPHA)");

	//Position and draw the second quad (Additive)
	fPosX += fMarginX + fBlockWidth;
	glBlendFunc(GL_ONE, GL_ONE);
	DrawQuad(fPosX, fPosY, fPosX + fBlockWidth, fPosY + fBlockHeight, m_uiTexForeground);

	m_Print3D.Print3D(66,12, 0.6f, 0xff00ffff, "Additive");
	m_Print3D.Print3D(64,16, 0.6f, 0xff00ffff, "(ONE, ONE)");

	//Position and draw the third quad (Modulate)
	fPosX = fX1 + fMarginX;
	fPosY -= fMarginY + fBlockHeight;

	glBlendFunc(GL_DST_COLOR, GL_ZERO);
	DrawQuad(fPosX, fPosY, fPosX + fBlockWidth, fPosY + fBlockHeight, m_uiTexForeground);

	m_Print3D.Print3D(22,52, 0.6f, 0xff00ffff, "Modulate");
	m_Print3D.Print3D(14,56, 0.6f, 0xff00ffff, "(DST_COLOR, ZERO)");

	//Position and draw the fourth quad (Modulate X 2)
	fPosX += fMarginX + fBlockWidth;
	glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
	DrawQuad(fPosX, fPosY, fPosX + fBlockWidth, fPosY + fBlockHeight, m_uiTexForeground);

	m_Print3D.Print3D(64,52, 0.6f, 0xff00ffff, "Modulate X2");
	m_Print3D.Print3D(53,56, 0.6f, 0xff00ffff, "(DST_COLOR, SRC_COLOR)");

	/* Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools */
	m_Print3D.DisplayDefaultTitle("AlphaBlend", "", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}
Ejemplo n.º 26
0
void OpenGL_Blitter::DrawLinearIP(const unsigned UsingIP, const unsigned rotated, const MDFN_Rect *tex_src_rect, const MDFN_Rect *dest_rect, const uint32 tmpwidth, const uint32 tmpheight)
{
 MDFN_Rect tmp_sr = *tex_src_rect;
 MDFN_Rect tmp_dr = *dest_rect;
 float tmp_sc[4][2];
 int tmp_dc[4][2];

 int32 start_pos;
 int32 bound_pos;
 bool rotate_side = (rotated == MDFN_ROTATE90 || rotated == MDFN_ROTATE270);
 bool reversi;
 bool dr_y;
 bool sr_y;

 if((UsingIP == VIDEOIP_LINEAR_Y) ^ rotate_side)
 {
  start_pos = dest_rect->x;
  bound_pos = dest_rect->x + dest_rect->w;
  dr_y = false;
  sr_y = rotate_side;
 }
 else
 {
  start_pos = dest_rect->y;
  bound_pos = dest_rect->y + dest_rect->h;
  dr_y = true;
  sr_y = !rotate_side;
 }

 //printf("Start: %4d, Bound: %4d sr_y=%d, reversi=%d\n", start_pos, bound_pos, sr_y, reversi);

 reversi = (rotated == MDFN_ROTATE270 && UsingIP == VIDEOIP_LINEAR_X) || (rotated == MDFN_ROTATE90 && UsingIP == VIDEOIP_LINEAR_Y);

 for(int i = start_pos; i < bound_pos; i++)
 {
  int sr_goon = i - start_pos;

  if(dr_y)
  {
   tmp_dr.y = i;
   tmp_dr.h = 1;
  }
  else
  {
   tmp_dr.x = i;
   tmp_dr.w = 1;
  }

  if(reversi)
   sr_goon = (bound_pos - start_pos) - 1 - sr_goon;

  if(sr_y)
  {
   tmp_sr.y = sr_goon * tex_src_rect->h / (rotate_side ? dest_rect->w : dest_rect->h);
   tmp_sr.h = 1;
  }
  else
  {
   tmp_sr.x = sr_goon * tex_src_rect->w / (rotate_side ? dest_rect->h : dest_rect->w);
   tmp_sr.w = 1;
  }

  MakeSourceCoords(&tmp_sr, tmp_sc, tmpwidth, tmpheight);
  MakeDestCoords(&tmp_dr, tmp_dc, rotated);

  DrawQuad(tmp_sc, tmp_dc);
 }
}
void FRCPassPostProcessWeightedSampleSum::Process(FRenderingCompositePassContext& Context)
{
	const FSceneView& View = Context.View;

	FRenderingCompositeOutput *Input = PassInputs[0].GetOutput();

	// input is not hooked up correctly
	check(Input);

	const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0);

	// input is not hooked up correctly
	check(InputDesc);

	const FSceneViewFamily& ViewFamily = *(View.Family);

	FIntPoint SrcSize = InputDesc->Extent;
	FIntPoint DestSize = PassOutputs[0].RenderTargetDesc.Extent;

	// e.g. 4 means the input texture is 4x smaller than the buffer size
	FIntPoint SrcScaleFactor = GSceneRenderTargets.GetBufferSizeXY() / SrcSize;
	FIntPoint DstScaleFactor = GSceneRenderTargets.GetBufferSizeXY() / DestSize;

	TRefCountPtr<IPooledRenderTarget> InputPooledElement = Input->RequestInput();

	check(!InputPooledElement->IsFree());

	const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context);

	FVector2D InvSrcSize(1.0f / SrcSize.X, 1.0f / SrcSize.Y);
	// we scale by width because FOV is defined horizontally
	float SrcSizeForThisAxis = View.ViewRect.Width() / (float)SrcScaleFactor.X;

	// in texel (input resolution), /2 as we use the diameter, 100 as we use percent
	float EffectiveBlurRadius = SizeScale * SrcSizeForThisAxis  / 2 / 100.0f;

	FVector2D BlurOffsets[MAX_FILTER_SAMPLES];
	FLinearColor BlurWeights[MAX_FILTER_SAMPLES];
	FVector2D OffsetAndWeight[MAX_FILTER_SAMPLES];

	const auto FeatureLevel = Context.View.GetFeatureLevel();

	// compute 1D filtered samples
	uint32 MaxNumSamples = GetMaxNumSamples(FeatureLevel);

	uint32 NumSamples = Compute1DGaussianFilterKernel(FeatureLevel, EffectiveBlurRadius, OffsetAndWeight, MaxNumSamples, FilterShape, CrossCenterWeight);

	SCOPED_DRAW_EVENTF(Context.RHICmdList, PostProcessWeightedSampleSum, TEXT("PostProcessWeightedSampleSum#%d"), NumSamples);

	// compute weights as weighted contributions of the TintValue
	for(uint32 i = 0; i < NumSamples; ++i)
	{
		BlurWeights[i] = TintValue * OffsetAndWeight[i].Y;
	}

	SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef());

	Context.SetViewportAndCallRHI(0, 0, 0.0f, DestSize.X, DestSize.Y, 1.0f);

	// set the state
	Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI());
	Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI());
	Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI());

	const FTextureRHIRef& FilterTexture = InputPooledElement->GetRenderTargetItem().ShaderResourceTexture;

	FRenderingCompositeOutput *Input1 = PassInputs[1].GetOutput();

	uint32 CombineMethodInt = 0;

	if(CombineMethod == EFCM_MaxMagnitude)
	{
		CombineMethodInt = 2;
	}

	// can be optimized
	FTextureRHIRef AdditiveTexture;

	if(Input1)
	{
		TRefCountPtr<IPooledRenderTarget> InputPooledElement1 = Input1->RequestInput();
		AdditiveTexture = InputPooledElement1->GetRenderTargetItem().ShaderResourceTexture;

		check(CombineMethod == EFCM_Weighted);

		CombineMethodInt = 1;
	}

	bool bDoFastBlur = DoFastBlur();

	if (FilterShape == EFS_Horiz)
	{
		float YOffset = bDoFastBlur ? (InvSrcSize.Y * 0.5f) : 0.0f;
		for (uint32 i = 0; i < NumSamples; ++i)
		{
			BlurOffsets[i] = FVector2D(InvSrcSize.X * OffsetAndWeight[i].X, YOffset);
		}
	}
	else
	{
		float YOffset = bDoFastBlur ? -(InvSrcSize.Y * 0.5f) : 0.0f;
		for (uint32 i = 0; i < NumSamples; ++i)
		{
			BlurOffsets[i] = FVector2D(0, InvSrcSize.Y * OffsetAndWeight[i].X + YOffset);
		}
	}

	FShader* VertexShader = nullptr;
	SetFilterShaders(
		Context.RHICmdList,
		FeatureLevel,
		TStaticSamplerState<SF_Bilinear,AM_Border,AM_Border,AM_Clamp>::GetRHI(),
		FilterTexture,
		AdditiveTexture,
		CombineMethodInt,
		BlurOffsets,
		BlurWeights,
		NumSamples,
		&VertexShader
		);

	bool bRequiresClear = true;
	// check if we have to clear the whole surface.
	// Otherwise perform the clear when the dest rectangle has been computed.
	if (FeatureLevel == ERHIFeatureLevel::ES2 || FeatureLevel == ERHIFeatureLevel::ES3_1)
	{
		Context.RHICmdList.Clear(true, FLinearColor(0, 0, 0, 0), false, 1.0f, false, 0, FIntRect());
		bRequiresClear = false;
	}

	FIntRect SrcRect =  FIntRect::DivideAndRoundUp(View.ViewRect, SrcScaleFactor);
	FIntRect DestRect = FIntRect::DivideAndRoundUp(View.ViewRect, DstScaleFactor);

	DrawQuad(Context.RHICmdList, bDoFastBlur, SrcRect, DestRect, bRequiresClear, DestSize, SrcSize, VertexShader);

	Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams());
}
Ejemplo n.º 28
0
void cPrimitives::DrawQuad( const eeQuad2f& q, const eeFloat& OffsetX, const eeFloat& OffsetY ) {
	DrawQuad( q, mColor, mColor, mColor, mColor, OffsetX, OffsetY );
}
Ejemplo n.º 29
0
void OpenGL_Blitter::Blit(MDFN_Surface *src_surface, const MDFN_Rect *src_rect, const MDFN_Rect *dest_rect, const MDFN_Rect *original_src_rect, int InterlaceField, int UsingIP, int rotated)
{
 MDFN_Rect tex_src_rect = *src_rect;
 float src_coords[4][2];
 int dest_coords[4][2];
 unsigned int tmpwidth;
 unsigned int tmpheight;
 uint32 *src_pixies;

 if(shader)
 {
  if(shader->ShaderNeedsBTIP())
   UsingIP = VIDEOIP_BILINEAR;
  else
   UsingIP = VIDEOIP_OFF;
 }

 if(src_rect->w == 0 || src_rect->h == 0 || dest_rect->w == 0 || dest_rect->h == 0 || original_src_rect->w == 0 || original_src_rect->h == 0)
 {
  printf("[BUG] OpenGL blitting nothing? --- %d:%d %d:%d %d:%d\n", src_rect->w, src_rect->h, dest_rect->w, dest_rect->h, original_src_rect->w, original_src_rect->h);
  return;
 }


 src_pixies = src_surface->pixels + tex_src_rect.x + tex_src_rect.y * src_surface->pitchinpix;
 tex_src_rect.x = 0;
 tex_src_rect.y = 0;

 MakeDestCoords(dest_rect, dest_coords, rotated);

 p_glBindTexture(GL_TEXTURE_2D, textures[0]);
 p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, UsingIP ? GL_LINEAR : GL_NEAREST);
 p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, UsingIP ? GL_LINEAR : GL_NEAREST);

 if(SupportNPOT)
 {
  tmpwidth = src_rect->w;
  tmpheight = src_rect->h;

  if(tmpwidth != last_w || tmpheight != last_h)
  {
   p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tmpwidth, tmpheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
   last_w = tmpwidth;
   last_h = tmpheight;
  }
 }
 else
 {
  bool ImageSizeChange = FALSE;

  tmpwidth = round_up_pow2(src_rect->w);
  tmpheight = round_up_pow2(src_rect->h);

  // If the required GL texture size has changed, resize the texture! :b
  if(tmpwidth != round_up_pow2(last_w) || tmpheight != round_up_pow2(last_h))
  {
   p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tmpwidth, tmpheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
   ImageSizeChange = TRUE;
  }
 
  // If the dimensions of our image stored in the texture have changed...
  if(src_rect->w != last_w || src_rect->h != last_h)
   ImageSizeChange = TRUE;

  // Only clean up if we're using pixel shaders and/or bilinear interpolation
  if(ImageSizeChange && (shader || UsingIP))
  {
   uint32 neo_dbs = DummyBlackSize;

   if(src_rect->w != tmpwidth && neo_dbs < src_rect->h)
    neo_dbs = src_rect->h;

   if(src_rect->h != tmpheight && neo_dbs < src_rect->w)
    neo_dbs = src_rect->w;

   if(neo_dbs != DummyBlackSize)
   {
    //printf("Realloc: %d\n", neo_dbs);
    if(DummyBlack)
     MDFN_free(DummyBlack);

    if((DummyBlack = (uint32 *)MDFN_calloc(neo_dbs, sizeof(uint32), _("OpenGL dummy black texture data"))))
     DummyBlackSize = neo_dbs;
    else
     DummyBlackSize = 0;
   }

   //printf("Cleanup: %d %d, %d %d\n", src_rect->w, src_rect->h, tmpwidth, tmpheight);

   if(DummyBlack) // If memory allocation failed for some reason, don't clean the texture. :(
   {
    if(src_rect->w < tmpwidth)
    {
     //puts("X");
     p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 1);
     p_glTexSubImage2D(GL_TEXTURE_2D, 0, src_rect->w, 0, 1, src_rect->h, GL_RGBA, GL_UNSIGNED_BYTE, DummyBlack);
    }
    if(src_rect->h < tmpheight)
    {
     //puts("Y");
     p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_rect->w);
     p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, src_rect->h, src_rect->w, 1, GL_RGBA, GL_UNSIGNED_BYTE, DummyBlack);
    }
   } // end if(DummyBlack)

  }

  last_w = src_rect->w;
  last_h = src_rect->h;
 }

 MakeSourceCoords(&tex_src_rect, src_coords, tmpwidth, tmpheight);

 if(shader)
  shader->ShaderBegin(gl_screen_w, gl_screen_h, src_rect, dest_rect, tmpwidth, tmpheight, round((double)tmpwidth * original_src_rect->w / src_rect->w), round((double)tmpheight * original_src_rect->h / src_rect->h), rotated);

 p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_surface->pitchinpix);

 p_glTexSubImage2D(GL_TEXTURE_2D, 0, tex_src_rect.x, tex_src_rect.y, tex_src_rect.w, tex_src_rect.h, PixelFormat, PixelType, src_pixies);

 //
 // Draw texture
 //
#ifdef MDFN_TRIANGLE_STRIP_TEST
 p_glBegin(GL_TRIANGLE_STRIP);
#else
 p_glBegin(GL_QUADS);
#endif

 if(UsingIP == VIDEOIP_LINEAR_X || UsingIP == VIDEOIP_LINEAR_Y)	// Linear interpolation, on one axis
 {
  DrawLinearIP(UsingIP, rotated, &tex_src_rect, dest_rect, tmpwidth, tmpheight);
 }
 else	// Regular bilinear or no interpolation.
 {
  DrawQuad(src_coords, dest_coords);
 }

 p_glEnd();

 if(shader)
  shader->ShaderEnd();

 if(using_scanlines)
 {
  float yif_offset = 0;
  int yh_shift = 0;

  if(using_scanlines < 0 && InterlaceField >= 0)
  {
   yif_offset = (float)InterlaceField / 512;
   yh_shift = 1;
  }


  p_glEnable(GL_BLEND);

  p_glBindTexture(GL_TEXTURE_2D, textures[1]);
  p_glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);

  p_glBegin(GL_QUADS);

  p_glTexCoord2f(0.0f, yif_offset + (original_src_rect->h >> yh_shift) / 256.0f);  // Bottom left of our picture.
  p_glVertex2f((signed)dest_coords[3][0], (signed)dest_coords[3][1]);

  p_glTexCoord2f(1.0f, yif_offset + (original_src_rect->h >> yh_shift) / 256.0f); // Bottom right of our picture.
  p_glVertex2f((signed)dest_coords[2][0], (signed)dest_coords[2][1]);

  p_glTexCoord2f(1.0f, yif_offset);    // Top right of our picture.
  p_glVertex2f((signed)dest_coords[1][0], (signed)dest_coords[1][1]);

  p_glTexCoord2f(0.0f, yif_offset);     // Top left of our picture.
  p_glVertex2f((signed)dest_coords[0][0], (signed)dest_coords[0][1]);

  p_glEnd();
  p_glDisable(GL_BLEND);
 }

 //if(1)
 //{
 // p_glAccum(GL_MULT, 0.99);
 // p_glAccum(GL_ACCUM, 1 - 0.99);
 // p_glAccum(GL_RETURN, 1.0);
 //}
}
Ejemplo n.º 30
0
/*!****************************************************************************
 @Function		RenderScene
 @Return		bool		true if no error occured
 @Description	Main rendering loop function of the program. The shell will
				call this function every frame.
				eglSwapBuffers() will be performed by PVRShell automatically.
				PVRShell will also manage important OS events.
				Will also manage relevent OS events. The user has access to
				these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLESEvilSkull::RenderScene()
{
	unsigned int i;
	float fCurrentfJawRotation, fCurrentfBackRotation;
	float fFactor, fInvFactor;

	// Update Skull Weights and Rotations using Animation Info
	if(m_i32Frame > g_fExprTime)
	{
		m_i32Frame = 0;
		m_i32BaseAnim = m_i32TargetAnim;

		++m_i32TargetAnim;

		if(m_i32TargetAnim > 6)
		{
			m_i32TargetAnim = 0;
		}
	}

	fFactor = float(m_i32Frame) / g_fExprTime;
	fInvFactor = 1.0f - fFactor;

	m_fSkullWeights[0] = (m_fExprTable[0][m_i32BaseAnim] * fInvFactor) + (m_fExprTable[0][m_i32TargetAnim] * fFactor);
	m_fSkullWeights[1] = (m_fExprTable[1][m_i32BaseAnim] * fInvFactor) + (m_fExprTable[1][m_i32TargetAnim] * fFactor);
	m_fSkullWeights[2] = (m_fExprTable[2][m_i32BaseAnim] * fInvFactor) + (m_fExprTable[2][m_i32TargetAnim] * fFactor);
	m_fSkullWeights[3] = (m_fExprTable[3][m_i32BaseAnim] * fInvFactor) + (m_fExprTable[3][m_i32TargetAnim] * fFactor);

	fCurrentfJawRotation = m_fJawRotation[m_i32BaseAnim] * fInvFactor + (m_fJawRotation[m_i32TargetAnim] * fFactor);
	fCurrentfBackRotation = m_fBackRotation[m_i32BaseAnim] * fInvFactor + (m_fBackRotation[m_i32TargetAnim] * fFactor);

	// Update Base Animation Value - FrameBased Animation for now
	++m_i32Frame;

	// Update Skull Vertex Data using Animation Params
	for(i = 0; i < m_Scene.pMesh[eSkull].nNumVertex * 3; ++i)
	{
		m_pMorphedVertices[i]= f2vt(m_pAVGVertices[i] + (m_pDiffVertices[0][i] * m_fSkullWeights[0]) \
													  + (m_pDiffVertices[1][i] * m_fSkullWeights[1]) \
													  + (m_pDiffVertices[2][i] * m_fSkullWeights[2]) \
													  + (m_pDiffVertices[3][i] * m_fSkullWeights[3]));

	}

	// Buffer Clear
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Render Skull and Jaw Opaque with Lighting
	glDisable(GL_BLEND);		// Opaque = No Blending
	glEnable(GL_LIGHTING);		// Lighting On

	// Set skull and jaw texture
	glBindTexture(GL_TEXTURE_2D, m_ui32Texture[1]);

	// Enable and set vertices, normals and index data
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	// Render Animated Jaw - Rotation Only
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	glLoadIdentity();

	myglMultMatrix(m_mView.f);

	myglTranslate(f2vt(0),f2vt(-50.0f),f2vt(-50.0f));

	myglRotate(f2vt(-fCurrentfJawRotation), f2vt(1.0f), f2vt(0.0f), f2vt(0.0f));
	myglRotate(f2vt(fCurrentfJawRotation) - f2vt(30.0f), f2vt(0), f2vt(1.0f), f2vt(-1.0f));

	RenderJaw();

	glPopMatrix();

	// Render Morphed Skull
	glPushMatrix();

	myglRotate(f2vt(fCurrentfJawRotation) - f2vt(30.0f), f2vt(0), f2vt(1.0f), f2vt(-1.0f));

	RenderSkull();

	// Render Eyes and Background with Alpha Blending and No Lighting

	glEnable(GL_BLEND);			// Enable Alpha Blending
	glDisable(GL_LIGHTING);		// Disable Lighting


	// Disable the normals as they aren't needed anymore
	glDisableClientState(GL_NORMAL_ARRAY);

	// Render Eyes using Skull Model Matrix
	DrawQuad(-30.0f ,0.0f ,50.0f ,20.0f , m_ui32Texture[0]);
	DrawQuad( 33.0f ,0.0f ,50.0f ,20.0f , m_ui32Texture[0]);

	glPopMatrix();

	// Render Dual Texture Background with different base color, rotation, and texture rotation
	glPushMatrix();

	glDisable(GL_BLEND);			// Disable Alpha Blending

	myglColor4(f2vt(0.7f+0.3f*((m_fSkullWeights[0]))), f2vt(0.7f), f2vt(0.7f), f2vt(1.0f));	// Animated Base Color
	myglTranslate(f2vt(10.0f), f2vt(-50.0f), f2vt(0.0f));
	myglRotate(f2vt(fCurrentfBackRotation*4.0f),f2vt(0),f2vt(0),f2vt(-1.0f));	// Rotation of Quad

	// Animated Texture Matrix
	glActiveTexture(GL_TEXTURE0);
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();

	myglTranslate(f2vt(-0.5f), f2vt(-0.5f), f2vt(0.0f));
	myglRotate(f2vt(fCurrentfBackRotation*-8.0f), f2vt(0), f2vt(0), f2vt(-1.0f));
	myglTranslate(f2vt(-0.5f), f2vt(-0.5f), f2vt(0.0f));

	// Draw Geometry
	DrawDualTexQuad (0.0f ,0.0f ,-100.0f ,300.0f, m_ui32Texture[3], m_ui32Texture[2]);

	// Disable Animated Texture Matrix
	glActiveTexture(GL_TEXTURE0);
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();

	// Make sure to disable the arrays
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);

	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	// Reset Colour
	myglColor4(f2vt(1.0f), f2vt(1.0f), f2vt(1.0f), f2vt(1.0f));

	// Display info text
	m_Print3D.DisplayDefaultTitle("EvilSkull", "Morphing.", ePVRTPrint3DSDKLogo);
	m_Print3D.Flush();

	return true;
}