90 shader = glCreateShader (type);
91 glShaderSource (shader, 1, & src, NULL);
92 glCompileShader (shader);
94 glGetShaderiv (shader, GL_COMPILE_STATUS, &
status);
99 glGetShaderiv (shader, GL_INFO_LOG_LENGTH, & log_len);
100 buffer = g_malloc (log_len + 1);
101 glGetShaderInfoLog (shader, log_len, NULL, buffer);
102 g_warning (
"Compile failure in %s shader:\n%s",
103 type == GL_VERTEX_SHADER ?
"vertex" :
"fragment",
107 glDeleteShader (shader);
132#define MATERIAL_DATA 6
164 lightning[0] = glGetUniformLocation (glsl ->
id,
"m_view");
165 lightning[1] = glGetUniformLocation (glsl ->
id,
"lights_on");
166 lightning[2] = glGetUniformLocation (glsl ->
id,
"mat.albedo");
167 lightning[3] = glGetUniformLocation (glsl ->
id,
"mat.metallic");
168 lightning[4] = glGetUniformLocation (glsl ->
id,
"mat.roughness");
169 lightning[5] = glGetUniformLocation (glsl ->
id,
"mat.back_light");
170 lightning[6] = glGetUniformLocation (glsl ->
id,
"mat.gamma");
171 lightning[7] = glGetUniformLocation (glsl ->
id,
"mat.alpha");
172 lightning[8] = glGetUniformLocation (glsl ->
id,
"fog.mode");
173 lightning[9] = glGetUniformLocation (glsl ->
id,
"fog.based");
174 lightning[10] = glGetUniformLocation (glsl ->
id,
"fog.density");
175 lightning[11] = glGetUniformLocation (glsl ->
id,
"fog.depth");
176 lightning[12] = glGetUniformLocation (glsl ->
id,
"fog.color");
177 lightning[13] = glGetUniformLocation (glsl ->
id,
"numLights");
179 for (j=0; j<
plot -> lights; j++)
205 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
206 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"size");
207 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"vertColor");
210 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
211 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
212 glEnableVertexAttribArray(glsl -> array_pointer[0]);
213 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
215 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
216 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
217 glEnableVertexAttribArray (glsl -> array_pointer[1]);
218 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
219 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
220 glEnableVertexAttribArray (glsl -> array_pointer[2]);
221 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
222 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
223 glEnableVertexAttribArray (glsl -> array_pointer[3]);
224 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
225 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
238 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
239 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"radius");
240 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"vertColor");
243 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
244 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
245 glEnableVertexAttribArray(glsl -> array_pointer[0]);
246 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
248 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
249 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
251 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
252 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
253 glEnableVertexAttribArray (glsl -> array_pointer[1]);
254 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
255 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
256 glEnableVertexAttribArray (glsl -> array_pointer[2]);
257 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
258 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
259 glEnableVertexAttribArray (glsl -> array_pointer[3]);
260 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
261 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
274 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"vertColor");
276 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
277 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
278 glEnableVertexAttribArray(glsl -> array_pointer[0]);
279 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *
sizeof(GLfloat), (GLvoid*) 0);
280 glEnableVertexAttribArray(glsl -> array_pointer[1]);
281 glVertexAttribPointer(glsl -> array_pointer[1], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
283 if (glsl ->
object ==
MEASU)
285 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"factor");
286 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"pattern");
287 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"text_proj");
288 glsl -> uniform_loc[4] = glGetUniformLocation (glsl ->
id,
"un_view");
289 glsl -> uniform_loc[5] = glGetUniformLocation (glsl ->
id,
"viewp");
290 glsl -> uniform_loc[6] = glGetUniformLocation (glsl ->
id,
"depth");
304 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
305 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"height");
306 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"radius");
307 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"quat");
308 glsl -> array_pointer[5] = glGetAttribLocation (glsl ->
id,
"vertColor");
311 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
312 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
313 glEnableVertexAttribArray(glsl -> array_pointer[0]);
314 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
317 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
318 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
321 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
322 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
323 glEnableVertexAttribArray (glsl -> array_pointer[1]);
324 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
325 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
326 glEnableVertexAttribArray (glsl -> array_pointer[2]);
327 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
328 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
329 glEnableVertexAttribArray (glsl -> array_pointer[3]);
330 glVertexAttribPointer (glsl -> array_pointer[3], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
331 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
332 glEnableVertexAttribArray (glsl -> array_pointer[4]);
333 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (5*
sizeof(GLfloat)));
334 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
335 glEnableVertexAttribArray (glsl -> array_pointer[5]);
336 glVertexAttribPointer (glsl -> array_pointer[5], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (9*
sizeof(GLfloat)));
337 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
350 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"offset");
351 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"radius");
352 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"quat");
353 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"vertColor");
356 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
357 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
358 glEnableVertexAttribArray(glsl -> array_pointer[0]);
359 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
362 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
363 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*
sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
366 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
367 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
368 glEnableVertexAttribArray (glsl -> array_pointer[1]);
369 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
370 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
371 glEnableVertexAttribArray (glsl -> array_pointer[2]);
372 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
373 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
374 glEnableVertexAttribArray (glsl -> array_pointer[3]);
375 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (4*
sizeof(GLfloat)));
376 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
377 glEnableVertexAttribArray (glsl -> array_pointer[4]);
378 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (8*
sizeof(GLfloat)));
379 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
392 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"vertNormal");
393 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"vertColor");
396 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
397 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
398 glEnableVertexAttribArray(glsl -> array_pointer[0]);
399 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
400 glEnableVertexAttribArray(glsl -> array_pointer[1]);
401 glVertexAttribPointer(glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
402 glEnableVertexAttribArray(glsl -> array_pointer[2]);
403 glVertexAttribPointer(glsl -> array_pointer[2], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (6*
sizeof(GLfloat)));
417 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
418 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances *
sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
419 glEnableVertexAttribArray (glsl -> array_pointer[2]);
421 glVertexAttribPointer (glsl -> array_pointer[2], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
422 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
423 if (glsl ->
object ==
MEASU)
425 glEnableVertexAttribArray (glsl -> array_pointer[3]);
426 glVertexAttribPointer (glsl -> array_pointer[3], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (3*
sizeof(GLfloat)));
427 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
428 glEnableVertexAttribArray (glsl -> array_pointer[4]);
429 glVertexAttribPointer (glsl -> array_pointer[4], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (6*
sizeof(GLfloat)));
430 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
431 if (obj -> inst_buffer_size == 12)
433 glEnableVertexAttribArray (glsl -> array_pointer[5]);
434 glVertexAttribPointer (glsl -> array_pointer[5], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*
sizeof(GLfloat), (GLvoid*) (9*
sizeof(GLfloat)));
435 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
450 glActiveTexture (GL_TEXTURE0);
452 glsl -> uniform_loc[1] = glGetUniformLocation (glsl ->
id,
"tex");
453 glUniform1i (glsl -> uniform_loc[1], 0);
454 glsl -> uniform_loc[2] = glGetUniformLocation (glsl ->
id,
"text_proj");
455 glsl -> uniform_loc[3] = glGetUniformLocation (glsl ->
id,
"un_view");
456 glsl -> uniform_loc[4] = glGetUniformLocation (glsl ->
id,
"viewp");
457 glsl -> uniform_loc[5] = glGetUniformLocation (glsl ->
id,
"pos_shift");
458 glsl -> uniform_loc[6] = glGetUniformLocation (glsl ->
id,
"vert_color");
460 glsl -> array_pointer[1] = glGetAttribLocation (glsl ->
id,
"tcoord");
461 glsl -> array_pointer[2] = glGetAttribLocation (glsl ->
id,
"offset");
462 if (glsl ->
object ==
MEASU)
464 glsl -> uniform_loc[7] = glGetUniformLocation (glsl ->
id,
"tilted");
465 glsl -> array_pointer[3] = glGetAttribLocation (glsl ->
id,
"at_a");
466 glsl -> array_pointer[4] = glGetAttribLocation (glsl ->
id,
"at_b");
467 if (obj -> inst_buffer_size == 12) glsl -> array_pointer[5] = glGetAttribLocation (glsl ->
id,
"at_c");
471 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
472 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*
sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
473 glEnableVertexAttribArray(glsl -> array_pointer[0]);
474 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) 0);
475 glEnableVertexAttribArray(glsl -> array_pointer[1]);
476 glVertexAttribPointer(glsl -> array_pointer[1], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*
sizeof(GLfloat), (GLvoid*) (2*
sizeof(GLfloat)));
489 object_3d * new_obj = g_malloc0 (
sizeof*new_obj);
490 new_obj -> quality = old_obj -> quality;
492 new_obj -> num_vertices = old_obj -> num_vertices;
493 new_obj -> vert_buffer_size = old_obj -> vert_buffer_size;
494 new_obj -> vertices =
duplicate_float (new_obj -> num_vertices*old_obj -> vert_buffer_size, old_obj -> vertices);
496 new_obj -> num_indices = old_obj -> num_indices;
497 new_obj -> ind_buffer_size = old_obj -> ind_buffer_size;
498 if (old_obj -> indices != NULL)
500 new_obj -> indices =
duplicate_int (new_obj -> num_indices*old_obj -> ind_buffer_size, old_obj -> indices);
503 new_obj -> num_instances = old_obj -> num_instances;
504 new_obj -> inst_buffer_size = old_obj -> inst_buffer_size;
505 if (old_obj -> instances != NULL)
507 new_obj -> instances =
duplicate_float (new_obj -> num_instances*old_obj -> inst_buffer_size, old_obj -> instances);
509 new_obj -> texture = old_obj -> texture;
511 for (i=0; i<5; i++) new_obj ->
shift[i] = old_obj ->
shift[i];
534 const GLchar * vertex,
const GLchar * geometry,
const GLchar * fragment,
535 GLenum type_of_vertices,
int narray,
int nunif, gboolean lightning,
object_3d * obj)
539 glsl ->
id = glCreateProgram ();
540 glsl ->
object = object;
541 glsl -> draw_type = object_id;
543 glsl -> vertex_shader =
create_shader (GL_VERTEX_SHADER, vertex);
544 glAttachShader (glsl ->
id, glsl -> vertex_shader);
545 if (geometry != NULL)
547 glsl -> geometry_shader =
create_shader (GL_GEOMETRY_SHADER, geometry);
548 glAttachShader (glsl ->
id, glsl -> geometry_shader);
550 glsl -> fragment_shader =
create_shader (GL_FRAGMENT_SHADER, fragment);
551 glAttachShader (glsl ->
id, glsl -> fragment_shader);
553 glBindFragDataLocation (glsl ->
id, 0,
"fragment_color");
554 glLinkProgram(glsl ->
id);
556 glsl -> vert_type = type_of_vertices;
558 glGenVertexArrays (1, & glsl -> vao);
560 glBindVertexArray (glsl -> vao);
566 glsl -> uniform_loc[0] = glGetUniformLocation (glsl ->
id,
"mvp");
568 glsl -> array_pointer[0] = glGetAttribLocation (glsl ->
id,
"vert");
570 glsl -> light_uniform = NULL;
575 glsl -> draw_instanced = FALSE;
578 if (glsl -> obj -> num_indices > 0) nvbo ++;
579 if (glsl -> obj -> num_instances > 0)
582 if (glsl -> obj -> num_instances > 1) glsl -> draw_instanced = TRUE;
586 glGenBuffers (nvbo, glsl -> vbo);
617 glDetachShader (glsl ->
id,glsl -> vertex_shader);
618 if (geometry != NULL) glDetachShader (glsl ->
id, glsl -> geometry_shader);
619 glDetachShader (glsl ->
id, glsl -> fragment_shader);
634 if (
id ==
ATOMS)
return TRUE;
635 if (
id ==
BONDS)
return TRUE;
636 if (
id ==
POLYS)
return TRUE;
637 if (
id ==
RINGS)
return TRUE;
638 if (
id ==
SELEC)
return TRUE;
639 if (
id ==
MDBOX)
return this_proj -> cell.npt;
640 if (
id ==
VOLMS)
return TRUE;
659 for (j=0; j< this_proj -> steps; j++) view -> n_shaders[i][j] = -1;
676 for (i=0; i<nshaders; i++)
679 this_proj -> modelgl -> create_shaders[k] = TRUE;
680 for (j=0; j<this_proj -> steps; j++)
682 this_proj -> modelgl -> n_shaders[k][j] = -1;
698 if (view -> ogl_glsl[shader][i] != NULL)
700 g_free (view -> ogl_glsl[shader][i]);
701 view -> ogl_glsl[shader][i] = NULL;
718 view -> create_shaders[i] = TRUE;
733 view -> create_shaders[
LABEL] = TRUE;
734 view -> create_shaders[
PICKS] = TRUE;
735 view -> create_shaders[
MEASU] = TRUE;
738 if (
is_atom_win_active(view) || (view -> mode ==
EDITION && (view -> anim -> last ->
img -> selected[1] -> selected || view -> selection_mode == 5)))
740 if (view -> measure_win != NULL)
763 view -> ogl_glsl[i] = NULL;
766 view -> ogl_glsl[i] = g_malloc0 (this_proj -> steps*
sizeof*view -> ogl_glsl[i]);
767 view -> n_shaders[i] =
allocint (this_proj -> steps);
768 for (j=0; j<this_proj -> steps; j++)
770 view -> n_shaders[i][j] = -1;
775 j = (i ==
MEASU) ? 2 : 1;
776 view -> ogl_glsl[i] = g_malloc0 (j*
sizeof*view -> ogl_glsl[i]);
777 view -> ogl_glsl[i][0] = NULL;
778 view -> n_shaders[i] =
allocint (j);
780 view -> create_shaders[i] = TRUE;
822 k = (glsl -> draw_type ==
GLSL_LIGHT) ? 0 :
plot -> m_terial.param[0];
823 glUniformMatrix4fv (glsl -> light_uniform[0], 1, GL_FALSE, &
wingl -> model_view_matrix.m00);
824 glUniform1i (glsl -> light_uniform[1], k);
825 glUniform3f (glsl -> light_uniform[2],
plot -> m_terial.albedo.x,
plot -> m_terial.albedo.y,
plot -> m_terial.albedo.z);
826 for (j=0; j<5; j++) glUniform1f (glsl -> light_uniform[3+j],
plot -> m_terial.param[j+1]);
827 glUniform1i (glsl -> light_uniform[8],
plot -> f_g.mode);
828 glUniform1i (glsl -> light_uniform[9],
plot -> f_g.based);
829 glUniform1f (glsl -> light_uniform[10],
plot -> f_g.density);
830 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);
831 glUniform3f (glsl -> light_uniform[12],
plot -> f_g.color.x,
plot -> f_g.color.y,
plot -> f_g.color.z);
832 glUniform1i (glsl -> light_uniform[13],
plot -> lights);
833 for (j=0; j<
plot -> lights; j++)
836 glUniform1i (glsl -> light_uniform[k],
plot -> l_ght[j].type);
837 if (
plot -> l_ght[j].fix == 0)
845 glUniform3f (glsl -> light_uniform[k+1], l_pos.
x, l_pos.
y, l_pos.
z);
846 if (
plot -> l_ght[j].fix == 0)
848 l_dir = m4_mul_pos (
wingl -> model_matrix,
plot -> l_ght[j].direction);
852 l_dir = m4_mul_pos (
wingl -> model_view_matrix,
plot -> l_ght[j].direction);
854 glUniform3f (glsl -> light_uniform[k+2], l_dir.
x, l_dir.
y, l_dir.
z);
855 glUniform3f (glsl -> light_uniform[k+3],
plot -> l_ght[j].intensity.x,
plot -> l_ght[j].intensity.y,
plot -> l_ght[j].intensity.z);
856 glUniform1f (glsl -> light_uniform[k+4],
plot -> l_ght[j].attenuation.x);
857 glUniform1f (glsl -> light_uniform[k+5],
plot -> l_ght[j].attenuation.y);
858 glUniform1f (glsl -> light_uniform[k+6],
plot -> l_ght[j].attenuation.z);
859 glUniform1f (glsl -> light_uniform[k+7], cos(
plot -> l_ght[j].spot_data.x*
pi/180.0));
860 glUniform1f (glsl -> light_uniform[k+8], cos(
plot -> l_ght[j].spot_data.y*
pi/180.0));
861 glUniform1f (glsl -> light_uniform[k+9], cos(
plot -> l_ght[j].spot_data.z*
pi/180.0));
877 glUniformMatrix4fv (glsl -> uniform_loc[2], 1, GL_FALSE, &
wingl -> label_projection_matrix.m00);
878 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, &
wingl -> un_view_matrix.m00);
879 glUniform4f (glsl -> uniform_loc[4],
wingl -> view_port.w,
wingl -> view_port.x,
wingl -> view_port.y,
wingl -> view_port.z);
880 glUniform4f (glsl -> uniform_loc[5], glsl -> obj ->
shift[0], glsl -> obj ->
shift[1],
881 glsl -> obj ->
shift[2], glsl -> obj ->
shift[3]);
882 glUniform4f (glsl -> uniform_loc[6], glsl ->
col -> red, glsl ->
col -> green,
883 glsl ->
col -> blue, glsl ->
col -> alpha);
884 if (glsl ->
object ==
MEASU) glUniform1i (glsl -> uniform_loc[7], (
plot -> mtilt) ? 1 : 0);
898 if (glsl ->
object ==
MAXIS)
903 k =
wingl -> atom_win -> active;
910 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> axis_proj_model_view_matrix.m00);
914 else if (glsl ->
object ==
LABEL)
916 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
919 else if (glsl ->
object ==
MEASU)
921 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
922 if (glsl -> vert_type == GL_TRIANGLE_STRIP)
928 glUniform1i (glsl -> uniform_loc[1],
plot -> mfactor);
930 if (glsl -> vert_type == GL_TRIANGLES)
933 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, &
wingl -> label_projection_matrix.m00);
935 glUniformMatrix4fv (glsl -> uniform_loc[4], 1, GL_FALSE, &
wingl -> un_view_matrix.m00);
936 glUniform4f (glsl -> uniform_loc[5],
wingl -> view_port.w,
wingl -> view_port.x,
wingl -> view_port.y,
wingl -> view_port.z);
939 glUniform1f (glsl -> uniform_loc[6], 1.0);
943 glUniform1f (glsl -> uniform_loc[6],
plot -> p_depth);
947 else if (glsl ->
object ==
LIGHT)
949 if (
plot -> light_loc[ids])
951 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_matrix.m00);
955 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
960 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, &
wingl -> proj_model_view_matrix.m00);
963 if (glsl -> line_width != 0.0) glLineWidth (glsl -> line_width);
967 glBindVertexArray (glsl -> vao);
972 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
977 glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
981 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
986 if (glsl -> draw_instanced)
988 glDrawElementsInstanced (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0, glsl -> obj -> num_instances);
992 glDrawElements (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0);
1000 glActiveTexture (GL_TEXTURE0);
1001 glBindTexture (
ogl_texture, glsl -> obj -> texture);
1003 if (glsl -> draw_instanced)
1005 j = (glsl -> draw_type ==
GLSL_STRING) ? 4 : 3*(glsl -> draw_type+1);
1006 glDrawArraysInstanced (glsl -> vert_type, 0, j, glsl -> obj -> num_instances);
1010 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1015 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1018 glBindVertexArray (0);
1034 for (j=0; j<
wingl -> n_shaders[id][i]; j++)
1036 if (
wingl -> ogl_glsl[
id][i][j])
1038 glsl =
wingl -> ogl_glsl[id][i][j];
1039 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 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...