From f88f52617be9966cddd3ec28d590704fb8a615eb Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Fri, 19 Apr 2013 20:46:21 +0000 Subject: Ajout option -Werror et affichage lorsque ca compile pas. Amelioration des kernels en conséquence. Bugfix avec le sizeof(source) qui prennait un caractère de trop (le '\0') MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2013-gpudataviz/trunk@31 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d --- src/gpudataviz.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/gpudataviz.cpp') diff --git a/src/gpudataviz.cpp b/src/gpudataviz.cpp index 1dc14f8..a3e577e 100644 --- a/src/gpudataviz.cpp +++ b/src/gpudataviz.cpp @@ -123,33 +123,38 @@ void MyGTKGLSceneWidget::on_realize() { const char source[]=STRINGIFY( /* This is OpenCL kernel code (Syntax like C but it's a different language) */ + __kernel void water1(__global float4 *pos, unsigned int width, unsigned int height, float time) { + /* Getting current vertex indices (could be seen as a 2D array of float4) */ unsigned int nx = get_global_id(0); unsigned int ny = get_global_id(1); - /* calculate uv coordinates of the mesh point [0.0;1.0] */ - float u = nx / (float) width; - float v = ny / (float) height; - /* calculate centered normalized coordinates [-1.0;1.0] */ - float x = u*2.0-1.0; - float y = v*2.0-1.0; - /* set some constants and calculate some intermediate values */ - float freq = 8.0 * 3.14; - float speed = 1.0; - float amp = 1.0 / 10.0; /* 0.1 does NOT works for me ! WTF !!! */ - float dist = sqrt(x*x+y*y); - /* Calculate the desirated value of the mesh point */ - float z = amp * sin( freq * dist + speed * time ) / dist ; - /* We only use normalized quaterinons here */ - float w = 1.0; - /* Write output vertex (centered) */ - pos[ny*width+nx] = (float4)(x, y, z, w); + /* A float4 vector that hold the output vertex */ + float4 out; + + /* Calculate centered mesh coordinates [-1.0;1.0]² */ + out.x = nx / (float) width * 2.0f - 1.0f; + out.y = ny / (float) height * 2.0f - 1.0f; + + /* Set some constants (should be preprocessor macros...) */ + float freq = 8.0f; + float speed = 1.0f; + float amp = 1.0f / 10.0f; /* 0.1f does NOT works for me ! WTF !!! */ + + /* Calculate some intermediate values */ + float dist = hypot(out.x,out.y); /* =sqrt(out.x*out.x+out.y*out.y); */ + + /* Calculate the desirated value of the mesh point z=f(x,y,t) */ + out.z = amp * sinpi( freq * dist + speed * time ) / dist ; + out.w = 1.0f; /* We always use normalized quaterinons here */ + + pos[ny*width+nx] = out; /* Write output vertex */ } ); // TODO : change API, use only one string and split it at each blanks //std::list knames; //knames.push_back("water1"); - cl_res = this->clKit.compileKernels(/*knames,*/ source, sizeof(source)); + cl_res = this->clKit.compileKernels(/*knames,*/ source, sizeof(source)-1); //knames.clear(); EXIT_IF_FAIL(6, cl_res==0); -- cgit v1.2.3