summaryrefslogtreecommitdiff
path: root/src/gpudataviz.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpudataviz.cpp')
-rw-r--r--src/gpudataviz.cpp61
1 files changed, 47 insertions, 14 deletions
diff --git a/src/gpudataviz.cpp b/src/gpudataviz.cpp
index 91ef5fa..a9ddfae 100644
--- a/src/gpudataviz.cpp
+++ b/src/gpudataviz.cpp
@@ -42,7 +42,22 @@ int main(int argc, char* argv[]) {
GTKWinMain gtkwinmain(glScene);
// Run the app
- gtkKit.run(gtkwinmain);
+ //gtkKit.run(gtkwinmain);
+
+ //FIXME : handle main loop quit, maybe do that logic inside MyGTKGLSceneWidget, find bug with multiple mouse button release
+ while ( true ) {
+ while ( Gtk::Main::events_pending() ) {
+ Gtk::Main::iteration(false);
+ }
+ if ( glScene.continuous_play ) {
+ glScene.step();
+ glScene.queue_draw();
+ std::cout << "." << std::flush;
+ } else {
+ Gtk::Main::iteration(true);
+ std::cout << "!" << std::flush;
+ }
+ }
return 0;
}
@@ -56,7 +71,8 @@ MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr<Gdk::GL::Config> &glconfig)
| Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK \
| Gdk::SCROLL_MASK;
set_events(mask); // The containing window should have those attributes too
- this->camera.rx = -64.0f; this->camera.ry = -16.0f; this->camera.tz = -1.0f;
+ this->camera.rx = -64.0f; this->camera.ry = -16.0f; this->camera.tz = -2.0f;
+ need_recompute=false; time=0.0f; continuous_play=false;
}
MyGTKGLSceneWidget::~MyGTKGLSceneWidget() { }
@@ -118,18 +134,20 @@ void MyGTKGLSceneWidget::on_realize() {
/* calculate uv coordinates of the mesh point [0.0;1.0] */
float u = nx / (float) width;
float v = ny / (float) height;
- /* calculate centered coordinates [-1.0;1.0] */
+ /* calculate centered normalized coordinates [-1.0;1.0] */
float x = u*2.0-1.0;
float y = v*2.0-1.0;
- /* We only use normalized quaterinons here */
- float w = 1.0;
/* Calculate the desirated value of the mesh point */
float freq = 8.0 * 3.14;
float amp = 1.0 / 10.0; /* 0.1 does NOT works ! WTF !!! */
float speed = 1.0;
float dist = sqrt(x*x+y*y);
- float z = amp * sin( freq * dist - speed * time ) / dist ;
-
+ float z;
+ //for(int i = 0; i < 40000; i++){
+ 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);
}
@@ -180,6 +198,16 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) {
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
+ // *** OpenCL BEGIN
+ if (this->need_recompute) {
+ this->need_recompute=false;
+// std::cout << "execKernel(\"water1\", " << this->time << ");" << std::endl;
+ int res = this->clKit.execKernel("water1", this->time);
+ if ( res !=0 ) std::cerr << "execKernel() has returned " << res << std::endl;
+// std::cout << " -> " << res << std::endl;
+ }
+ // *** OpenCL END
+
// *** OpenGL BEGIN ***
if (!glwindow->gl_begin(get_gl_context())) {
std::cerr << "Oups : glwindow->gl_begin(get_gl_context())" << std::endl;
@@ -212,6 +240,11 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) {
return true;
}
+void MyGTKGLSceneWidget::step() {
+ this->time += 0.01f;
+ this->need_recompute = true;
+}
+
bool MyGTKGLSceneWidget::on_motion_notify_event (GdkEventMotion *event) {
return do_mouse_logic(event->type, event->state, event->x, event->y);
}
@@ -283,7 +316,7 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
*/
static GdkEventType prev_type = GDK_NOTHING; // Static variable to hold previous mouse button event
static guint drag_x=0, drag_y=0; // Static for DRAGING displacement calculus
- static float t=0.0f; // XXX Just for playing with time
+ bool recompute=false; // Setting it to true will call OpenCL on next redraw
bool redraw=false; // Setting it to true will queue a redraw to the widget (invalidate)
// For event filter debug (display all events)
@@ -330,14 +363,13 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
redraw=true;
}*/
- MOUSE_DRAGING(GDK_BUTTON1_MASK) {
- t+=0.1f;
- std::cout << "execKernel(\"water1\", " << t << ");" << std::endl;
- int res = this->clKit.execKernel("water1", t);
- std::cout << " -> " << res << std::endl;
- redraw=true;
+ MOUSE_DRAG_START(GDK_BUTTON1_MASK) {
+ this->continuous_play=true;
}
+ MOUSE_DRAG_END(GDK_BUTTON1_MASK) {
+ this->continuous_play=false;
+ }
// Demo filters
MOUSE_CLIC(GDK_BUTTON1_MASK, GDK_SHIFT_MASK, GDK_CONTROL_MASK) {
@@ -356,5 +388,6 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
}
if ( redraw ) queue_draw();
+ if ( recompute ) this->need_recompute=true;
return true;
}