Skip to content

Commit 0815a0d

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 bf76ba4 commit 0815a0d

File tree

5 files changed

+69
-85
lines changed

5 files changed

+69
-85
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: 31 additions & 26 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,29 @@ 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;
54+
5355
GLuint nodeTexture; //texture id used to bind
5456
GLuint nodeSamplerLocation; //shader sampler address
5557
GLuint indicesAttributeLocation; //shader attribute address
5658
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.
59+
#define NUM_NODES 512
60+
NodeInfo data[NUM_NODES]; //our data that will be transmitted using float texture.
5961
double alpha = 0; //use to make a simple funny effect;
62+
//
6063
static void updateFloatTexture() {
6164
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);
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);
6770
++count;
6871
}
6972
glBindTexture(GL_TEXTURE_2D, nodeTexture);
@@ -73,12 +76,13 @@ static void updateFloatTexture() {
7376
// In desktop GL, we can also use sized internal formats.
7477
const GLenum internalFormat = GL_RGBA32F;
7578
#endif
76-
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
79+
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
7780
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7881
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7982
glBindTexture(GL_TEXTURE_2D, 0);
8083
alpha -= 0.001;
8184
}
85+
8286
static void glut_draw_callback(void) {
8387
glDisable(GL_CULL_FACE);
8488
glDisable(GL_DEPTH_TEST);
@@ -93,9 +97,10 @@ static void glut_draw_callback(void) {
9397
glEnableVertexAttribArray(0);
9498
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
9599
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
96-
glDrawArrays(GL_POINTS, 0, nbNodes);
100+
glDrawArrays(GL_POINTS, 0, NUM_NODES);
97101
glutSwapBuffers();
98102
}
103+
99104
GLuint createShader(const char source[], int type) {
100105
GLint status;
101106
char msg[512];
@@ -105,11 +110,12 @@ GLuint createShader(const char source[], int type) {
105110
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
106111
if (status == GL_FALSE) {
107112
glGetShaderInfoLog(shader, sizeof msg, NULL, msg);
108-
std::cout << "Shader info: \"" << msg << "\"" << std::endl;
113+
printf("Shader info: \"%s\"\n", msg);
109114
}
110115
assert(status == GL_TRUE);
111116
return shader;
112117
}
118+
113119
static void gl_init(void) {
114120
GLuint program = glCreateProgram();
115121
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
@@ -120,13 +126,13 @@ static void gl_init(void) {
120126
glGetProgramiv(program, GL_LINK_STATUS, &status);
121127
if (status == GL_FALSE) {
122128
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
123-
std::cout << "info: \"" << msg << "\"" << std::endl;
129+
printf("info: \"%s\"\n", msg);
124130
}
125131
assert(status == GL_TRUE);
126132
glUseProgram(program);
127-
std::vector<float> elements(nbNodes);
133+
float elements[NUM_NODES];
128134
int count = 0;
129-
for (float x=0; x < nbNodes; ++x ) {
135+
for (float x=0; x < NUM_NODES; ++x ) {
130136
elements[count] = count;
131137
++count;
132138
}
@@ -135,26 +141,25 @@ static void gl_init(void) {
135141
/* Store the vertices in a vertex buffer object (VBO) */
136142
glGenBuffers(1, &indicesVBO);
137143
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
138-
glBufferData(GL_ARRAY_BUFFER, elements.size() * sizeof(float), &elements[0], GL_STATIC_DRAW);
144+
glBufferData(GL_ARRAY_BUFFER, NUM_NODES * sizeof(float), &elements[0], GL_STATIC_DRAW);
139145
/* Get the locations of the uniforms so we can access them */
140-
nodeSamplerLocation = glGetUniformLocation(program, "nodeInfo");
146+
nodeSamplerLocation = glGetUniformLocation(program, "nodeInfo");
141147
glBindAttribLocation(program, 0, "indices");
142148
#ifndef __EMSCRIPTEN__ // GLES2 & WebGL do not have these, only pre 3.0 desktop GL and compatibility mode GL3.0+ GL do.
143149
//Enable glPoint size in shader, always enable in Open Gl ES 2.
144150
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
145151
glEnable(GL_POINT_SPRITE);
146152
#endif
147153
}
154+
148155
int main(int argc, char *argv[]) {
149156
glutInit(&argc, argv);
150157
glutInitWindowSize(640, 480);
151158
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
152159
glutCreateWindow("Simple FLOAT Texture Test");
153160
/* Set up glut callback functions */
154-
glutDisplayFunc(glut_draw_callback );
161+
glutDisplayFunc(glut_draw_callback);
155162
gl_init();
156163
glutMainLoop();
157164
return 0;
158165
}
159-
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,26 +44,29 @@ 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);
@@ -72,12 +76,13 @@ static void updateFloatTexture() {
7276
// In desktop GL, we can also use sized internal formats.
7377
const GLenum internalFormat = GL_RGBA32F;
7478
#endif
75-
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
79+
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
7680
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
7781
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
7882
glBindTexture(GL_TEXTURE_2D, 0);
7983
alpha -= 0.001;
8084
}
85+
8186
static void glut_draw_callback(void) {
8287
glDisable(GL_CULL_FACE);
8388
glDisable(GL_DEPTH_TEST);
@@ -92,30 +97,32 @@ static void glut_draw_callback(void) {
9297
glEnableVertexAttribArray(0);
9398
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
9499
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
95-
glDrawArrays(GL_POINTS, 0, nbNodes);
100+
glDrawArrays(GL_POINTS, 0, NUM_NODES);
96101
glutSwapBuffers();
97102
}
98-
GLuint createShader(const char source[], int type) {
103+
104+
GLuint createShader(const char* source, int type) {
99105
char msg[512];
100106
GLuint shader = glCreateShader(type);
101-
glShaderSource(shader, 1, (const GLchar**)(&source), NULL);
107+
glShaderSource(shader, 1, &source, NULL);
102108
glCompileShader(shader);
103109
glGetShaderInfoLog(shader, sizeof msg, NULL, msg);
104-
std::cout << "Shader info: " << msg << std::endl;
110+
printf("Shader info: %s\n", msg);
105111
return shader;
106112
}
113+
107114
static void gl_init(void) {
108115
GLuint program = glCreateProgram();
109116
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
110117
glAttachShader(program, createShader(fragment_shader, GL_FRAGMENT_SHADER));
111118
glLinkProgram(program);
112119
char msg[512];
113120
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
114-
std::cout << "info: " << msg << std::endl;
121+
printf("info: %s\n", msg);
115122
glUseProgram(program);
116-
std::vector<float> elements(nbNodes);
123+
float elements[NUM_NODES];
117124
int count = 0;
118-
for (float x=0; x < nbNodes; ++x ) {
125+
for (float x=0; x < NUM_NODES; ++x ) {
119126
elements[count] = count;
120127
++count;
121128
}
@@ -124,28 +131,29 @@ static void gl_init(void) {
124131
/* Store the vertices in a vertex buffer object (VBO) */
125132
glGenBuffers(1, &indicesVBO);
126133
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
127-
float zeroes[nbNodes];
134+
float zeroes[NUM_NODES];
128135
memset(zeroes, 0, sizeof(zeroes));
129-
glBufferData(GL_ARRAY_BUFFER, elements.size() * sizeof(float), zeroes, GL_STATIC_DRAW);
130-
for (int x = 0; x < nbNodes; x++) {
136+
glBufferData(GL_ARRAY_BUFFER, NUM_NODES * sizeof(float), zeroes, GL_STATIC_DRAW);
137+
for (int x = 0; x < NUM_NODES; x++) {
131138
glBufferSubData(GL_ARRAY_BUFFER, x * sizeof(float), sizeof(float), &elements[x]);
132139
}
133140
/* Get the locations of the uniforms so we can access them */
134-
nodeSamplerLocation = glGetUniformLocation(program, "nodeInfo");
141+
nodeSamplerLocation = glGetUniformLocation(program, "nodeInfo");
135142
glBindAttribLocation(program, 0, "indices");
136143
#ifndef __EMSCRIPTEN__ // GLES2 & WebGL do not have these, only pre 3.0 desktop GL and compatibility mode GL3.0+ GL do.
137144
//Enable glPoint size in shader, always enable in Open Gl ES 2.
138145
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
139146
glEnable(GL_POINT_SPRITE);
140147
#endif
141148
}
149+
142150
int main(int argc, char *argv[]) {
143151
glutInit(&argc, argv);
144152
glutInitWindowSize(640, 480);
145153
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
146-
glutCreateWindow("Simple FLOAT Texture Test");
154+
int w = glutCreateWindow("Simple FLOAT Texture Test");
147155
/* Set up glut callback functions */
148-
glutDisplayFunc(glut_draw_callback );
156+
glutDisplayFunc(glut_draw_callback);
149157
gl_init();
150158
glutMainLoop();
151159
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)