-
Notifications
You must be signed in to change notification settings - Fork 1
/
b05_RGBTextureTest.cpp
151 lines (127 loc) · 4.85 KB
/
b05_RGBTextureTest.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* b05_RGBTextureTest - benchmark #5, RGB Texture test:
* ----------------------------------------------------
* This test tests RGB based texturing on a quadrilateral shape rendering
*
* Author: Jarkko Vatjus-Anttila <[email protected]>
*
* For conditions of distribution and use, see copyright notice in license.txt
*/
#include "b05_RGBTextureTest.h"
#include "DebugLog.h"
#include "GLWrapper.h"
/*
* Constructor and destructor are dummy ones. Only descriptions are set, and other activities are
* done when calling the virtual benchmark API
*/
b05_RGBTextureTest::b05_RGBTextureTest()
{
setName("RGB texture mapping test");
setDescription("This test tests simple texture mapping on a quad using RGB based texture");
}
b05_RGBTextureTest::~b05_RGBTextureTest()
{
}
/*
* initBenchmark() shall initialize all required resources for this test case. If initialization fails,
* false must be returned to indicate core benchmark not to continue execution. DebugLog::Instance()->MESSAGE()
* method can be used to output information about the initialization
*/
bool b05_RGBTextureTest::initBenchmark(void)
{
const char *texturefilename = "./resources/pngRGB.png";
const char vertex_src[] =
"attribute vec4 a_Position; \n"
"attribute vec2 a_Texcoord; \n"
"varying vec2 v_Texcoord; \n"
"void main() \n"
"{ \n"
" gl_Position = a_Position; \n"
" v_Texcoord = a_Texcoord; \n"
"} \n";
const char fragment_src[] =
"precision mediump float; \n"
"varying vec2 v_Texcoord; \n"
"uniform sampler2D s_texture; \n"
"void main() \n"
"{ \n"
" gl_FragColor = texture2D(s_texture, v_Texcoord);\n"
"} \n";
/*
* Shader program init:
*/
ss = new SimpleShader();
if (false == ss->fromFiles(vertex_src, fragment_src))
{
DebugLog::Instance()->MESSAGE(2, "Shader program object creation failed\n");
return false;
}
GLWrapper::Instance()->GLBINDATTRIBLOCATION(ss->getProgramObject(), 0, "a_Position");
GLWrapper::Instance()->GLBINDATTRIBLOCATION(ss->getProgramObject(), 1, "a_Texcoord");
ss->linkProgram();
texturesampler = GLWrapper::Instance()->GLGETUNIFORMLOCATION(ss->getProgramObject(), "s_texture");
/*
* Texture loading for the test case:
*/
st = new SimpleTexture();
if (false == st->fromFile(texturefilename))
{
DebugLog::Instance()->MESSAGE(1, "Error: Loading of texturefile '%s' failed.\n", texturefilename);
return false;
}
GLWrapper::Instance()->GLCLEARCOLOR(0.0f, 0.0f, 0.0f, 0.0f);
// If we have errors in GL pipe, then abort.
if (GLWrapper::Instance()->getGLErrors() > 0) return false;
return true;
}
/*
* destroyBenchmark() shall free all resources allocated by the initBenchmark() method. The core shall
* call this method once the benchmark case has been run.
*/
bool b05_RGBTextureTest::destroyBenchmark(void)
{
return true;
}
// Constant vectors for the render test
static GLfloat vVertices[] = { -0.5f, -0.5f, 0.0f,
-0.5f, 0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
0.5f, -0.5f, 0.0f };
static GLfloat vTexcoord[] = { 0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 1.0f,
1.0f, 0.0f };
void b05_RGBTextureTest::Render(void)
{
GLWrapper::Instance()->GLVIEWPORT(0, 0, display->getDisplayWidth(), display->getDisplayHeight());
GLWrapper::Instance()->GLCLEAR(GL_COLOR_BUFFER_BIT);
GLWrapper::Instance()->GLACTIVETEXTURE(GL_TEXTURE0);
st->bind();
GLWrapper::Instance()->GLUNIFORM1I(texturesampler, 0);
GLWrapper::Instance()->GLVERTEXATTRIBPOINTER(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
GLWrapper::Instance()->GLENABLEVERTEXATTRIBARRAY(0);
GLWrapper::Instance()->GLVERTEXATTRIBPOINTER(1, 2, GL_FLOAT, GL_FALSE, 0, vTexcoord);
GLWrapper::Instance()->GLENABLEVERTEXATTRIBARRAY(1);
GLWrapper::Instance()->GLDRAWARRAYS(GL_TRIANGLES, 0, 6);
// get the rendered buffer to the screen
GLWrapper::Instance()->EGLSWAPBUFFERS(display->getEGLDisplay(), display->getEGLSurface());
}
/*
* renderSingleFrame()
*/
bool b05_RGBTextureTest::renderSingleFrame(float deltatime)
{
Render();
return true;
}
/*
* getRenderStatistics()
*/
bool b05_RGBTextureTest::getRenderStatistics(RENDER_STATISTICS *rs)
{
return true;
}