summaryrefslogtreecommitdiff
path: root/tests/poc_c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/poc_c')
-rw-r--r--tests/poc_c/main.c80
1 files changed, 27 insertions, 53 deletions
diff --git a/tests/poc_c/main.c b/tests/poc_c/main.c
index ef71052..5aef940 100644
--- a/tests/poc_c/main.c
+++ b/tests/poc_c/main.c
@@ -9,7 +9,7 @@
#include <GL/glew.h> // For VBO OpenGL extensions
#include <GL/glu.h>
-//#include <CL/opencl.h>
+#include <CL/opencl.h>
#include <gdk/x11/gdkglx.h> // X11 specific
@@ -51,7 +51,7 @@ gboolean gl_area_on_draw (GtkObject* area, GdkEventExpose* event, gpointer void_
GLdouble projection_dx = 0.0;
GLdouble projection_dy = 0.0;
- GLdouble projection_dz = -3.0;
+ GLdouble projection_dz = -2.0;
// Reset picture.
glViewport (0, 0, (GLint) viewport_width, (GLint) viewport_height);
@@ -66,20 +66,7 @@ gboolean gl_area_on_draw (GtkObject* area, GdkEventExpose* event, gpointer void_
glLoadIdentity ();
gluPerspective (fovy, aspect, zNear, zFar);
glTranslated (projection_dx, projection_dy, projection_dz);
- // Use the line below instead of the two above, for non perspective view.
- // glOrtho (-aspect, +aspect, -1.0, +1.0, zNear, zFar);
-
- // Draw a 1x1 square center on origin and on the x*y plan.
- // x*y*z, Z negative forward oriented.
-
- /*
- glBegin (GL_POINTS);
- glVertex3d ( 0.3, -0.3, 0.0);
- glVertex3d ( 0.3, 0.3, 0.0);
- glVertex3d (-0.3, 0.3, 0.0);
- glVertex3d (-0.3, -0.3, 0.0);
- glEnd ();
- */
+
if (data->gl_vbo) {
glBindBuffer(GL_ARRAY_BUFFER, data->gl_vbo);
glVertexPointer(4, GL_FLOAT, 0, (GLvoid *) 0);
@@ -95,7 +82,7 @@ gboolean gl_area_on_draw (GtkObject* area, GdkEventExpose* event, gpointer void_
return TRUE; // Do not propagate the event.
}
-/*
+
cl_int execKernel(cl_context cl_ctx, cl_command_queue commandQueue, cl_kernel kernel, size_t mesh_width, size_t mesh_height, size_t group_size, cl_mem cl_vbo, float time) {
cl_int res;
@@ -130,7 +117,7 @@ cl_int execKernel(cl_context cl_ctx, cl_command_queue commandQueue, cl_kernel ke
return CL_SUCCESS;
}
-*/
+
int main(int argc, char *argv[]) {
GtkWidget* main_win;
GtkVBox* main_box;
@@ -165,9 +152,9 @@ int main(int argc, char *argv[]) {
gl_area = GTK_DRAWING_AREA(gtk_drawing_area_new());
gl_config = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH);
res = gtk_widget_set_gl_capability(GTK_WIDGET(gl_area), gl_config,
- /* GdkGLContext *share_list */ NULL,
- /* gboolean direct */ TRUE,
- /* int render_type */ GDK_GL_RGBA_TYPE);
+ NULL, // GdkGLContext *share_list
+ TRUE, // gboolean direct
+ GDK_GL_RGBA_TYPE); //int render_type
if ( !res ) {
fputs ("Failed to set_gl_capability(gl_area)\n", stderr);
return EXIT_FAILURE;
@@ -177,7 +164,7 @@ int main(int argc, char *argv[]) {
gtk_widget_show_all(main_win);
- /* gl_area needs to be realized to do that (so, it is after gtk_widget_show_all(main_win) )*/
+ // gl_area needs to be realized to do that (so, it is after gtk_widget_show_all(main_win) )
gl_context=gtk_widget_get_gl_context(GTK_WIDGET(gl_area));
if ( !gl_context) {
fputs ("Failed to get_gl_context(gl_area)\n", stderr);
@@ -199,15 +186,6 @@ int main(int argc, char *argv[]) {
/* BEGIN : X11 specific */
-
- /*
- glx_context=gdk_x11_gl_context_get_glxcontext(gl_context);
- if ( !glx_context) {
- fputs ("Failed to gdk_x11_gl_context_get_glxcontext(gl_context)\n", stderr);
- return EXIT_FAILURE;
- }
- printf("glx_context==%p\n", (void *)glx_context);
- */
glx_context=glXGetCurrentContext();
if ( !glx_context ) {
fputs ("Failed to glXGetCurrentContext()", stderr);
@@ -222,18 +200,15 @@ int main(int argc, char *argv[]) {
printf("glx_current_context==%p\n", (void *)glx_context);
printf("glx_current_display==%p\n", (void *)glx_display);
- /*
cl_context_properties cpsGL[] = {
// CL_CONTEXT_PLATFORM value to be filled later
CL_CONTEXT_PLATFORM, (cl_context_properties) NULL,
CL_GLX_DISPLAY_KHR, (intptr_t) glx_display,
CL_GL_CONTEXT_KHR, (intptr_t) glx_context, 0
};
- */
/* END : X11 specific */
gdk_gl_drawable_gl_end (drawable);
-/*
cl_uint i, plat_count;
cl_platform_id *plat_ids, plat_id;
char pbuf[100];
@@ -307,65 +282,64 @@ int main(int argc, char *argv[]) {
break;
}
-*/
- unsigned int mesh_width=32, mesh_height=32, group_size=2;
- // To be removed
- typedef struct {
- float x,y,z,w;
- } cl_float4;
+ unsigned int mesh_width=32, mesh_height=32, group_size=2;
//fprintf(stderr, "sizeof(cl_float4)==%ld\n", sizeof(cl_float4));
GLsizeiptr gl_vbo_data_size = mesh_width * mesh_height * sizeof(cl_float4);
+/*
float gl_vertex_default_pos[16] = { // to be removed
0.5, -0.5, 0.0, 1.0,
0.5, 0.5, 0.0, 1.0,
-0.5, 0.5, 0.0, 1.0,
-0.5, -0.5, 0.0, 1.0
};
-
+*/
res = gdk_gl_drawable_gl_begin(drawable, gl_context);
glGenBuffers(1, &gl_vbo);
glBindBuffer(GL_ARRAY_BUFFER, gl_vbo);
- glBufferData(GL_ARRAY_BUFFER, gl_vbo_data_size, NULL, GL_STREAM_DRAW /*GL_DYNAMIC_DRAW vu dans SimpleGL de ATI*/);
+ glBufferData(GL_ARRAY_BUFFER, gl_vbo_data_size, NULL, GL_STREAM_DRAW); // GL_DYNAMIC_DRAW vu dans SimpleGL de ATI
on_expose_data.gl_vbo = gl_vbo;
on_expose_data.mesh_width = mesh_width;
on_expose_data.mesh_height = mesh_height;
// to be removed : default values
- glBufferSubData(GL_ARRAY_BUFFER,0, 16* sizeof(cl_float4) /*gl_vbo_data_size*/, gl_vertex_default_pos);
+ //glBufferSubData(GL_ARRAY_BUFFER,0, 16* sizeof(cl_float4), gl_vertex_default_pos);
- /*
+
cl_mem cl_vbo = clCreateFromGLBuffer(cl_ctx, CL_MEM_WRITE_ONLY, gl_vbo, &res);
if ( res!=CL_SUCCESS ) {
fputs ("Failed to clCreateFromGLBuffer()\n", stderr);
return EXIT_FAILURE;
}
-*/
+
glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind buffer (no more current buffer)
gdk_gl_drawable_gl_end (drawable);
const char *source="\
-__kernel void zero_z(__global float4 * pos, unsigned int width, unsigned int height, float time) { \
+__kernel void zero_z(__global float4 *pos, unsigned int width, unsigned int height, float time) { \
unsigned int x = get_global_id(0); \
unsigned int y = get_global_id(1); \
- /* calculate uv coordinates */ \
+ /* calculate uv coordinates of the mesh point [0.0;1.0] */ \
float u = x / (float) width; \
float v = y / (float) height; \
- /* Only normalized quaterinons here */ \
+ /* calculate centered coordinates [-0.5;0.5] */\
+ float u2 = (u*2-1)/2;\
+ float v2 = (v*2-1)/2;\
+ /* We only use normalized quaterinons here */ \
float w = 1.0f; \
- /* Calculate the desirated value */ \
+ /* Calculate the desirated value of the mesh point */ \
float z = 0.0f; \
- /* Write output vertex */\
- pos[y*width+x] = (float4)(u - 0.5f, v - 0.5f, z, w); \
+ /* Write output vertex (centered) */\
+ pos[y*width+x] = (float4)(u2, v2, z, w); \
}\
";
size_t sourceLen=strlen(source);
-/*
+
cl_program program = clCreateProgramWithSource(cl_ctx, 1, &source, &sourceLen,&res);
if ( res!=CL_SUCCESS ) {
fputs("Failed to clCreateProgramWithSource()\n", stderr);
@@ -397,7 +371,7 @@ __kernel void zero_z(__global float4 * pos, unsigned int width, unsigned int hei
execKernel(cl_ctx, commandQueue, kernel, mesh_width, mesh_height, group_size, cl_vbo, 0.0f);
clReleaseKernel(kernel);
-*/
+
gtk_main();
return EXIT_SUCCESS;
}