Skip to content

Commit

Permalink
Simplify test_gl_subdata and test_float_tex. NFC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 committed Feb 22, 2024
1 parent f9df292 commit 1fd888d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 83 deletions.
26 changes: 0 additions & 26 deletions test/core/test_std_cout_new.cpp

This file was deleted.

53 changes: 29 additions & 24 deletions test/float_tex.cpp → test/float_tex.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <assert.h>
#include <math.h>
#include <stdio.h>

#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
extern "C" {
#include <GL/gl.h>
#include <GL/glut.h>
}

static const char vertex_shader[] =
"#ifdef GL_ES\n"
"precision lowp float;\n"
Expand All @@ -29,6 +28,7 @@ static const char vertex_shader[] =
" gl_PointSize = v.z;\n"
" color = vec4(0.5 + v.w/2., 0.5 + 0.5 * v.w/2., 0.5, 1);\n"
"}\n";

static const char fragment_shader[] =
"#ifdef GL_ES\n"
"precision lowp float;\n"
Expand All @@ -44,26 +44,28 @@ static const char fragment_shader[] =
"}\n"
"if ( dst > 0.5) discard;\n"
"}";
struct NodeInfo { //structure that we want to transmit to our shaders

typedef struct NodeInfo { //structure that we want to transmit to our shaders
float x;
float y;
float s;
float c;
};
} NodeInfo;
GLuint nodeTexture; //texture id used to bind
GLuint nodeSamplerLocation; //shader sampler address
GLuint indicesAttributeLocation; //shader attribute address
GLuint indicesVBO; //Vertex Buffer Object Id;
const int nbNodes = 512;
NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture.
#define NUM_NODES 512
NodeInfo data[NUM_NODES]; //our data that will be transmitted using float texture.
double alpha = 0; //use to make a simple funny effect;
//
static void updateFloatTexture() {
int count = 0;
for (float x=0; x < nbNodes; ++x ) {
data[count].x = 0.2*pow(cos(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * cos(alpha + x/nbNodes * 16. * M_PI);
data[count].y = 0.2*pow(sin(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * sin(alpha + x/nbNodes * 16. * M_PI);
data[count].s = (16. + 16. * cos(alpha + x/nbNodes * 32. * M_PI)) + 8.;// * fmod(x/nbNodes + alpha, 1.) + 5.;
data[count].c = 0.5 + 0.5 * sin(alpha + x/nbNodes * 32. * M_PI);
for (float x=0; x < NUM_NODES; ++x ) {
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);
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);
data[count].s = (16. + 16. * cos(alpha + x/NUM_NODES * 32. * M_PI)) + 8.;// * fmod(x/NUM_NODES + alpha, 1.) + 5.;
data[count].c = 0.5 + 0.5 * sin(alpha + x/NUM_NODES * 32. * M_PI);
++count;
}
glBindTexture(GL_TEXTURE_2D, nodeTexture);
Expand All @@ -73,12 +75,13 @@ static void updateFloatTexture() {
// In desktop GL, we can also use sized internal formats.
const GLenum internalFormat = GL_RGBA32F;
#endif
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
alpha -= 0.001;
}

static void glut_draw_callback(void) {
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
Expand All @@ -93,9 +96,10 @@ static void glut_draw_callback(void) {
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawArrays(GL_POINTS, 0, nbNodes);
glDrawArrays(GL_POINTS, 0, NUM_NODES);
glutSwapBuffers();
}

GLuint createShader(const char source[], int type) {
GLint status;
char msg[512];
Expand All @@ -105,11 +109,12 @@ GLuint createShader(const char source[], int type) {
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE) {
glGetShaderInfoLog(shader, sizeof msg, NULL, msg);
std::cout << "Shader info: \"" << msg << "\"" << std::endl;
printf("Shader info: \"%s\"\n", msg);
}
assert(status == GL_TRUE);
return shader;
}

static void gl_init(void) {
GLuint program = glCreateProgram();
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
Expand All @@ -120,13 +125,13 @@ static void gl_init(void) {
glGetProgramiv(program, GL_LINK_STATUS, &status);
if (status == GL_FALSE) {
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
std::cout << "info: \"" << msg << "\"" << std::endl;
printf("info: \"%s\"\n", msg);
}
assert(status == GL_TRUE);
glUseProgram(program);
std::vector<float> elements(nbNodes);
float elements[NUM_NODES];
int count = 0;
for (float x=0; x < nbNodes; ++x ) {
for (float x=0; x < NUM_NODES; ++x ) {
elements[count] = count;
++count;
}
Expand All @@ -135,7 +140,7 @@ static void gl_init(void) {
/* Store the vertices in a vertex buffer object (VBO) */
glGenBuffers(1, &indicesVBO);
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
glBufferData(GL_ARRAY_BUFFER, elements.size() * sizeof(float), &elements[0], GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, NUM_NODES * sizeof(float), &elements[0], GL_STATIC_DRAW);
/* Get the locations of the uniforms so we can access them */
nodeSamplerLocation = glGetUniformLocation(program, "nodeInfo");
glBindAttribLocation(program, 0, "indices");
Expand All @@ -145,16 +150,16 @@ static void gl_init(void) {
glEnable(GL_POINT_SPRITE);
#endif
}

int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Simple FLOAT Texture Test");
/* Set up glut callback functions */
glutDisplayFunc(glut_draw_callback );
glutDisplayFunc(glut_draw_callback);
gl_init();
glutMainLoop();
return 0;
}


64 changes: 36 additions & 28 deletions test/gl_subdata.cpp → test/gl_subdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <math.h>
#include <stdio.h>
#include <string.h>

#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <cmath>
#include <iostream>
#include <vector>
extern "C" {
#include <GL/gl.h>
#include <GL/glut.h>
}

static const char vertex_shader[] =
"#ifdef GL_ES\n"
"precision lowp float;\n"
Expand All @@ -28,6 +28,7 @@ static const char vertex_shader[] =
" gl_PointSize = v.z;\n"
" color = vec4(0.5 + v.w/2., 0.5 + 0.5 * v.w/2., 0.5, 1);\n"
"}\n";

static const char fragment_shader[] =
"#ifdef GL_ES\n"
"precision lowp float;\n"
Expand All @@ -43,42 +44,46 @@ static const char fragment_shader[] =
"}\n"
"if ( dst > 0.5) discard;\n"
"}";
struct NodeInfo { //structure that we want to transmit to our shaders

typedef struct NodeInfo { //structure that we want to transmit to our shaders
float x;
float y;
float s;
float c;
};
} NodeInfo;

GLuint nodeTexture; //texture id used to bind
GLuint nodeSamplerLocation; //shader sampler address
GLuint indicesAttributeLocation; //shader attribute address
GLuint indicesVBO; //Vertex Buffer Object Id;
const int nbNodes = 512;
NodeInfo data[nbNodes]; //our data that will be transmitted using float texture.
#define NUM_NODES 512
NodeInfo data[NUM_NODES]; //our data that will be transmitted using float texture.
double alpha = 0; //use to make a simple funny effect;

static void updateFloatTexture() {
int count = 0;
for (float x=0; x < nbNodes; ++x ) {
data[count].x = 0.2*pow(cos(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * cos(alpha + x/nbNodes * 16. * M_PI);
data[count].y = 0.2*pow(sin(alpha), 3) + (sin(alpha)*3. + 3.5) * x/nbNodes * sin(alpha + x/nbNodes * 16. * M_PI);
data[count].s = (16. + 16. * cos(alpha + x/nbNodes * 32. * M_PI)) + 8.;// * fmod(x/nbNodes + alpha, 1.) + 5.;
data[count].c = 0.5 + 0.5 * sin(alpha + x/nbNodes * 32. * M_PI);
for (float x=0; x < NUM_NODES; ++x ) {
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);
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);
data[count].s = (16. + 16. * cos(alpha + x/NUM_NODES * 32. * M_PI)) + 8.;// * fmod(x/NUM_NODES + alpha, 1.) + 5.;
data[count].c = 0.5 + 0.5 * sin(alpha + x/NUM_NODES * 32. * M_PI);
++count;
}
glBindTexture(GL_TEXTURE_2D, nodeTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
#ifdef __EMSCRIPTEN__ // In GLES2 and WebGL1, we must use unsized texture internal formats.
const GLenum internalFormat = GL_RGBA;
#else
// In desktop GL, we can also use sized internal formats.
const GLenum internalFormat = GL_RGBA32F;
#endif
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, nbNodes, 1, 0, GL_RGBA, GL_FLOAT, data);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, NUM_NODES, 1, 0, GL_RGBA, GL_FLOAT, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
alpha -= 0.001;
}

static void glut_draw_callback(void) {
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
Expand All @@ -93,30 +98,32 @@ static void glut_draw_callback(void) {
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawArrays(GL_POINTS, 0, nbNodes);
glDrawArrays(GL_POINTS, 0, NUM_NODES);
glutSwapBuffers();
}
GLuint createShader(const char source[], int type) {

GLuint createShader(const char* source, int type) {
char msg[512];
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, (const GLchar**)(&source), NULL);
glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader);
glGetShaderInfoLog(shader, sizeof msg, NULL, msg);
std::cout << "Shader info: " << msg << std::endl;
printf("Shader info: %s\n", msg);
return shader;
}

static void gl_init(void) {
GLuint program = glCreateProgram();
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
glAttachShader(program, createShader(fragment_shader, GL_FRAGMENT_SHADER));
glLinkProgram(program);
char msg[512];
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
std::cout << "info: " << msg << std::endl;
printf("info: %s\n", msg);
glUseProgram(program);
std::vector<float> elements(nbNodes);
float elements[NUM_NODES];
int count = 0;
for (float x=0; x < nbNodes; ++x ) {
for (float x=0; x < NUM_NODES; ++x ) {
elements[count] = count;
++count;
}
Expand All @@ -125,10 +132,10 @@ static void gl_init(void) {
/* Store the vertices in a vertex buffer object (VBO) */
glGenBuffers(1, &indicesVBO);
glBindBuffer(GL_ARRAY_BUFFER, indicesVBO);
float zeroes[nbNodes];
float zeroes[NUM_NODES];
memset(zeroes, 0, sizeof(zeroes));
glBufferData(GL_ARRAY_BUFFER, elements.size() * sizeof(float), zeroes, GL_STATIC_DRAW);
for (int x = 0; x < nbNodes; x++) {
glBufferData(GL_ARRAY_BUFFER, NUM_NODES * sizeof(float), zeroes, GL_STATIC_DRAW);
for (int x = 0; x < NUM_NODES; x++) {
glBufferSubData(GL_ARRAY_BUFFER, x * sizeof(float), sizeof(float), &elements[x]);
}
/* Get the locations of the uniforms so we can access them */
Expand All @@ -140,13 +147,14 @@ static void gl_init(void) {
glEnable(GL_POINT_SPRITE);
#endif
}

int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Simple FLOAT Texture Test");
int w = glutCreateWindow("Simple FLOAT Texture Test");
/* Set up glut callback functions */
glutDisplayFunc(glut_draw_callback );
glutDisplayFunc(glut_draw_callback);
gl_init();
glutMainLoop();
return 0;
Expand Down
4 changes: 2 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2320,11 +2320,11 @@ def test_tex_nonbyte(self):

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

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

@requires_graphics_hardware
def test_perspective(self):
Expand Down
3 changes: 0 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5703,9 +5703,6 @@ def test_direct_string_constant_usage(self):
self.set_setting('EXIT_RUNTIME')
self.do_core_test('test_direct_string_constant_usage.cpp')

def test_std_cout_new(self):
self.do_core_test('test_std_cout_new.cpp')

def test_std_function_incomplete_return(self):
self.do_core_test('test_std_function_incomplete_return.cpp')

Expand Down

0 comments on commit 1fd888d

Please sign in to comment.