Skip to content

Commit 1fd888d

Browse files
committed
Simplify test_gl_subdata and test_float_tex. NFC
Also, remove test_std_cout_new.cpp completely. This test seems to be based on the code from these other two tests but doesn't seem to server any useful purpose anymore. Its was first added in ad285f6.
1 parent f9df292 commit 1fd888d

File tree

5 files changed

+67
-83
lines changed

5 files changed

+67
-83
lines changed

test/core/test_std_cout_new.cpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/float_tex.cpp renamed to test/float_tex.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6+
#include <assert.h>
7+
#include <math.h>
8+
#include <stdio.h>
9+
610
#define GL_GLEXT_PROTOTYPES
711
#define EGL_EGLEXT_PROTOTYPES
8-
#include <cassert>
9-
#include <cmath>
10-
#include <iostream>
11-
#include <vector>
12-
extern "C" {
1312
#include <GL/gl.h>
1413
#include <GL/glut.h>
15-
}
14+
1615
static const char vertex_shader[] =
1716
"#ifdef GL_ES\n"
1817
"precision lowp float;\n"
@@ -29,6 +28,7 @@ static const char vertex_shader[] =
2928
" gl_PointSize = v.z;\n"
3029
" color = vec4(0.5 + v.w/2., 0.5 + 0.5 * v.w/2., 0.5, 1);\n"
3130
"}\n";
31+
3232
static const char fragment_shader[] =
3333
"#ifdef GL_ES\n"
3434
"precision lowp float;\n"
@@ -44,26 +44,28 @@ static const char fragment_shader[] =
4444
"}\n"
4545
"if ( dst > 0.5) discard;\n"
4646
"}";
47-
struct NodeInfo { //structure that we want to transmit to our shaders
47+
48+
typedef struct NodeInfo { //structure that we want to transmit to our shaders
4849
float x;
4950
float y;
5051
float s;
5152
float c;
52-
};
53+
} NodeInfo;
5354
GLuint nodeTexture; //texture id used to bind
5455
GLuint nodeSamplerLocation; //shader sampler address
5556
GLuint indicesAttributeLocation; //shader attribute address
5657
GLuint indicesVBO; //Vertex Buffer Object Id;
57-
const int nbNodes = 512;
58-
NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture.
58+
#define NUM_NODES 512
59+
NodeInfo data[NUM_NODES]; //our data that will be transmitted using float texture.
5960
double alpha = 0; //use to make a simple funny effect;
61+
//
6062
static void updateFloatTexture() {
6163
int count = 0;
62-
for (float x=0; x < nbNodes; ++x ) {
63-
data[count].x = 0.2*pow(cos(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * cos(alpha + x/nbNodes * 16. * M_PI);
64-
data[count].y = 0.2*pow(sin(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * sin(alpha + x/nbNodes * 16. * M_PI);
65-
data[count].s = (16. + 16. * cos(alpha + x/nbNodes * 32. * M_PI)) + 8.;// * fmod(x/nbNodes + alpha, 1.) + 5.;
66-
data[count].c = 0.5 + 0.5 * sin(alpha + x/nbNodes * 32. * M_PI);
64+
for (float x=0; x < NUM_NODES; ++x ) {
65+
data[count].x = 0.2*pow(cos(alpha), 3) + (sin(alpha)*3. + 3.5) * x/NUM_NODES * cos(alpha + x/NUM_NODES * 16. * M_PI);
66+
data[count].y = 0.2*pow(sin(alpha), 3) + (sin(alpha)*3. + 3.5) * x/NUM_NODES * sin(alpha + x/NUM_NODES * 16. * M_PI);
67+
data[count].s = (16. + 16. * cos(alpha + x/NUM_NODES * 32. * M_PI)) + 8.;// * fmod(x/NUM_NODES + alpha, 1.) + 5.;
68+
data[count].c = 0.5 + 0.5 * sin(alpha + x/NUM_NODES * 32. * M_PI);
6769
++count;
6870
}
6971
glBindTexture(GL_TEXTURE_2D, nodeTexture);
@@ -73,12 +75,13 @@ static void updateFloatTexture() {
7375
// In desktop GL, we can also use sized internal formats.
7476
const GLenum internalFormat = GL_RGBA32F;
7577
#endif
76-
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
78+
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
7779
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7880
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7981
glBindTexture(GL_TEXTURE_2D, 0);
8082
alpha -= 0.001;
8183
}
84+
8285
static void glut_draw_callback(void) {
8386
glDisable(GL_CULL_FACE);
8487
glDisable(GL_DEPTH_TEST);
@@ -93,9 +96,10 @@ static void glut_draw_callback(void) {
9396
glEnableVertexAttribArray(0);
9497
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
9598
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
96-
glDrawArrays(GL_POINTS, 0, nbNodes);
99+
glDrawArrays(GL_POINTS, 0, NUM_NODES);
97100
glutSwapBuffers();
98101
}
102+
99103
GLuint createShader(const char source[], int type) {
100104
GLint status;
101105
char msg[512];
@@ -105,11 +109,12 @@ GLuint createShader(const char source[], int type) {
105109
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
106110
if (status == GL_FALSE) {
107111
glGetShaderInfoLog(shader, sizeof msg, NULL, msg);
108-
std::cout << "Shader info: \"" << msg << "\"" << std::endl;
112+
printf("Shader info: \"%s\"\n", msg);
109113
}
110114
assert(status == GL_TRUE);
111115
return shader;
112116
}
117+
113118
static void gl_init(void) {
114119
GLuint program = glCreateProgram();
115120
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
@@ -120,13 +125,13 @@ static void gl_init(void) {
120125
glGetProgramiv(program, GL_LINK_STATUS, &status);
121126
if (status == GL_FALSE) {
122127
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
123-
std::cout << "info: \"" << msg << "\"" << std::endl;
128+
printf("info: \"%s\"\n", msg);
124129
}
125130
assert(status == GL_TRUE);
126131
glUseProgram(program);
127-
std::vector<float> elements(nbNodes);
132+
float elements[NUM_NODES];
128133
int count = 0;
129-
for (float x=0; x < nbNodes; ++x ) {
134+
for (float x=0; x < NUM_NODES; ++x ) {
130135
elements[count] = count;
131136
++count;
132137
}
@@ -135,7 +140,7 @@ static void gl_init(void) {
135140
/* Store the vertices in a vertex buffer object (VBO) */
136141
glGenBuffers(1, &indicesVBO);
137142
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
138-
glBufferData(GL_ARRAY_BUFFER, elements.size() * sizeof(float), &elements[0], GL_STATIC_DRAW);
143+
glBufferData(GL_ARRAY_BUFFER, NUM_NODES * sizeof(float), &elements[0], GL_STATIC_DRAW);
139144
/* Get the locations of the uniforms so we can access them */
140145
nodeSamplerLocation = glGetUniformLocation(program, "nodeInfo");
141146
glBindAttribLocation(program, 0, "indices");
@@ -145,16 +150,16 @@ static void gl_init(void) {
145150
glEnable(GL_POINT_SPRITE);
146151
#endif
147152
}
153+
148154
int main(int argc, char *argv[]) {
149155
glutInit(&argc, argv);
150156
glutInitWindowSize(640, 480);
151157
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
152158
glutCreateWindow("Simple FLOAT Texture Test");
153159
/* Set up glut callback functions */
154-
glutDisplayFunc(glut_draw_callback );
160+
glutDisplayFunc(glut_draw_callback);
155161
gl_init();
156162
glutMainLoop();
157163
return 0;
158164
}
159165

160-

test/gl_subdata.cpp renamed to test/gl_subdata.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6+
#include <math.h>
7+
#include <stdio.h>
8+
#include <string.h>
9+
610
#define GL_GLEXT_PROTOTYPES
711
#define EGL_EGLEXT_PROTOTYPES
8-
#include <cmath>
9-
#include <iostream>
10-
#include <vector>
11-
extern "C" {
1212
#include <GL/gl.h>
1313
#include <GL/glut.h>
14-
}
14+
1515
static const char vertex_shader[] =
1616
"#ifdef GL_ES\n"
1717
"precision lowp float;\n"
@@ -28,6 +28,7 @@ static const char vertex_shader[] =
2828
" gl_PointSize = v.z;\n"
2929
" color = vec4(0.5 + v.w/2., 0.5 + 0.5 * v.w/2., 0.5, 1);\n"
3030
"}\n";
31+
3132
static const char fragment_shader[] =
3233
"#ifdef GL_ES\n"
3334
"precision lowp float;\n"
@@ -43,42 +44,46 @@ static const char fragment_shader[] =
4344
"}\n"
4445
"if ( dst > 0.5) discard;\n"
4546
"}";
46-
struct NodeInfo { //structure that we want to transmit to our shaders
47+
48+
typedef struct NodeInfo { //structure that we want to transmit to our shaders
4749
float x;
4850
float y;
4951
float s;
5052
float c;
51-
};
53+
} NodeInfo;
54+
5255
GLuint nodeTexture; //texture id used to bind
5356
GLuint nodeSamplerLocation; //shader sampler address
5457
GLuint indicesAttributeLocation; //shader attribute address
5558
GLuint indicesVBO; //Vertex Buffer Object Id;
56-
const int nbNodes = 512;
57-
NodeInfo data[nbNodes]; //our data that will be transmitted using float texture.
59+
#define NUM_NODES 512
60+
NodeInfo data[NUM_NODES]; //our data that will be transmitted using float texture.
5861
double alpha = 0; //use to make a simple funny effect;
62+
5963
static void updateFloatTexture() {
6064
int count = 0;
61-
for (float x=0; x < nbNodes; ++x ) {
62-
data[count].x = 0.2*pow(cos(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * cos(alpha + x/nbNodes * 16. * M_PI);
63-
data[count].y = 0.2*pow(sin(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * sin(alpha + x/nbNodes * 16. * M_PI);
64-
data[count].s = (16. + 16. * cos(alpha + x/nbNodes * 32. * M_PI)) + 8.;// * fmod(x/nbNodes + alpha, 1.) + 5.;
65-
data[count].c = 0.5 + 0.5 * sin(alpha + x/nbNodes * 32. * M_PI);
65+
for (float x=0; x < NUM_NODES; ++x ) {
66+
data[count].x = 0.2*pow(cos(alpha), 3) + (sin(alpha)*3. + 3.5) * x/NUM_NODES * cos(alpha + x/NUM_NODES * 16. * M_PI);
67+
data[count].y = 0.2*pow(sin(alpha), 3) + (sin(alpha)*3. + 3.5) * x/NUM_NODES * sin(alpha + x/NUM_NODES * 16. * M_PI);
68+
data[count].s = (16. + 16. * cos(alpha + x/NUM_NODES * 32. * M_PI)) + 8.;// * fmod(x/NUM_NODES + alpha, 1.) + 5.;
69+
data[count].c = 0.5 + 0.5 * sin(alpha + x/NUM_NODES * 32. * M_PI);
6670
++count;
6771
}
6872
glBindTexture(GL_TEXTURE_2D, nodeTexture);
69-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
73+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
7074
#ifdef __EMSCRIPTEN__ // In GLES2 and WebGL1, we must use unsized texture internal formats.
7175
const GLenum internalFormat = GL_RGBA;
7276
#else
7377
// In desktop GL, we can also use sized internal formats.
7478
const GLenum internalFormat = GL_RGBA32F;
7579
#endif
76-
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
80+
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
7781
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7882
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7983
glBindTexture(GL_TEXTURE_2D, 0);
8084
alpha -= 0.001;
8185
}
86+
8287
static void glut_draw_callback(void) {
8388
glDisable(GL_CULL_FACE);
8489
glDisable(GL_DEPTH_TEST);
@@ -93,30 +98,32 @@ static void glut_draw_callback(void) {
9398
glEnableVertexAttribArray(0);
9499
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
95100
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
96-
glDrawArrays(GL_POINTS, 0, nbNodes);
101+
glDrawArrays(GL_POINTS, 0, NUM_NODES);
97102
glutSwapBuffers();
98103
}
99-
GLuint createShader(const char source[], int type) {
104+
105+
GLuint createShader(const char* source, int type) {
100106
char msg[512];
101107
GLuint shader = glCreateShader(type);
102-
glShaderSource(shader, 1, (const GLchar**)(&source), NULL);
108+
glShaderSource(shader, 1, &source, NULL);
103109
glCompileShader(shader);
104110
glGetShaderInfoLog(shader, sizeof msg, NULL, msg);
105-
std::cout << "Shader info: " << msg << std::endl;
111+
printf("Shader info: %s\n", msg);
106112
return shader;
107113
}
114+
108115
static void gl_init(void) {
109116
GLuint program = glCreateProgram();
110117
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
111118
glAttachShader(program, createShader(fragment_shader, GL_FRAGMENT_SHADER));
112119
glLinkProgram(program);
113120
char msg[512];
114121
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
115-
std::cout << "info: " << msg << std::endl;
122+
printf("info: %s\n", msg);
116123
glUseProgram(program);
117-
std::vector<float> elements(nbNodes);
124+
float elements[NUM_NODES];
118125
int count = 0;
119-
for (float x=0; x < nbNodes; ++x ) {
126+
for (float x=0; x < NUM_NODES; ++x ) {
120127
elements[count] = count;
121128
++count;
122129
}
@@ -125,10 +132,10 @@ static void gl_init(void) {
125132
/* Store the vertices in a vertex buffer object (VBO) */
126133
glGenBuffers(1, &indicesVBO);
127134
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
128-
float zeroes[nbNodes];
135+
float zeroes[NUM_NODES];
129136
memset(zeroes, 0, sizeof(zeroes));
130-
glBufferData(GL_ARRAY_BUFFER, elements.size() * sizeof(float), zeroes, GL_STATIC_DRAW);
131-
for (int x = 0; x < nbNodes; x++) {
137+
glBufferData(GL_ARRAY_BUFFER, NUM_NODES * sizeof(float), zeroes, GL_STATIC_DRAW);
138+
for (int x = 0; x < NUM_NODES; x++) {
132139
glBufferSubData(GL_ARRAY_BUFFER, x * sizeof(float), sizeof(float), &elements[x]);
133140
}
134141
/* Get the locations of the uniforms so we can access them */
@@ -140,13 +147,14 @@ static void gl_init(void) {
140147
glEnable(GL_POINT_SPRITE);
141148
#endif
142149
}
150+
143151
int main(int argc, char *argv[]) {
144152
glutInit(&argc, argv);
145153
glutInitWindowSize(640, 480);
146154
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
147-
glutCreateWindow("Simple FLOAT Texture Test");
155+
int w = glutCreateWindow("Simple FLOAT Texture Test");
148156
/* Set up glut callback functions */
149-
glutDisplayFunc(glut_draw_callback );
157+
glutDisplayFunc(glut_draw_callback);
150158
gl_init();
151159
glutMainLoop();
152160
return 0;

test/test_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,11 +2320,11 @@ def test_tex_nonbyte(self):
23202320

23212321
@requires_graphics_hardware
23222322
def test_float_tex(self):
2323-
self.btest('float_tex.cpp', reference='float_tex.png', args=['-lGL', '-lglut'])
2323+
self.btest('float_tex.c', reference='float_tex.png', args=['-lGL', '-lglut'])
23242324

23252325
@requires_graphics_hardware
23262326
def test_subdata(self):
2327-
self.btest('gl_subdata.cpp', reference='float_tex.png', args=['-lGL', '-lglut'])
2327+
self.btest('gl_subdata.c', reference='float_tex.png', args=['-lGL', '-lglut'])
23282328

23292329
@requires_graphics_hardware
23302330
def test_perspective(self):

test/test_core.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5703,9 +5703,6 @@ def test_direct_string_constant_usage(self):
57035703
self.set_setting('EXIT_RUNTIME')
57045704
self.do_core_test('test_direct_string_constant_usage.cpp')
57055705

5706-
def test_std_cout_new(self):
5707-
self.do_core_test('test_std_cout_new.cpp')
5708-
57095706
def test_std_function_incomplete_return(self):
57105707
self.do_core_test('test_std_function_incomplete_return.cpp')
57115708

0 commit comments

Comments
 (0)