summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/poc_c/main.c83
1 files changed, 40 insertions, 43 deletions
diff --git a/tests/poc_c/main.c b/tests/poc_c/main.c
index a1341c0..ef71052 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
@@ -71,30 +71,31 @@ gboolean gl_area_on_draw (GtkObject* area, GdkEventExpose* event, gpointer void_
// Draw a 1x1 square center on origin and on the x*y plan.
// x*y*z, Z negative forward oriented.
-/*
- glBegin (GL_QUADS);
- glVertex3d ( 0.5, -0.5, 0.0);
- glVertex3d ( 0.5, 0.5, 0.0);
- glVertex3d (-0.5, 0.5, 0.0);
- glVertex3d (-0.5, -0.5, 0.0);
+
+ /*
+ 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(data->mesh_width * data->mesh_height, GL_FLOAT, 0, (GLvoid *) 0);
+ glVertexPointer(4, GL_FLOAT, 0, (GLvoid *) 0);
glEnableClientState(GL_VERTEX_ARRAY);
- glDrawArrays(GL_POINTS/*GL_QUADS*/, 0, 4);
+ glDrawArrays(GL_POINTS, 0, data->mesh_width * data->mesh_height);
glDisableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
+
gdk_gl_drawable_swap_buffers (drawable);
gdk_gl_drawable_gl_end (drawable);
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;
@@ -109,37 +110,27 @@ cl_int execKernel(cl_context cl_ctx, cl_command_queue commandQueue, cl_kernel ke
res=clEnqueueAcquireGLObjects(commandQueue, 1, &cl_vbo, 0, 0, NULL);
- res=clSetKernelArg(kernel, 0, sizeof(cl_mem), &cl_vbo); /* float4 *pos */
+ res=clSetKernelArg(kernel, 0, sizeof(cl_mem), &cl_vbo); // float4 *pos
res=clSetKernelArg(kernel, 1, sizeof(cl_uint), (void *)&mesh_width);
res=clSetKernelArg(kernel, 2, sizeof(cl_uint), (void *)&mesh_height);
res=clSetKernelArg(kernel, 3, sizeof(float), &time);
// Execute kernel on given device
res=clEnqueueNDRangeKernel(commandQueue, kernel, 2, NULL, globalWorkSize, localWorkSize, 0, NULL, eventND);
- /* cl_int clEnqueueNDRangeKernel (cl_command_queue command_queue,
- cl_kernel kernel,
- cl_uint work_dim,
- const size_t *global_work_offset, 1.0 spec say "must be NULL" (for future usage)
- const size_t *global_work_size,
- const size_t *local_work_size,
- cl_uint num_events_in_wait_list,
- const cl_event *event_wait_list,
- cl_event *event)
- */
if ( res != CL_SUCCESS ) {
fputs("Failed to clEnqueueNDRangeKernel()\n", stderr);
return 1;
}
res=clFlush(commandQueue);
- res=clWaitForEvents(1,eventND); /*XXX: SimpleGL utilie une attente active, pourquoi ? */
+ res=clWaitForEvents(1,eventND); //XXX: SimpleGL utilie une attente active, pourquoi ?
res=clReleaseEvent(eventND[0]);
res=clEnqueueReleaseGLObjects(commandQueue, 1, &cl_vbo, 0, 0, 0);
res=clFinish(commandQueue);
return CL_SUCCESS;
}
-
+*/
int main(int argc, char *argv[]) {
GtkWidget* main_win;
GtkVBox* main_box;
@@ -231,16 +222,18 @@ 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 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];
@@ -272,7 +265,7 @@ int main(int argc, char *argv[]) {
clGetPlatformInfo(plat_id, CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL);
printf("Plaform %i (id %p) : VENDOR : '%s'\n", i, (void *) plat_id, pbuf);
- /* CL_CONTEXT_PLATFORM value filled now */
+ // CL_CONTEXT_PLATFORM value filled now
cpsGL[1]=(cl_context_properties) plat_id;
// TODO : use the clGetGLContextInfoKHR() normally when available
@@ -314,17 +307,24 @@ 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=2, mesh_height=2, 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);
@@ -334,19 +334,21 @@ int main(int argc, char *argv[]) {
on_expose_data.mesh_width = mesh_width;
on_expose_data.mesh_height = mesh_height;
- /* to be removed : default values
- glBufferSubData(GL_ARRAY_BUFFER,0, gl_vbo_data_size, gl_vertex_default_pos);
- */
+ // to be removed : default values
+ glBufferSubData(GL_ARRAY_BUFFER,0, 16* sizeof(cl_float4) /*gl_vbo_data_size*/, 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) { \
unsigned int x = get_global_id(0); \
@@ -363,7 +365,7 @@ __kernel void zero_z(__global float4 * pos, unsigned int width, unsigned int hei
}\
";
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);
@@ -387,20 +389,15 @@ __kernel void zero_z(__global float4 * pos, unsigned int width, unsigned int hei
fputs(buildLog, stderr);
free(buildLog);
fputs("\n************************************************\n", stderr);
-/*
- fputs("\n SOURCE\n", stderr);
- fputs("************************************************\n", stderr);
- fputs(source, stderr);
- fputs("\n************************************************\n", stderr);
-*/
return EXIT_FAILURE;
}
}
cl_kernel kernel = clCreateKernel(program,"zero_z",&res);
- execKernel(cl_ctx, commandQueue, kernel, mesh_width, mesh_height, group_size, cl_vbo, /*time*/0.0f);
+ execKernel(cl_ctx, commandQueue, kernel, mesh_width, mesh_height, group_size, cl_vbo, 0.0f);
clReleaseKernel(kernel);
+*/
gtk_main();
return EXIT_SUCCESS;
}