File: COGLES2Renderer2D.cpp

package info (click to toggle)
supertuxkart 1.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 767,580 kB
  • sloc: cpp: 412,075; xml: 106,334; ansic: 83,792; asm: 1,559; python: 1,403; sh: 1,366; objc: 452; makefile: 333; javascript: 23; awk: 20
file content (100 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (C) 2013 Patryk Nadrowski
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
// driver implemented by Amundis.
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h

#include "IrrCompileConfig.h"

#ifdef _IRR_COMPILE_WITH_OGLES2_

#include "COGLES2Renderer2D.h"
#include "IGPUProgrammingServices.h"
#include "os.h"
#include "COGLES2Driver.h"

namespace irr
{
namespace video
{

//! Constructor
COGLES2Renderer2D::COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver)
	:	COGLES2MaterialRenderer(driver, 0, EMT_SOLID), RenderTargetSize(core::dimension2d<u32>(0,0)),
		Matrix(core::matrix4::EM4CONST_NOTHING), Texture(0)
{
	#ifdef _DEBUG
	setDebugName("COGLES2Renderer2D");
	#endif

	int Temp = 0;

	init(Temp, vertexShaderProgram, pixelShaderProgram, false);

	Driver->getBridgeCalls()->setProgram(Program);

	// These states doesn't change later.

	MatrixID = getPixelShaderConstantID("uOrthoMatrix");
	UseTextureID = getPixelShaderConstantID("uUseTexture");
	s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit");	

	int TextureUnit = 0;
	setPixelShaderConstant(TextureUnitID, &TextureUnit, 1);

	Driver->getBridgeCalls()->setProgram(0);
}


//! Destructor
COGLES2Renderer2D::~COGLES2Renderer2D()
{
}


void COGLES2Renderer2D::OnSetMaterial(const video::SMaterial& material,
				const video::SMaterial& lastMaterial,
				bool resetAllRenderstates,
				video::IMaterialRendererServices* services)
{
	Driver->getBridgeCalls()->setProgram(Program);

	Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}


bool COGLES2Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
{
	Driver->setTextureRenderStates(Driver->getCurrentMaterial(), false);

	const core::dimension2d<u32>& renderTargetSize = Driver->getCurrentRenderTargetSize();

	if (RenderTargetSize != renderTargetSize)
	{
		Matrix.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0f, 1.0f);
		Matrix.setTranslation(core::vector3df(-1,1,0));

		setPixelShaderConstant(MatrixID, Matrix.pointer(), 16);

		RenderTargetSize = renderTargetSize;
	}

	int UseTexture = Texture ? 1 : 0;
	setPixelShaderConstant(UseTextureID, &UseTexture, 1);

	return true;
}


void COGLES2Renderer2D::setTexture(const ITexture* texture)
{
	Texture = texture;
}


} // end namespace video
} // end namespace irr


#endif