91 shader = glCreateShader (type);
92 glShaderSource (shader, 1, & src, NULL);
93 glCompileShader (shader);
95 glGetShaderiv (shader, GL_COMPILE_STATUS, &
status);
100 glGetShaderiv (shader, GL_INFO_LOG_LENGTH, & log_len);
101 buffer = g_malloc (log_len + 1);
102 glGetShaderInfoLog (shader, log_len, NULL, buffer);
103 g_warning (
"Compile failure in %s shader:\n%s",
104 type == GL_VERTEX_SHADER ?
"vertex" :
"fragment",
108 glDeleteShader (shader);
133#define MATERIAL_DATA 6
165 lightning[0] = glGetUniformLocation (glsl ->
id,
"m_view");
166 lightning[1] = glGetUniformLocation (glsl ->
id,
"lights_on");
167 lightning[2] = glGetUniformLocation (glsl ->
id,
"mat.albedo");
168 lightning[3] = glGetUniformLocation (glsl ->
id,
"mat.metallic");
169 lightning[4] = glGetUniformLocation (glsl ->
id,
"mat.roughness");
170 lightning[5] = glGetUniformLocation (glsl ->
id,
"mat.back_light");
171 lightning[6] = glGetUniformLocation (glsl ->
id,
"mat.gamma");
172 lightning[7] = glGetUniformLocation (glsl ->
id,
"mat.alpha");
173 lightning[8] = glGetUniformLocation (glsl ->
id,
"fog.mode");
174 lightning[9] = glGetUniformLocation (glsl ->
id,
"fog.based");
175 lightning[10] = glGetUniformLocation (glsl ->
id,
"fog.density");
176 lightning[11] = glGetUniformLocation (glsl ->
id,
"fog.depth");
177 lightning[12] = glGetUniformLocation (glsl ->
id,
"fog.color");
178 lightning[13] = glGetUniformLocation (glsl ->
id,
"numLights");
180 for (j=0; j<
plot -> l_ghtning.lights; j++)
206 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
207 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"size");
208 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"vertColor");
211 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
212 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
213 glEnableVertexAttribArray(glsl -> array_pointer[0]);
214 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
216 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
217 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
218 glEnableVertexAttribArray (glsl -> array_pointer[1]);
219 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
220 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
221 glEnableVertexAttribArray (glsl -> array_pointer[2]);
222 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
223 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
224 glEnableVertexAttribArray (glsl -> array_pointer[3]);
225 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
226 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
239 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
240 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"radius");
241 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"vertColor");
244 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
245 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
246 glEnableVertexAttribArray(glsl -> array_pointer[0]);
247 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
249 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
250 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
252 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
253 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
254 glEnableVertexAttribArray (glsl -> array_pointer[1]);
255 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
256 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
257 glEnableVertexAttribArray (glsl -> array_pointer[2]);
258 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
259 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
260 glEnableVertexAttribArray (glsl -> array_pointer[3]);
261 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
262 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
275 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"vertColor");
277 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
278 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
279 glEnableVertexAttribArray(glsl -> array_pointer[0]);
280 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *
sizeof(GLfloat), (GLvoid*) 0);
281 glEnableVertexAttribArray(glsl -> array_pointer[1]);
282 glVertexAttribPointer(glsl -> array_pointer[1], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
284 if (glsl ->
object ==
MEASU)
286 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"factor");
287 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"pattern");
288 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"text_proj");
289 glsl -> uniform_loc[4] = glGetUniformLocation (glsl ->
id,
"un_view");
290 glsl -> uniform_loc[5] = glGetUniformLocation (glsl ->
id,
"viewp");
291 glsl -> uniform_loc[6] = glGetUniformLocation (glsl ->
id,
"depth");
305 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
306 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"height");
307 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"radius");
308 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"quat");
309 glsl -> array_pointer[5] = glGetAttribLocation (glsl ->
id,
"vertColor");
312 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
313 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
314 glEnableVertexAttribArray(glsl -> array_pointer[0]);
315 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
318 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
319 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
322 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
323 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
324 glEnableVertexAttribArray (glsl -> array_pointer[1]);
325 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
326 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
327 glEnableVertexAttribArray (glsl -> array_pointer[2]);
328 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
329 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
330 glEnableVertexAttribArray (glsl -> array_pointer[3]);
331 glVertexAttribPointer (glsl -> array_pointer[3], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
332 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
333 glEnableVertexAttribArray (glsl -> array_pointer[4]);
334 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (5*
sizeof(GLfloat)));
335 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
336 glEnableVertexAttribArray (glsl -> array_pointer[5]);
337 glVertexAttribPointer (glsl -> array_pointer[5], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (9*
sizeof(GLfloat)));
338 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
351 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
352 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"radius");
353 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"quat");
354 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"vertColor");
357 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
358 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
359 glEnableVertexAttribArray(glsl -> array_pointer[0]);
360 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
363 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
364 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
367 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
368 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
369 glEnableVertexAttribArray (glsl -> array_pointer[1]);
370 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
371 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
372 glEnableVertexAttribArray (glsl -> array_pointer[2]);
373 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
374 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
375 glEnableVertexAttribArray (glsl -> array_pointer[3]);
376 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
377 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
378 glEnableVertexAttribArray (glsl -> array_pointer[4]);
379 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (8*
sizeof(GLfloat)));
380 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
393 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"vertNormal");
394 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"vertColor");
397 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
398 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
399 glEnableVertexAttribArray(glsl -> array_pointer[0]);
400 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
401 glEnableVertexAttribArray(glsl -> array_pointer[1]);
402 glVertexAttribPointer(glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
403 glEnableVertexAttribArray(glsl -> array_pointer[2]);
404 glVertexAttribPointer(glsl -> array_pointer[2], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (6*
sizeof(GLfloat)));
418 glsl -> uniform_loc[0] = glGetUniformLocation (glsl ->
id,
"first_color");
419 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"second_color");
420 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"gradient");
421 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"position");
423 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
424 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
425 glEnableVertexAttribArray(glsl -> array_pointer[0]);
426 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
440 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
441 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
442 glEnableVertexAttribArray (glsl -> array_pointer[2]);
444 glVertexAttribPointer (glsl -> array_pointer[2], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
445 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
446 if (glsl ->
object ==
MEASU)
448 glEnableVertexAttribArray (glsl -> array_pointer[3]);
449 glVertexAttribPointer (glsl -> array_pointer[3], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
450 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
451 glEnableVertexAttribArray (glsl -> array_pointer[4]);
452 glVertexAttribPointer (glsl -> array_pointer[4], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (6*
sizeof(GLfloat)));
453 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
454 if (obj -> inst_buffer_size == 12)
456 glEnableVertexAttribArray (glsl -> array_pointer[5]);
457 glVertexAttribPointer (glsl -> array_pointer[5], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (9*
sizeof(GLfloat)));
458 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
473 glActiveTexture (GL_TEXTURE0);
475 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"tex");
476 glUniform1i (glsl -> uniform_loc[1], 0);
477 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"text_proj");
478 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"un_view");
479 glsl -> uniform_loc[4] = glGetUniformLocation (glsl ->
id,
"viewp");
480 glsl -> uniform_loc[5] = glGetUniformLocation (glsl ->
id,
"pos_shift");
481 glsl -> uniform_loc[6] = glGetUniformLocation (glsl ->
id,
"vert_color");
483 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"tcoord");
484 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"offset");
485 if (glsl ->
object ==
MEASU)
487 glsl -> uniform_loc[7] = glGetUniformLocation (glsl ->
id,
"tilted");
488 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"at_a");
489 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"at_b");
490 if (obj -> inst_buffer_size == 12) glsl -> array_pointer[5] = glGetAttribLocation (glsl ->
id,
"at_c");
494 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
495 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
496 glEnableVertexAttribArray(glsl -> array_pointer[0]);
497 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
498 glEnableVertexAttribArray(glsl -> array_pointer[1]);
499 glVertexAttribPointer(glsl -> array_pointer[1], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (2*
sizeof(GLfloat)));
512 object_3d * new_obj = g_malloc0 (
sizeof*new_obj);
513 new_obj -> quality = old_obj -> quality;
515 new_obj -> num_vertices = old_obj -> num_vertices;
516 new_obj -> vert_buffer_size = old_obj -> vert_buffer_size;
517 new_obj -> vertices =
duplicate_float (new_obj -> num_vertices*old_obj -> vert_buffer_size, old_obj -> vertices);
519 new_obj -> num_indices = old_obj -> num_indices;
520 new_obj -> ind_buffer_size = old_obj -> ind_buffer_size;
521 if (old_obj -> indices != NULL)
523 new_obj -> indices =
duplicate_int (new_obj -> num_indices*old_obj -> ind_buffer_size, old_obj -> indices);
526 new_obj -> num_instances = old_obj -> num_instances;
527 new_obj -> inst_buffer_size = old_obj -> inst_buffer_size;
528 if (old_obj -> instances != NULL)
530 new_obj -> instances =
duplicate_float (new_obj -> num_instances*old_obj -> inst_buffer_size, old_obj -> instances);
532 new_obj -> texture = old_obj -> texture;
534 for (i=0; i<5; i++) new_obj ->
shift[i] = old_obj ->
shift[i];
557 const GLchar * vertex,
const GLchar * geometry,
const GLchar * fragment,
558 GLenum type_of_vertices,
int narray,
int nunif, gboolean lightning,
object_3d * obj)
562 glsl ->
id = glCreateProgram ();
563 glsl ->
object = object;
564 glsl -> draw_type = object_id;
566 glsl -> vertex_shader =
create_shader (GL_VERTEX_SHADER, vertex);
567 glAttachShader (glsl ->
id, glsl -> vertex_shader);
568 if (geometry != NULL)
570 glsl -> geometry_shader =
create_shader (GL_GEOMETRY_SHADER, geometry);
571 glAttachShader (glsl ->
id, glsl -> geometry_shader);
573 glsl -> fragment_shader =
create_shader (GL_FRAGMENT_SHADER, fragment);
574 glAttachShader (glsl ->
id, glsl -> fragment_shader);
576 glBindFragDataLocation (glsl ->
id, 0,
"fragment_color");
577 glLinkProgram(glsl ->
id);
579 glsl -> vert_type = type_of_vertices;
581 glGenVertexArrays (1, & glsl -> vao);
583 glBindVertexArray (glsl -> vao);
589 if (object_id !=
GLSL_BACK) glsl -> uniform_loc[0] = glGetUniformLocation (glsl ->
id,
"mvp");
591 glsl -> array_pointer[0] = glGetAttribLocation (glsl ->
id,
"vert");
593 glsl -> light_uniform = NULL;
598 glsl -> draw_instanced = FALSE;
601 if (glsl -> obj -> num_indices > 0) nvbo ++;
602 if (glsl -> obj -> num_instances > 0)
605 if (glsl -> obj -> num_instances > 1) glsl -> draw_instanced = TRUE;
609 glGenBuffers (nvbo, glsl -> vbo);
643 glDetachShader (glsl ->
id,glsl -> vertex_shader);
644 if (geometry != NULL) glDetachShader (glsl ->
id, glsl -> geometry_shader);
645 glDetachShader (glsl ->
id, glsl -> fragment_shader);
660 if (
id ==
ATOMS)
return TRUE;
661 if (
id ==
BONDS)
return TRUE;
662 if (
id ==
POLYS)
return TRUE;
663 if (
id ==
RINGS)
return TRUE;
664 if (
id ==
SELEC)
return TRUE;
665 if (
id ==
MDBOX)
return this_proj -> cell.npt;
666 if (
id ==
VOLMS)
return TRUE;
685 for (j=0; j< this_proj -> steps; j++) view -> n_shaders[i][j] = -1;
702 for (i=0; i<nshaders; i++)
705 this_proj -> modelgl -> create_shaders[k] = TRUE;
706 for (j=0; j<this_proj -> steps; j++)
708 this_proj -> modelgl -> n_shaders[k][j] = -1;
724 if (view -> ogl_glsl[shader][i] != NULL)
726 g_free (view -> ogl_glsl[shader][i]);
727 view -> ogl_glsl[shader][i] = NULL;
744 view -> create_shaders[i] = TRUE;
759 view -> create_shaders[
LABEL] = TRUE;
760 view -> create_shaders[
PICKS] = TRUE;
761 view -> create_shaders[
MEASU] = TRUE;
764 if (
is_atom_win_active(view) || (view -> mode ==
EDITION && (view -> anim -> last ->
img -> selected[1] -> selected || view -> selection_mode == 5)))
766 if (view -> measure_win != NULL)
789 view -> ogl_glsl[i] = NULL;
792 view -> ogl_glsl[i] = g_malloc0 (this_proj -> steps*
sizeof*view -> ogl_glsl[i]);
793 view -> n_shaders[i] =
allocint (this_proj -> steps);
794 for (j=0; j<this_proj -> steps; j++)
796 view -> n_shaders[i][j] = -1;
801 j = (i ==
MEASU) ? 2 : 1;
802 view -> ogl_glsl[i] = g_malloc0 (j*
sizeof*view -> ogl_glsl[i]);
803 view -> ogl_glsl[i][0] = NULL;
804 view -> n_shaders[i] =
allocint (j);
806 view -> create_shaders[i] = TRUE;
848 k = (glsl -> draw_type ==
GLSL_LIGHT) ? 0 :
plot -> m_terial.param[0];
849 glUniformMatrix4fv (glsl -> light_uniform[0], 1, GL_FALSE, &
wingl -> model_view_matrix.m00);
850 glUniform1i (glsl -> light_uniform[1], k);
851 glUniform3f (glsl -> light_uniform[2],
plot -> m_terial.albedo.x,
plot -> m_terial.albedo.y,
plot -> m_terial.albedo.z);
852 for (j=0; j<5; j++) glUniform1f (glsl -> light_uniform[3+j],
plot -> m_terial.param[j+1]);
853 glUniform1i (glsl -> light_uniform[8],
plot -> f_g.mode);
854 glUniform1i (glsl -> light_uniform[9],
plot -> f_g.based);
855 glUniform1f (glsl -> light_uniform[10],
plot -> f_g.density/
plot -> p_depth);
856 glUniform2f (glsl -> light_uniform[11],
plot -> f_g.depth[0]*
plot -> p_depth/100.0 +
plot -> p_depth,
plot -> f_g.depth[1]*
plot -> p_depth/100.0+
plot -> p_depth);
857 glUniform3f (glsl -> light_uniform[12],
plot -> f_g.color.x,
plot -> f_g.color.y,
plot -> f_g.color.z);
858 glUniform1i (glsl -> light_uniform[13],
plot -> l_ghtning.lights);
859 for (j=0; j<
plot -> l_ghtning.lights; j++)
862 glUniform1i (glsl -> light_uniform[k],
plot -> l_ghtning.spot[j].type);
863 if (
plot -> l_ghtning.spot[j].fix == 0)
865 l_pos = m4_mul_pos (
wingl -> model_matrix,
plot -> l_ghtning.spot[j].position);
869 l_pos = m4_mul_pos (
wingl -> model_view_matrix,
plot -> l_ghtning.spot[j].position);
871 glUniform3f (glsl -> light_uniform[k+1], l_pos.
x, l_pos.
y, l_pos.
z);
872 if (
plot -> l_ghtning.spot[j].fix == 0)
874 l_dir = m4_mul_pos (
wingl -> model_matrix,
plot -> l_ghtning.spot[j].direction);
878 l_dir = m4_mul_pos (
wingl -> model_view_matrix,
plot -> l_ghtning.spot[j].direction);
880 glUniform3f (glsl -> light_uniform[k+2], l_dir.
x, l_dir.
y, l_dir.
z);
881 glUniform3f (glsl -> light_uniform[k+3],
plot -> l_ghtning.spot[j].intensity.x,
plot -> l_ghtning.spot[j].intensity.y,
plot -> l_ghtning.spot[j].intensity.z);
882 glUniform1f (glsl -> light_uniform[k+4],
plot -> l_ghtning.spot[j].attenuation.x);
883 glUniform1f (glsl -> light_uniform[k+5],
plot -> l_ghtning.spot[j].attenuation.y);
884 glUniform1f (glsl -> light_uniform[k+6],
plot -> l_ghtning.spot[j].attenuation.z);
885 glUniform1f (glsl -> light_uniform[k+7], cos(
plot -> l_ghtning.spot[j].spot_data.x*
pi/180.0));
886 glUniform1f (glsl -> light_uniform[k+8], cos(
plot -> l_ghtning.spot[j].spot_data.y*
pi/180.0));
887 glUniform1f (glsl -> light_uniform[k+9], cos(
plot -> l_ghtning.spot[j].spot_data.z*
pi/180.0));
906 glUniformMatrix4fv (glsl -> uniform_loc[2], 1, GL_FALSE, &
wingl -> label_projection_matrix.m00);
907 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, &
wingl -> un_view_matrix.m00);
908 glUniform4f (glsl -> uniform_loc[4],
wingl -> view_port.w,
wingl -> view_port.x,
wingl -> view_port.y,
wingl -> view_port.z);
909 glUniform4f (glsl -> uniform_loc[5], glsl -> obj ->
shift[0], glsl -> obj ->
shift[1],
910 glsl -> obj ->
shift[2], glsl -> obj ->
shift[3]);
911 glUniform4f (glsl -> uniform_loc[6], glsl ->
col -> red, glsl ->
col -> green,
912 glsl ->
col -> blue, glsl ->
col -> alpha);
913 if (glsl ->
object ==
MEASU) glUniform1i (glsl -> uniform_loc[7],
this_tilt);
927 if (glsl ->
object ==
MAXIS)
932 k =
wingl -> atom_win -> active;
939 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> axis_proj_model_view_matrix.m00);
943 else if (glsl ->
object ==
LABEL)
945 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
948 else if (glsl ->
object ==
BACKG)
952 glUniform4f (glsl -> uniform_loc[j],
plot -> back -> gradient_color[j].red,
953 plot -> back -> gradient_color[j].green,
954 plot -> back -> gradient_color[j].blue,
955 plot -> back -> gradient_color[j].alpha);
957 glUniform1i (glsl -> uniform_loc[2],
plot -> back -> direction);
958 glUniform1f (glsl -> uniform_loc[3],
plot -> back ->
position);
960 else if (glsl ->
object ==
MEASU)
962 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
963 if (glsl -> vert_type == GL_TRIANGLE_STRIP)
971 if (glsl -> vert_type == GL_TRIANGLES)
974 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, &
wingl -> label_projection_matrix.m00);
976 glUniformMatrix4fv (glsl -> uniform_loc[4], 1, GL_FALSE, &
wingl -> un_view_matrix.m00);
977 glUniform4f (glsl -> uniform_loc[5],
wingl -> view_port.w,
wingl -> view_port.x,
wingl -> view_port.y,
wingl -> view_port.z);
980 glUniform1f (glsl -> uniform_loc[6], 1.0);
984 glUniform1f (glsl -> uniform_loc[6],
plot -> p_depth);
988 else if (glsl ->
object ==
LIGHT)
990 if (
plot -> light_loc[ids])
992 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_matrix.m00);
996 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
1001 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
1004 if (glsl -> line_width != 0.0) glLineWidth (glsl -> line_width);
1008 glBindVertexArray (glsl -> vao);
1013 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
1018 glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
1022 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1027 if (glsl -> draw_instanced)
1029 glDrawElementsInstanced (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0, glsl -> obj -> num_instances);
1033 glDrawElements (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0);
1041 glActiveTexture (GL_TEXTURE0);
1042 glBindTexture (
ogl_texture, glsl -> obj -> texture);
1044 if (glsl -> draw_instanced)
1046 j = (glsl -> draw_type ==
GLSL_STRING) ? 4 : 3*(glsl -> draw_type+1);
1047 glDrawArraysInstanced (glsl -> vert_type, 0, j, glsl -> obj -> num_instances);
1051 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1056 if (glsl -> draw_type ==
GLSL_BACK) glDisable (GL_DEPTH_TEST);
1057 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1058 if (glsl -> draw_type ==
GLSL_BACK) glEnable (GL_DEPTH_TEST);
1061 glBindVertexArray (0);
1078 for (j=0; j<
wingl -> n_shaders[id][i]; j++)
1080 if (
wingl -> ogl_glsl[
id][i][j])
1082 glsl =
wingl -> ogl_glsl[id][i][j];
1083 glUseProgram (glsl ->
id);
1095 for (j=0; j<
wingl -> n_shaders[id][i]; j++)
1097 if (
wingl -> ogl_glsl[
id][i][j])
1099 glsl =
wingl -> ogl_glsl[id][i][j];
1100 glUseProgram (glsl ->
id);
mat4_t create_axis_matrices(int type)
create axis OpenGL rendering matrices
mat4_t create_label_matrices()
create label projection matrices
int * duplicate_int(int num, int *old_val)
copy a list of int
float * duplicate_float(int num, float *old_val)
copy a list of float
int * allocint(int val)
allocate an int * pointer
Global variable declarations Global convenience function declarations Global data structure defin...
gboolean is_atom_win_active(glwin *view)
is the model edition window visible ?
GLuint * allocgluint(int val)
allocate a GLuint * pointer
project * get_project_by_id(int p)
get project pointer using id number
void update(glwin *view)
update the rendering of the OpenGL window
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
void update_selection_tree(glwin *view, int pi, int id)
update measurements tree view
shaders
The different types of shaders in the atomes program.
Messaging function declarations.
void recreate_all_shaders(glwin *view)
re-initialize all OpenGL shaders
void re_create_all_md_shaders(glwin *view)
re-initialize all MD dependent OpenGL shaders
void set_light_uniform_location(GLuint *lightning, int id, int j, int k, char *string)
set lightning uniform location
void glsl_bind_background(glsl_program *glsl, object_3d *obj)
bind background data to an OpenGL shader program
void re_create_md_shaders(int nshaders, int shaders[nshaders], project *this_proj)
re-initialize some MD dependent OpenGL shaders
void glsl_bind_spheres(glsl_program *glsl, object_3d *obj)
bind a 3D object sphere to an OpenGL shader program
GLuint * glsl_add_lights(glsl_program *glsl)
add lightning to an OpenGL shader program
void init_shaders(glwin *view)
initialize all the OpenGL shaders
void set_lights_data(glsl_program *glsl)
set lightning data for an OpenGL progam
void glsl_bind_lines(glsl_program *glsl, object_3d *obj)
bind a 3D object line to an OpenGL shader program
void shading_glsl_text(glsl_program *glsl)
Render text in OpenGL.
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
void render_this_shader(glsl_program *glsl, int ids)
render an OpenGL shader
void glsl_bind_string(glsl_program *glsl, object_3d *obj)
bind a 3D object text string to an OpenGL shader program
void draw_vertices(int id)
Draw OpenGL shader program.
gboolean glsl_disable_cull_face(glsl_program *glsl)
Disable or enable cull face for OpenGL rendering.
GLuint create_shader(int type, const GLchar *src)
create an OpenGL GLSL shader
gboolean in_md_shaders(project *this_proj, int id)
is this shader MD dependent ?
void glsl_bind_cylinders(glsl_program *glsl, object_3d *obj)
bind a 3D object cylinder to an OpenGL shader program
uint16_t stipple_pattern[NDOTS]
glsl_program * init_shader_program(int object, int object_id, const GLchar *vertex, const GLchar *geometry, const GLchar *fragment, GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d *obj)
create an OpenGL shader program
void init_default_shaders(glwin *view)
re-initialize the default OpenGL shaders
void update_string_instances(glsl_program *glsl, object_3d *obj)
Update OpenGL string texture instances.
void glsl_bind_polyhedra(glsl_program *glsl, object_3d *obj)
bind a 3D object polyhedra to an OpenGL shader program
void glsl_bind_points(glsl_program *glsl, object_3d *obj)
bind a 3D object point to an OpenGL shader program
void glsl_bind_caps(glsl_program *glsl, object_3d *obj)
bind a 3D object cylinder cap to an OpenGL shader program
object_3d * duplicate_object_3d(object_3d *old_obj)
create a copy of an object_3d data structure
GLuint * alloc_shader_pointer(GLuint *pointer, int shaders)
allocate GLuint data pointer, ensure that it is clean
Variable declarations related to GLSL programs Data structure declarations related to GLSL programs...