Changeset 8804:6852c45a40f1 in orange
 Timestamp:
 08/26/11 13:56:39 (3 years ago)
 Branch:
 default
 Convert:
 7c2f93fe26afd6902d761ff7ed9de549ff3a1f2d
 Location:
 source/orangeqt
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

source/orangeqt/plot3d.cpp
r8792 r8804 13 13 typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); 14 14 PFNGLGETVERTEXATTRIBPOINTERPROC glVertexAttribPointer = NULL; 15 typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); 16 PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = NULL; 17 //typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); 18 PFNGLUNIFORM2FPROC glUniform2f = NULL; 15 19 16 20 #define BUFFER_OFFSET(i) ((char *)NULL + (i)) … … 37 41 void Plot3D::set_symbol_geometry(int symbol, int type, const QList<QVector3D>& geometry) 38 42 { 39 if (type == 0) 40 geometry_data_2d[symbol] = geometry; 41 else if (type == 1) 42 geometry_data_3d[symbol] = geometry; 43 else 44 geometry_data_edges[symbol] = geometry; 43 switch (type) 44 { 45 case 0: 46 geometry_data_2d[symbol] = geometry; 47 break; 48 case 1: 49 geometry_data_3d[symbol] = geometry; 50 break; 51 case 2: 52 geometry_data_edges_2d[symbol] = geometry; 53 break; 54 case 3: 55 geometry_data_edges_3d[symbol] = geometry; 56 break; 57 default: 58 std::cout << "Wrong geometry type!" << std::endl; 59 } 45 60 } 46 61 … … 61 76 glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)glXGetProcAddress((const GLubyte*)"glEnableVertexAttribArray"); 62 77 glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)glXGetProcAddress((const GLubyte*)"glDisableVertexAttribArray"); 78 glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)glXGetProcAddress((const GLubyte*)"glGetUniformLocation"); 79 glUniform2f = (PFNGLUNIFORM2FPROC)glXGetProcAddress((const GLubyte*)"glUniform2f"); 63 80 #endif 64 81 } … … 71 88 const float scale = 0.001; 72 89 float* vbo_data = new float[num_examples * 144 * 13]; 90 float* vbo_edges_data = new float[num_examples * 144 * 13]; 73 91 float* dest = vbo_data; 92 float* dest_edges = vbo_edges_data; 74 93 int size_in_bytes = 0; 94 int size_in_bytes_edges = 0; 75 95 QMap<int, QList<QVector3D> >& geometry = use_2d_symbols ? geometry_data_2d : geometry_data_3d; 96 QMap<int, QList<QVector3D> >& geometry_edges = use_2d_symbols ? geometry_data_edges_2d : geometry_data_edges_3d; 76 97 77 98 for (int index = 0; index < num_examples; ++index) … … 130 151 } 131 152 } 153 154 for (int i = 0; i < geometry_edges[symbol].count(); i += 2) { 155 size_in_bytes_edges += 2*13*4; 156 157 for (int j = 0; j < 2; ++j) 158 { 159 *dest_edges = x_pos; dest_edges++; 160 *dest_edges = y_pos; dest_edges++; 161 *dest_edges = z_pos; dest_edges++; 162 163 *dest_edges = geometry_edges[symbol][i+j].x()*size*scale; dest_edges++; 164 *dest_edges = geometry_edges[symbol][i+j].y()*size*scale; dest_edges++; 165 *dest_edges = geometry_edges[symbol][i+j].z()*size*scale; dest_edges++; 166 167 *dest_edges = color.redF(); dest_edges++; 168 *dest_edges = color.greenF(); dest_edges++; 169 *dest_edges = color.blueF(); dest_edges++; 170 171 // Just use offset 172 *dest_edges = geometry_edges[symbol][i+j].x(); dest_edges++; 173 *dest_edges = geometry_edges[symbol][i+j].y(); dest_edges++; 174 *dest_edges = geometry_edges[symbol][i+j].z(); dest_edges++; 175 176 *dest_edges = index; dest_edges++; 177 } 178 } 132 179 } 133 180 … … 139 186 delete [] vbo_data; 140 187 188 glGenBuffers(1, &vbo_edges_id); 189 glBindBuffer(GL_ARRAY_BUFFER, vbo_edges_id); 190 glBufferData(GL_ARRAY_BUFFER, size_in_bytes_edges, vbo_edges_data, GL_STATIC_DRAW); 191 glBindBuffer(GL_ARRAY_BUFFER, 0); 192 193 delete [] vbo_edges_data; 194 141 195 num_vertices = size_in_bytes / (13*4); 196 num_edges_vertices = size_in_bytes_edges / (13*4); 142 197 vbo_generated = true; 143 198 } 144 199 145 void Plot3D::draw_data( )200 void Plot3D::draw_data(GLuint shader_id, float alpha_value) 146 201 { 147 202 if (!vbo_generated) 148 203 return; 204 205 glUniform2f(glGetUniformLocation(shader_id, "alpha_value"), alpha_value0.4, alpha_value0.4); 149 206 150 207 glBindBuffer(GL_ARRAY_BUFFER, vbo_id); … … 168 225 glDisableVertexAttribArray(4); 169 226 227 glUniform2f(glGetUniformLocation(shader_id, "alpha_value"), alpha_value, alpha_value); 228 229 // Edges 230 glBindBuffer(GL_ARRAY_BUFFER, vbo_edges_id); 231 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 13*4, BUFFER_OFFSET(0)); 232 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 13*4, BUFFER_OFFSET(3*4)); 233 glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 13*4, BUFFER_OFFSET(6*4)); 234 glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 13*4, BUFFER_OFFSET(9*4)); 235 glVertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, 13*4, BUFFER_OFFSET(12*4)); 236 glEnableVertexAttribArray(0); 237 glEnableVertexAttribArray(1); 238 glEnableVertexAttribArray(2); 239 glEnableVertexAttribArray(3); 240 glEnableVertexAttribArray(4); 241 242 glDrawArrays(GL_LINES, 0, num_edges_vertices); 243 244 glDisableVertexAttribArray(0); 245 glDisableVertexAttribArray(1); 246 glDisableVertexAttribArray(2); 247 glDisableVertexAttribArray(3); 248 glDisableVertexAttribArray(4); 249 170 250 glBindBuffer(GL_ARRAY_BUFFER, 0); 171 251 } 
source/orangeqt/plot3d.h
r8792 r8804 20 20 const QList<QColor>& colors, int num_symbols_used, 21 21 bool x_discrete, bool y_discrete, bool z_discrete, bool use_2d_symbols); 22 void draw_data( );22 void draw_data(GLuint shader_id, float alpha_value); 23 23 24 24 private: … … 27 27 int example_size; 28 28 int num_vertices; 29 int num_edges_vertices; 29 30 GLuint vbo_id; 31 GLuint vbo_edges_id; 30 32 bool vbo_generated; 31 33 32 34 QMap<int, QList<QVector3D> > geometry_data_2d; 33 35 QMap<int, QList<QVector3D> > geometry_data_3d; 34 QMap<int, QList<QVector3D> > geometry_data_edges; 36 QMap<int, QList<QVector3D> > geometry_data_edges_2d; 37 QMap<int, QList<QVector3D> > geometry_data_edges_3d; 35 38 }; 36 39 
source/orangeqt/plot3d.sip
r8785 r8804 17 17 const QList<QColor>& colors, int num_symbols_used, 18 18 bool x_discrete, bool y_discrete, bool z_discrete, bool use_2d_symbols); 19 void draw_data( );19 void draw_data(GLuint shader_id, float alpha_value); 20 20 };
Note: See TracChangeset
for help on using the changeset viewer.