summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gpudataviz.cpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/src/gpudataviz.cpp b/src/gpudataviz.cpp
index 1f59768..89adf40 100644
--- a/src/gpudataviz.cpp
+++ b/src/gpudataviz.cpp
@@ -47,9 +47,8 @@ int main(int argc, char* argv[]) {
return 0;
}
-/* MyGTKGLSceneWidget implementation (extends a Gtk::DrawingArea with Gtk::GL::Widget)
- I want to keep all interesting code parts in this file, in natural reading order
-*/
+// MyGTKGLSceneWidget implementation (extends a Gtk::DrawingArea with Gtk::GL::Widget)
+// I want to keep all interesting code parts in this file, in natural reading order
MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr<Gdk::GL::Config> &glconfig) {
CALL_TRACE;
set_gl_capability(glconfig);
@@ -57,8 +56,10 @@ 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
+
+ // Some starting default values
this->camera.rx = -64.0f; this->camera.ry = -16.0f; this->camera.tz = -2.0f;
- need_recompute=false; time=0.0f; continuous_play=false;
+ need_recompute=false; continuous_play=false; time=0.0f;
}
MyGTKGLSceneWidget::~MyGTKGLSceneWidget() { }
@@ -78,21 +79,22 @@ void MyGTKGLSceneWidget::on_realize() {
// *** OpenGL BEGIN ***
GLenum gl_res;
if (!glwindow->gl_begin(get_gl_context())) {
- std::cerr << "Oups : glwindow->gl_begin(get_gl_context())" << std::endl;
+ std::cerr << "Oops : glwindow->gl_begin(get_gl_context())" << std::endl;
return;
}
EXIT_IF_FAIL(3, Gdk::GL::query_gl_extension("GL_ARB_vertex_buffer_object") );
EXIT_IF_FAIL(4, glewInit() == 0 );
- //size_t mesh_width=256, mesh_height=256, group_size=256; // TODO : not here
- //size_t mesh_width=512, mesh_height=512, group_size=256; // TODO : not here
- //size_t mesh_width=1024, mesh_height=1024, group_size=256; // TODO : not here
- size_t mesh_width=2048, mesh_height=2048, group_size=256; // TODO : not here
+ // TODO : mesh size should not be fixed here
+ //size_t mesh_width=256, mesh_height=256, group_size=256;
+ //size_t mesh_width=512, mesh_height=512, group_size=256;
+ size_t mesh_width=1024, mesh_height=1024, group_size=256;
+ //size_t mesh_width=2048, mesh_height=2048, group_size=256;
GLuint gl_vbo=0;
GLsizeiptr gl_vbo_data_size = mesh_width * mesh_height * sizeof(cl_float4);
- std::cout << "gl_vbo_data_size==" << gl_vbo_data_size << std::endl;
+ //std::cout << "gl_vbo_data_size==" << gl_vbo_data_size << std::endl;
glGenBuffers(1, &gl_vbo);
glBindBuffer(GL_ARRAY_BUFFER, gl_vbo);
@@ -108,12 +110,12 @@ void MyGTKGLSceneWidget::on_realize() {
intptr_t gl_context = (intptr_t)glXGetCurrentContext();
intptr_t gl_display = (intptr_t)glXGetCurrentDisplay();
//#else
-// #error initOpenCL works only for X11 systems for now
+// #error This code works only for X11 systems for now
//#endif
int cl_res = this->clKit.initCL(gl_display, gl_context, gl_vbo, mesh_width, mesh_height, group_size);
EXIT_IF_FAIL(cl_res, cl_res==0);
- this->clKit.resetVBO(); // XXX Just for displaying a flat mesh at start
+ this->clKit.resetVBO(); // Just for displaying a flat mesh at start
const char source[]=STRINGIFY(
/* This is OpenCL kernel code (Syntax like C but it's a different language) */
@@ -128,7 +130,7 @@ void MyGTKGLSceneWidget::on_realize() {
float y = v*2.0-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 amp = 1.0 / 10.0; /* 0.1 does NOT works for me ! WTF !!! */
float speed = 1.0;
float dist = sqrt(x*x+y*y);
float z;
@@ -142,17 +144,17 @@ void MyGTKGLSceneWidget::on_realize() {
}
);
+ // TODO : change API, use only one string and split it at each blanks
std::list<std::string> knames;
knames.push_back("water1");
cl_res = this->clKit.compileKernels(knames, source, sizeof(source));
-
- EXIT_IF_FAIL(6, cl_res==0);
knames.clear();
+ EXIT_IF_FAIL(6, cl_res==0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Projection setup is done at on_configure_event
- // Camera setup (ie initial MODELVIEW matrix) is done at on_expose_event
+ // Camera setup (ie MODELVIEW matrix) is done at on_expose_event
glwindow->gl_end();
// *** OpenGL END ***
@@ -168,7 +170,7 @@ bool MyGTKGLSceneWidget::on_configure_event(GdkEventConfigure* event) {
// *** OpenGL BEGIN ***
//FIXME could segfault if get_gl_window() has failed
if (!glwindow->gl_begin(get_gl_context())) {
- std::cerr << "Oups : glwindow->gl_begin(get_gl_context())" << std::endl;
+ std::cerr << "Oops : glwindow->gl_begin(get_gl_context())" << std::endl;
return false;
}
@@ -184,12 +186,12 @@ bool MyGTKGLSceneWidget::on_configure_event(GdkEventConfigure* event) {
}
bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) {
- std::cout << "e" << std::flush;
// CALL_TRACE ; // This one runs mainly when GTK GL Widget have to be redrawn
+ std::cout << "e" << std::flush;
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
- // *** OpenCL BEGIN
+ // *** OpenCL BEGIN ***
if (this->need_recompute) {
this->need_recompute=false;
//std::cout << "execKernel(\"water1\", " << this->time << ");" << std::endl;
@@ -198,11 +200,11 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) {
if ( res !=0 ) std::cerr << "execKernel() has returned " << res << std::endl;
//std::cout << " -> " << res << std::endl;
}
- // *** OpenCL END
+ // *** OpenCL END ***
// *** OpenGL BEGIN ***
if (!glwindow->gl_begin(get_gl_context())) {
- std::cerr << "Oups : glwindow->gl_begin(get_gl_context())" << std::endl;
+ std::cerr << "Oops : glwindow->gl_begin(get_gl_context())" << std::endl;
return false;
}
@@ -224,23 +226,21 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) {
float t_z=this->camera.tz;
// Vertex alpha blending automatic tuning (if big density then high transparency)
- /* The comprehensible one
- float c1=(1024*1024)/(m_w*m_h);
- float c2=(s_h*s_h)/(1024*1024);
- float c3=(-2*-2)/(t_z*t_z);
- float alpha=0.5*c1*c2*c3;
- if (alpha < 0.01f) alpha = 0.01f;
- if (alpha > 1.0f) alpha = 1.0f;
- */
- //std::cout << "c1 == " << c1 << " c2 == " << c2 << " c3 == " << c3 << " alpha == " << alpha << std::endl;;
-
- /* The optimized one */
+ // The comprehensible one
+ //float c1=(1024*1024)/(m_w*m_h); // coef 1 decreases with mesh point quantity
+ //float c2=(s_h*s_h)/(1024*1024); // coef 2 increases with viewport pixel quantity
+ //float c3=(-2*-2)/(t_z*t_z); // coef 3 decreases with mesh-camera distance
+ //float alpha=0.5*c1*c2*c3; // Combine it all
+ //if (alpha < 0.01f) alpha = 0.01f; // Prevent values outside acceptable range
+ //if (alpha > 1.0f) alpha = 1.0f;
+ //std::cout <<"c1="<<c1<<" c2="<<c2<<" c3="<<c3<<" alpha="<<alpha<<std::endl;
+
+ // The compacted one
float alpha=2.0f*(s_h*s_h)/(m_w*m_h)/(t_z*t_z);
if (alpha < 0.01f) alpha = 0.01f;
if (alpha > 1.0f) alpha = 1.0f;
- //std::cout << "c1 == " << c1 << " c2 == " << c2 << " c3 == " << c3 << " alpha == " << alpha << std::endl;;
- glColor4f(0.40f,0.78f,0.97f,alpha);
+ glColor4f(0.40f,0.78f,0.97f,alpha); // XXX Blue is great but it's fixed here and shouldn't
glBindBuffer(GL_ARRAY_BUFFER, this->clKit.getGLVBO());
glVertexPointer(4, GL_FLOAT, 0, (GLvoid *) 0);
glEnableClientState(GL_VERTEX_ARRAY);
@@ -256,27 +256,27 @@ bool MyGTKGLSceneWidget::on_expose_event(GdkEventExpose* event) {
return true;
}
+// Update time (and flags) for continuous_play mode
void MyGTKGLSceneWidget::step() {
- this->time += 0.05f;
+ this->time += 0.01f;
this->need_recompute = true;
}
+// Combine all kind of mouse event and redirect them to a unique method : do_mouse_logic()
bool MyGTKGLSceneWidget::on_motion_notify_event (GdkEventMotion *event) {
return do_mouse_logic(event->type, event->state, event->x, event->y);
}
-
bool MyGTKGLSceneWidget::on_button_press_event(GdkEventButton *event) {
return do_mouse_logic(event->type, event->state | 1<<(7+event->button) , event->x, event->y);
}
-
bool MyGTKGLSceneWidget::on_button_release_event(GdkEventButton *event) {
return do_mouse_logic(event->type, event->state, event->x, event->y);
}
-
bool MyGTKGLSceneWidget::on_scroll_event(GdkEventScroll *event) {
return do_mouse_logic(event->type, event->state | 1<<(7+event->direction) , event->x, event->y);
}
+// Define helper macros to filter mouse events in do_mouse_logic()
#define ALL_KEYBOARD_MODIFIERS ( GDK_SHIFT_MASK | GDK_CONTROL_MASK \
| GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK )
@@ -307,7 +307,6 @@ bool MyGTKGLSceneWidget::on_scroll_event(GdkEventScroll *event) {
( type == GDK_MOTION_NOTIFY ) \
&& ( state & state_mask ) == state_mask \
)
-
//FIXME find bug with multiple mouse button release
#define MOUSE_DRAG_END(state_mask) if ( \
type == GDK_BUTTON_RELEASE \
@@ -315,8 +314,8 @@ bool MyGTKGLSceneWidget::on_scroll_event(GdkEventScroll *event) {
)
bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x, guint y) {
- std::cout << "m" << std::flush;
//CALL_TRACE ; // This one runs when a mouse event is catched by the GTK GL Widget
+ std::cout << "m" << std::flush;
/*
* type : the type of the event.
* Simple motion : GDK_MOTION_NOTIFY (3)
@@ -382,12 +381,14 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
redraw=true;
}*/
+ // Enabling continous_play mode
MOUSE_DRAG_START(GDK_BUTTON1_MASK) {
this->continuous_play=true;
- // The trick to have a perpetual redraw : generate a draw event in the idle signal
+ // The trick to have a perpetual redraw : generate a draw event in the idle signal handler
Glib::signal_idle().connect( sigc::mem_fun(*this, &MyGTKGLSceneWidget::on_gtk_idle) );
}
+ // Disabling continous_play mode
MOUSE_DRAG_END(GDK_BUTTON1_MASK) {
this->continuous_play=false;
}
@@ -408,9 +409,8 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
prev_type=type;
}
- if ( redraw ) std::cout << "q" << std::flush;
- if ( redraw ) queue_draw();
- if ( recompute ) this->need_recompute=true;
+ if ( redraw ) { queue_draw(); std::cout << "q" << std::flush; }
+ if ( recompute ) { this->need_recompute=true; }
return true;
}
@@ -422,6 +422,7 @@ bool MyGTKGLSceneWidget::on_gtk_idle() {
// Disconnected automatically the first time it returns false
if ( ! continuous_play ) return false;
+ //TODO : compute and display FPS when in continuous_play mode
this->step();
this->queue_draw();
return true;