98 shader = glCreateShader (type);
99 glShaderSource (shader, 1, & src, NULL);
100 glCompileShader (shader);
102 glGetShaderiv (shader, GL_COMPILE_STATUS, &
status);
107 glGetShaderiv (shader, GL_INFO_LOG_LENGTH, & log_len);
108 buffer = g_malloc0(log_len + 1);
109 glGetShaderInfoLog (shader, log_len, NULL, buffer);
110 g_warning (_(
"Compilation failure in %s shader:\n%s"),
111 type == GL_VERTEX_SHADER ?
"vertex" :
"fragment",
115 glDeleteShader (shader);
140#define MATERIAL_DATA 8
153 object -> instances =
allocfloat (
object -> num_instances *
object -> inst_buffer_size);
169 gchar * light_string = g_strdup_printf (
"AllLights[%d].%s", j,
string);
171 g_free (light_string);
185 lightning[0] = glGetUniformLocation (glsl ->
id,
"m_view");
186 lightning[1] = glGetUniformLocation (glsl ->
id,
"m_proj");
187 lightning[2] = glGetUniformLocation (glsl ->
id,
"view_is_ortho");
188 lightning[3] = glGetUniformLocation (glsl ->
id,
"lights_on");
189 lightning[4] = glGetUniformLocation (glsl ->
id,
"mat.albedo");
190 lightning[5] = glGetUniformLocation (glsl ->
id,
"mat.metallic");
191 lightning[6] = glGetUniformLocation (glsl ->
id,
"mat.roughness");
192 lightning[7] = glGetUniformLocation (glsl ->
id,
"mat.ambient_occlusion");
193 lightning[8] = glGetUniformLocation (glsl ->
id,
"mat.gamma");
194 lightning[9] = glGetUniformLocation (glsl ->
id,
"mat.alpha");
195 lightning[10] = glGetUniformLocation (glsl ->
id,
"fog.mode");
196 lightning[11] = glGetUniformLocation (glsl ->
id,
"fog.based");
197 lightning[12] = glGetUniformLocation (glsl ->
id,
"fog.density");
198 lightning[13] = glGetUniformLocation (glsl ->
id,
"fog.depth");
199 lightning[14] = glGetUniformLocation (glsl ->
id,
"fog.color");
200 lightning[15] = glGetUniformLocation (glsl ->
id,
"numLights");
202 for (j=0; j<
plot -> l_ghtning.lights; j++)
229 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
230 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"size");
231 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"vertColor");
234 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
235 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
236 glEnableVertexAttribArray(glsl -> array_pointer[0]);
237 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
239 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
240 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
241 glEnableVertexAttribArray (glsl -> array_pointer[1]);
242 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
243 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
244 glEnableVertexAttribArray (glsl -> array_pointer[2]);
245 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
246 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
247 glEnableVertexAttribArray (glsl -> array_pointer[3]);
248 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
249 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
262 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
263 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"radius");
264 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"vertColor");
267 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
268 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
269 glEnableVertexAttribArray(glsl -> array_pointer[0]);
270 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
272 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
273 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
275 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
276 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
277 glEnableVertexAttribArray (glsl -> array_pointer[1]);
278 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
279 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
280 glEnableVertexAttribArray (glsl -> array_pointer[2]);
281 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
282 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
283 glEnableVertexAttribArray (glsl -> array_pointer[3]);
284 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
285 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
298 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"vertColor");
300 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
301 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
302 glEnableVertexAttribArray(glsl -> array_pointer[0]);
303 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *
sizeof(GLfloat), (GLvoid*) 0);
304 glEnableVertexAttribArray(glsl -> array_pointer[1]);
305 glVertexAttribPointer(glsl -> array_pointer[1], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
307 if (glsl ->
object ==
MEASU)
309 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"factor");
310 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"pattern");
311 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"text_proj");
312 glsl -> uniform_loc[4] = glGetUniformLocation (glsl ->
id,
"un_view");
313 glsl -> uniform_loc[5] = glGetUniformLocation (glsl ->
id,
"viewp");
314 glsl -> uniform_loc[6] = glGetUniformLocation (glsl ->
id,
"depth");
328 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
329 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"height");
330 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"radius");
331 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"quat");
332 glsl -> array_pointer[5] = glGetAttribLocation (glsl ->
id,
"vertColor");
335 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
336 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
337 glEnableVertexAttribArray(glsl -> array_pointer[0]);
338 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
341 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
342 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
345 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
346 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
347 glEnableVertexAttribArray (glsl -> array_pointer[1]);
348 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
349 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
350 glEnableVertexAttribArray (glsl -> array_pointer[2]);
351 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
352 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
353 glEnableVertexAttribArray (glsl -> array_pointer[3]);
354 glVertexAttribPointer (glsl -> array_pointer[3], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
355 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
356 glEnableVertexAttribArray (glsl -> array_pointer[4]);
357 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (5*
sizeof(GLfloat)));
358 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
359 glEnableVertexAttribArray (glsl -> array_pointer[5]);
360 glVertexAttribPointer (glsl -> array_pointer[5], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (9*
sizeof(GLfloat)));
361 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
365 glsl -> array_pointer[6] = glGetAttribLocation (glsl ->
id,
"r_sphere_a");
366 glsl -> array_pointer[7] = glGetAttribLocation (glsl ->
id,
"r_sphere_b");
367 glEnableVertexAttribArray (glsl -> array_pointer[6]);
368 glVertexAttribPointer (glsl -> array_pointer[6], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (13*
sizeof(GLfloat)));
369 glVertexAttribDivisor (glsl -> array_pointer[6], 1);
371 glEnableVertexAttribArray (glsl -> array_pointer[7]);
372 glVertexAttribPointer (glsl -> array_pointer[7], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (14*
sizeof(GLfloat)));
373 glVertexAttribDivisor (glsl -> array_pointer[7], 1);
387 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
388 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"radius");
389 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"quat");
390 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"vertColor");
393 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
394 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
395 glEnableVertexAttribArray(glsl -> array_pointer[0]);
396 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
399 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
400 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
403 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
404 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
405 glEnableVertexAttribArray (glsl -> array_pointer[1]);
406 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
407 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
408 glEnableVertexAttribArray (glsl -> array_pointer[2]);
409 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
410 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
411 glEnableVertexAttribArray (glsl -> array_pointer[3]);
412 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
413 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
414 glEnableVertexAttribArray (glsl -> array_pointer[4]);
415 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (8*
sizeof(GLfloat)));
416 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
429 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"vertNormal");
430 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"vertColor");
433 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
434 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
435 glEnableVertexAttribArray(glsl -> array_pointer[0]);
436 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
437 glEnableVertexAttribArray(glsl -> array_pointer[1]);
438 glVertexAttribPointer(glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
439 glEnableVertexAttribArray(glsl -> array_pointer[2]);
440 glVertexAttribPointer(glsl -> array_pointer[2], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (6*
sizeof(GLfloat)));
454 glsl -> uniform_loc[0] = glGetUniformLocation (glsl ->
id,
"first_color");
455 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"second_color");
456 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"gradient");
457 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"position");
459 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
460 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
461 glEnableVertexAttribArray(glsl -> array_pointer[0]);
462 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
476 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
477 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
478 glEnableVertexAttribArray (glsl -> array_pointer[2]);
480 glVertexAttribPointer (glsl -> array_pointer[2], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
481 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
482 if (glsl ->
object ==
MEASU)
484 glEnableVertexAttribArray (glsl -> array_pointer[3]);
485 glVertexAttribPointer (glsl -> array_pointer[3], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
486 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
487 glEnableVertexAttribArray (glsl -> array_pointer[4]);
488 glVertexAttribPointer (glsl -> array_pointer[4], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (6*
sizeof(GLfloat)));
489 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
490 if (obj -> inst_buffer_size == 12)
492 glEnableVertexAttribArray (glsl -> array_pointer[5]);
493 glVertexAttribPointer (glsl -> array_pointer[5], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (9*
sizeof(GLfloat)));
494 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
509 glActiveTexture (GL_TEXTURE0);
511 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"tex");
512 glUniform1i (glsl -> uniform_loc[1], 0);
513 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"text_proj");
514 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"un_view");
515 glsl -> uniform_loc[4] = glGetUniformLocation (glsl ->
id,
"viewp");
516 glsl -> uniform_loc[5] = glGetUniformLocation (glsl ->
id,
"pos_shift");
517 glsl -> uniform_loc[6] = glGetUniformLocation (glsl ->
id,
"vert_color");
519 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"tcoord");
520 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"offset");
521 if (glsl ->
object ==
MEASU)
523 glsl -> uniform_loc[7] = glGetUniformLocation (glsl ->
id,
"tilted");
524 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"at_a");
525 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"at_b");
526 if (obj -> inst_buffer_size == 12) glsl -> array_pointer[5] = glGetAttribLocation (glsl ->
id,
"at_c");
530 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
531 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
532 glEnableVertexAttribArray(glsl -> array_pointer[0]);
533 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
534 glEnableVertexAttribArray(glsl -> array_pointer[1]);
535 glVertexAttribPointer(glsl -> array_pointer[1], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (2*
sizeof(GLfloat)));
548 object_3d * new_obj = g_malloc0(
sizeof*new_obj);
549 new_obj -> quality = old_obj -> quality;
551 new_obj -> num_vertices = old_obj -> num_vertices;
552 new_obj -> vert_buffer_size = old_obj -> vert_buffer_size;
553 new_obj -> vertices =
duplicate_float (new_obj -> num_vertices*old_obj -> vert_buffer_size, old_obj -> vertices);
555 new_obj -> num_indices = old_obj -> num_indices;
556 new_obj -> ind_buffer_size = old_obj -> ind_buffer_size;
557 if (old_obj -> indices != NULL)
559 new_obj -> indices =
duplicate_int (new_obj -> num_indices*old_obj -> ind_buffer_size, old_obj -> indices);
562 new_obj -> num_instances = old_obj -> num_instances;
563 new_obj -> inst_buffer_size = old_obj -> inst_buffer_size;
564 if (old_obj -> instances != NULL)
566 new_obj -> instances =
duplicate_float (new_obj -> num_instances*old_obj -> inst_buffer_size, old_obj -> instances);
568 new_obj -> texture = old_obj -> texture;
570 for (i=0; i<5; i++) new_obj ->
shift[i] = old_obj ->
shift[i];
583 if (obj -> vertices) g_free (obj -> vertices);
584 if (obj -> indices) g_free (obj -> indices);
585 if (obj -> instances) g_free (obj -> instances);
599 if (glsl -> array_pointer) g_free (glsl -> array_pointer);
600 if (glsl -> uniform_loc) g_free (glsl -> uniform_loc);
601 if (glsl -> light_uniform) g_free (glsl -> light_uniform);
602 if (glsl -> vbo) g_free (glsl -> vbo);
627 const GLchar * vertex,
const GLchar * geometry,
const GLchar * fragment,
628 GLenum type_of_vertices,
int narray,
int nunif, gboolean lightning,
object_3d * obj)
632 glsl ->
id = glCreateProgram ();
633 glsl ->
object = object;
634 glsl -> draw_type = object_id;
636 glsl -> vertex_shader =
create_shader (GL_VERTEX_SHADER, vertex);
637 glAttachShader (glsl ->
id, glsl -> vertex_shader);
638 if (geometry != NULL)
640 glsl -> geometry_shader =
create_shader (GL_GEOMETRY_SHADER, geometry);
641 glAttachShader (glsl ->
id, glsl -> geometry_shader);
643 glsl -> fragment_shader =
create_shader (GL_FRAGMENT_SHADER, fragment);
644 glAttachShader (glsl ->
id, glsl -> fragment_shader);
646 glBindFragDataLocation (glsl ->
id, 0,
"fragment_color");
647 glLinkProgram(glsl ->
id);
649 glsl -> vert_type = type_of_vertices;
651 glGenVertexArrays (1, & glsl -> vao);
653 glBindVertexArray (glsl -> vao);
659 if (object_id !=
GLSL_BACK) glsl -> uniform_loc[0] = glGetUniformLocation (glsl ->
id,
"mvp");
661 glsl -> array_pointer[0] = glGetAttribLocation (glsl ->
id,
"vert");
663 glsl -> light_uniform = NULL;
669 glsl -> draw_instanced = FALSE;
672 if (glsl -> obj -> num_indices > 0) nvbo ++;
673 if (glsl -> obj -> num_instances > 0)
676 if (glsl -> obj -> num_instances > 1) glsl -> draw_instanced = TRUE;
680 glGenBuffers (nvbo, glsl -> vbo);
714 glDetachShader (glsl ->
id,glsl -> vertex_shader);
715 if (geometry != NULL) glDetachShader (glsl ->
id, glsl -> geometry_shader);
716 glDetachShader (glsl ->
id, glsl -> fragment_shader);
731 if (
id ==
ATOMS)
return TRUE;
732 if (
id ==
BONDS)
return TRUE;
733 if (
id ==
POLYS)
return TRUE;
734 if (
id ==
RINGS)
return TRUE;
735 if (
id ==
SELEC)
return TRUE;
736 if (
id ==
MDBOX)
return this_proj -> cell.npt;
737 if (
id ==
VOLMS)
return TRUE;
756 for (j=0; j< this_proj -> steps; j++) view -> n_shaders[i][j] = -1;
773 for (i=0; i<nshaders; i++)
776 this_proj -> modelgl -> create_shaders[k] = TRUE;
777 for (j=0; j<this_proj -> steps; j++)
779 this_proj -> modelgl -> n_shaders[k][j] = -1;
796 if (view -> ogl_glsl[shader][i] != NULL)
798 j = view -> n_shaders[shader][i];
799 for (k=0; k<j; k++) view -> ogl_glsl[shader][i][k] =
free_this_glsl_program (view -> ogl_glsl[shader][i][k]);
816 view -> create_shaders[i] = TRUE;
831 view -> create_shaders[
LABEL] = TRUE;
832 view -> create_shaders[
PICKS] = TRUE;
833 view -> create_shaders[
MEASU] = TRUE;
836 if (
is_atom_win_active(view) || (view -> mode ==
EDITION && (view -> anim -> last ->
img -> selected[1] -> selected || view -> selection_mode == 5)))
838 if (view -> measure_win != NULL)
861 view -> ogl_glsl[i] = NULL;
864 view -> ogl_glsl[i] = g_malloc0(this_proj -> steps*
sizeof*view -> ogl_glsl[i]);
865 view -> n_shaders[i] =
allocint (this_proj -> steps);
866 for (j=0; j<this_proj -> steps; j++)
868 view -> n_shaders[i][j] = -1;
873 j = (i ==
MEASU) ? 2 : 1;
874 view -> ogl_glsl[i] = g_malloc0(j*
sizeof*view -> ogl_glsl[i]);
875 view -> ogl_glsl[i][0] = NULL;
876 view -> n_shaders[i] =
allocint (j);
878 view -> create_shaders[i] = TRUE;
921 glUniformMatrix4fv (glsl -> light_uniform[0], 1, GL_FALSE, &
wingl -> model_view_matrix.m00);
922 glUniformMatrix4fv (glsl -> light_uniform[1], 1, GL_FALSE, &
wingl -> projection_matrix.m00);
923 glUniform1i (glsl -> light_uniform[2],
plot ->
rep);
924 glUniform1i (glsl -> light_uniform[3], (glsl -> draw_type ==
GLSL_LIGHT) ? 0 :
plot -> m_terial.param[0]);
925 glUniform3f (glsl -> light_uniform[4],
plot -> m_terial.albedo.x,
plot -> m_terial.albedo.y,
plot -> m_terial.albedo.z);
926 for (j=0; j<5; j++) glUniform1f (glsl -> light_uniform[5+j],
plot -> m_terial.param[j+1]);
927 glUniform1i (glsl -> light_uniform[10],
plot -> f_g.mode);
928 glUniform1i (glsl -> light_uniform[11],
plot -> f_g.based);
929 glUniform1f (glsl -> light_uniform[12],
plot -> f_g.density/
plot -> p_depth);
930 glUniform2f (glsl -> light_uniform[13],
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);
931 glUniform3f (glsl -> light_uniform[14],
plot -> f_g.color.x,
plot -> f_g.color.y,
plot -> f_g.color.z);
932 glUniform1i (glsl -> light_uniform[15],
plot -> l_ghtning.lights);
933 for (j=0; j<
plot -> l_ghtning.lights; j++)
936 glUniform1i (glsl -> light_uniform[k],
plot -> l_ghtning.spot[j] -> type);
937 if (
plot -> l_ghtning.spot[j] -> fix == 0)
939 l_pos = m4_mul_pos (
wingl -> model_matrix,
plot -> l_ghtning.spot[j] ->
position);
943 l_pos = m4_mul_pos (
wingl -> model_view_matrix,
plot -> l_ghtning.spot[j] ->
position);
945 glUniform3f (glsl -> light_uniform[k+1], l_pos.
x, l_pos.
y, l_pos.
z);
946 if (
plot -> l_ghtning.spot[j] -> fix == 0)
948 l_dir = m4_mul_pos (
wingl -> model_matrix,
plot -> l_ghtning.spot[j] -> direction);
952 l_dir = m4_mul_pos (
wingl -> model_view_matrix,
plot -> l_ghtning.spot[j] -> direction);
954 glUniform3f (glsl -> light_uniform[k+2], l_dir.
x, l_dir.
y, l_dir.
z);
955 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);
956 glUniform1f (glsl -> light_uniform[k+4],
plot -> l_ghtning.spot[j] -> attenuation.x);
957 glUniform1f (glsl -> light_uniform[k+5],
plot -> l_ghtning.spot[j] -> attenuation.y);
958 glUniform1f (glsl -> light_uniform[k+6],
plot -> l_ghtning.spot[j] -> attenuation.z);
959 glUniform1f (glsl -> light_uniform[k+7], cos(
plot -> l_ghtning.spot[j] -> spot_data.x*
pi/180.0));
960 glUniform1f (glsl -> light_uniform[k+8], cos(
plot -> l_ghtning.spot[j] -> spot_data.y*
pi/180.0));
961 glUniform1f (glsl -> light_uniform[k+9], cos(
plot -> l_ghtning.spot[j] -> spot_data.z*
pi/180.0));
980 glUniformMatrix4fv (glsl -> uniform_loc[2], 1, GL_FALSE, &
wingl -> label_projection_matrix.m00);
981 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, &
wingl -> un_view_matrix.m00);
982 glUniform4f (glsl -> uniform_loc[4],
wingl -> view_port.w,
wingl -> view_port.x,
wingl -> view_port.y,
wingl -> view_port.z);
983 glUniform4f (glsl -> uniform_loc[5], glsl -> obj ->
shift[0], glsl -> obj ->
shift[1],
984 glsl -> obj ->
shift[2], glsl -> obj ->
shift[3]);
985 glUniform4f (glsl -> uniform_loc[6], glsl ->
col -> red, glsl ->
col -> green,
986 glsl ->
col -> blue, glsl ->
col -> alpha);
987 if (glsl ->
object ==
MEASU) glUniform1i (glsl -> uniform_loc[7],
this_tilt);
1001 if (glsl ->
object ==
MAXIS)
1006 k =
wingl -> atom_win -> active;
1007 if (
wingl -> atom_win -> show_axis[k])
1013 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> axis_proj_model_view_matrix.m00);
1017 else if (glsl ->
object ==
LABEL)
1019 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
1022 else if (glsl ->
object ==
BACKG)
1026 glUniform4f (glsl -> uniform_loc[j],
plot -> back -> gradient_color[j].red,
1027 plot -> back -> gradient_color[j].green,
1028 plot -> back -> gradient_color[j].blue,
1029 plot -> back -> gradient_color[j].alpha);
1031 glUniform1i (glsl -> uniform_loc[2],
plot -> back -> direction);
1032 glUniform1f (glsl -> uniform_loc[3],
plot -> back ->
position);
1034 else if (glsl ->
object ==
MEASU)
1036 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
1037 if (glsl -> vert_type == GL_TRIANGLE_STRIP)
1043 glUniform1i (glsl -> uniform_loc[1],
this_factor);
1045 if (glsl -> vert_type == GL_TRIANGLES)
1048 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, &
wingl -> label_projection_matrix.m00);
1050 glUniformMatrix4fv (glsl -> uniform_loc[4], 1, GL_FALSE, &
wingl -> un_view_matrix.m00);
1051 glUniform4f (glsl -> uniform_loc[5],
wingl -> view_port.w,
wingl -> view_port.x,
wingl -> view_port.y,
wingl -> view_port.z);
1054 glUniform1f (glsl -> uniform_loc[6], 1.0);
1058 glUniform1f (glsl -> uniform_loc[6],
plot -> p_depth);
1062 else if (glsl ->
object ==
LIGHT)
1064 if (
plot -> light_loc[ids])
1066 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_matrix.m00);
1070 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
1075 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
1078 if (glsl -> line_width != 0.0) glLineWidth (glsl -> line_width);
1082 glBindVertexArray (glsl -> vao);
1087 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
1092 glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
1096 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1104 glEnable (GL_POLYGON_OFFSET_FILL);
1105 glPolygonOffset (1.0, 1.0);
1107 if (glsl -> draw_instanced)
1109 glDrawElementsInstanced (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0, glsl -> obj -> num_instances);
1113 glDrawElements (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0);
1117 glDisable (GL_POLYGON_OFFSET_FILL);
1125 glActiveTexture (GL_TEXTURE0);
1126 glBindTexture (
ogl_texture, glsl -> obj -> texture);
1131 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1134 if (glsl -> draw_instanced)
1136 j = (glsl -> draw_type ==
GLSL_STRING) ? 4 : 3*(glsl -> draw_type+1);
1137 glDrawArraysInstanced (glsl -> vert_type, 0, j, glsl -> obj -> num_instances);
1141 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1146 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1152 if (glsl -> draw_type ==
GLSL_BACK) glDisable (GL_DEPTH_TEST);
1153 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1154 if (glsl -> draw_type ==
GLSL_BACK) glEnable (GL_DEPTH_TEST);
1157 glBindVertexArray (0);
1174 for (j=0; j<
wingl -> n_shaders[id][i]; j++)
1176 if (
wingl -> ogl_glsl[
id][i][j])
1178 glsl =
wingl -> ogl_glsl[id][i][j];
1179 glUseProgram (glsl ->
id);
1191 for (j=0; j<
wingl -> n_shaders[id][i]; j++)
1193 if (
wingl -> ogl_glsl[
id][i][j])
1195 glsl =
wingl -> ogl_glsl[id][i][j];
1196 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
float * allocfloat(int val)
allocate a float * 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
gboolean in_md_shaders(project *this_proj, int id)
is this shader MD dependent ?
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
glsl_program * free_this_glsl_program(glsl_program *glsl)
free memory allocated to create a glsl program
void draw_vertices(int id)
Draw OpenGL shader program.
void allocate_instances(object_3d *object)
allocate the instances buffer of a 3D object
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
object_3d * free_object_3d(object_3d *obj)
free the memory allocated to create an object_3d data structure
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...