atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
ogl_shading.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2026 by CNRS and University of Strasbourg */
15
22
23/*
24* This file: 'ogl_shading.c'
25*
26* Contains:
27*
28
29 - The functions to create GLSL programs
30 - The functions to manage GLSL programs
31
32*
33*
34* List of functions:
35
36 GLuint create_shader (int type, const GLchar * src);
37 GLuint * alloc_shader_pointer (GLuint * pointer, int shaders);
38 GLuint * glsl_add_lights (glsl_program * glsl);
39
40 gboolean in_md_shaders (project * this_proj, int id);
41 gboolean glsl_disable_cull_face (glsl_program * glsl);
42
43 void allocate_instances (object_3d * object);
44 void set_light_uniform_location (GLuint * lightning, int id, int j, int k, char * string);
45 void glsl_bind_points (glsl_program * glsl, object_3d * obj);
46 void glsl_bind_spheres (glsl_program * glsl, object_3d * obj);
47 void glsl_bind_lines (glsl_program * glsl, object_3d * obj);
48 void glsl_bind_cylinders (glsl_program * glsl, object_3d * obj);
49 void glsl_bind_caps (glsl_program * glsl, object_3d * obj);
50 void glsl_bind_polyhedra (glsl_program * glsl, object_3d * obj);
51 void glsl_bind_background (glsl_program * glsl, object_3d * obj);
52 void update_string_instances (glsl_program * glsl, object_3d * obj);
53 void glsl_bind_string (glsl_program * glsl, object_3d * obj);
54 void re_create_all_md_shaders (glwin * view);
55 void re_create_md_shaders (int nshaders, int shaders[nshaders], project * this_proj);
56 void cleaning_shaders (glwin * view, int shader);
57 void recreate_all_shaders (glwin * view);
58 void init_default_shaders (glwin * view);
59 void init_shaders (glwin * view);
60 void set_lights_data (glsl_program * glsl);
61 void shading_glsl_text (glsl_program * glsl);
62 void update_ray_instances (glsl_program * glsl);
63 void render_this_shader (glsl_program * glsl, int ids);
64 void draw_vertices (int id);
65
66 glsl_program * free_this_glsl_program (glsl_program * glsl);
67 glsl_program * init_shader_program (int object, int object_id,
68 const GLchar * vertex, const GLchar * geometry, const GLchar * fragment,
69 GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d * obj);
70
71 object_3d * duplicate_object_3d (object_3d * old_obj);
72
73*
74* Notes:
75*
76
77*/
78
79#include "global.h"
80#include "interface.h"
81#include "glview.h"
82#include "ogl_shading.h"
83
84/* Create and compile a shader */
93GLuint create_shader (int type, const GLchar * src)
94{
95 GLuint shader;
96 int status;
97
98 shader = glCreateShader (type);
99 glShaderSource (shader, 1, & src, NULL);
100 glCompileShader (shader);
101
102 glGetShaderiv (shader, GL_COMPILE_STATUS, & status);
103 if (status == GL_FALSE)
104 {
105 int log_len;
106 char *buffer;
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",
112 buffer);
113
114 g_free (buffer);
115 glDeleteShader (shader);
116 return 0;
117 }
118 return shader;
119}
120
129GLuint * alloc_shader_pointer (GLuint * pointer, int shaders)
130{
131 if (pointer != NULL)
132 {
133 g_free (pointer);
134 pointer = NULL;
135 }
136 return allocgluint(shaders);
137}
138
139#define LIGHT_INFO 3
140#define MATERIAL_DATA 8
141#define FOG_DATA 5
142#define LIGHT_DATA 10
143
152{
153 object -> instances = allocfloat (object -> num_instances * object -> inst_buffer_size);
154}
155
167void set_light_uniform_location (GLuint * lightning, int id, int j, int k, char * string)
168{
169 gchar * light_string = g_strdup_printf ("AllLights[%d].%s", j, string);
170 lightning[LIGHT_INFO+MATERIAL_DATA+FOG_DATA+LIGHT_DATA*j+k] = glGetUniformLocation (id, light_string);
171 g_free (light_string);
172}
173
182{
183 int tot = MATERIAL_DATA + plot -> l_ghtning.lights * LIGHT_DATA + LIGHT_INFO + FOG_DATA;
184 GLuint * lightning = allocgluint(tot);
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");
201 int j;
202 for (j=0; j<plot -> l_ghtning.lights; j++)
203 {
204 set_light_uniform_location (lightning, glsl -> id, j, 0, "type");
205 set_light_uniform_location (lightning, glsl -> id, j, 1, "position");
206 set_light_uniform_location (lightning, glsl -> id, j, 2, "direction");
207 set_light_uniform_location (lightning, glsl -> id, j, 3, "intensity");
208 set_light_uniform_location (lightning, glsl -> id, j, 4, "constant");
209 set_light_uniform_location (lightning, glsl -> id, j, 5, "linear");
210 set_light_uniform_location (lightning, glsl -> id, j, 6, "quadratic");
211 set_light_uniform_location (lightning, glsl -> id, j, 7, "cone_angle");
212 set_light_uniform_location (lightning, glsl -> id, j, 8, "spot_inner");
213 set_light_uniform_location (lightning, glsl -> id, j, 9, "spot_outer");
214 }
215
216 return lightning;
217}
218
228{
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");
232
233 // The points vertices
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);
238 // The instances (pos + col)
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);
250}
251
261{
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");
265
266 // The sphere vertices
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);
271 // The sphere indices
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);
274 // The instances (pos + col)
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);
286}
287
297{
298 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "vertColor");
299 // The line vertices
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)));
306
307 if (glsl -> object == MEASU)
308 {
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");
315 }
316}
317
327{
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");
333
334 // The cylinder vertices
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);
339
340 // The cylinder indices
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);
343
344 // The instances (pos + lenght, + rad + rot + col)
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);
362
363 if (obj -> inst_buffer_size == CYLI_BUFF_SIZE + 2)
364 {
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);
370
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);
374 }
375}
376
386{
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");
391
392 // The cylinder vertices
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);
397
398 // The cylinder indices
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);
401
402 // The instances (pos + length, + rad + rot + col)
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);
417}
418
428{
429 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "vertNormal");
430 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "vertColor");
431
432 // The polyhedra vertices (triangles + normal orientation)
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)));
441}
442
452{
453
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");
458
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);
463}
464
474{
475 // The instances (pos)
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]);
479
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)
483 {
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)
491 {
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);
495 }
496 }
497}
498
508{
509 glActiveTexture (GL_TEXTURE0);
510 glBindTexture (ogl_texture, obj -> texture);
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");
518
519 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "tcoord");
520 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "offset");
521 if (glsl -> object == MEASU)
522 {
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");
527 }
528
529 // The string (rendered using triangles and textures + colors)
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)));
536 update_string_instances (glsl, obj);
537}
538
547{
548 object_3d * new_obj = g_malloc0(sizeof*new_obj);
549 new_obj -> quality = old_obj -> quality;
550 // Vertices
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);
554 // Indices
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)
558 {
559 new_obj -> indices = duplicate_int (new_obj -> num_indices*old_obj -> ind_buffer_size, old_obj -> indices);
560 }
561 // Instances
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)
565 {
566 new_obj -> instances = duplicate_float (new_obj -> num_instances*old_obj -> inst_buffer_size, old_obj -> instances);
567 }
568 new_obj -> texture = old_obj -> texture;
569 int i;
570 for (i=0; i<5; i++) new_obj -> shift[i] = old_obj -> shift[i];
571 return new_obj;
572}
573
582{
583 if (obj -> vertices) g_free (obj -> vertices);
584 if (obj -> indices) g_free (obj -> indices);
585 if (obj -> instances) g_free (obj -> instances);
586 g_free (obj);
587 return NULL;
588}
589
598{
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);
603 glsl -> obj = free_object_3d (glsl -> obj);
604 g_free (glsl);
605 return NULL;
606}
607
626glsl_program * init_shader_program (int object, int object_id,
627 const GLchar * vertex, const GLchar * geometry, const GLchar * fragment,
628 GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d * obj)
629{
630 glsl_program * glsl = g_malloc0(sizeof * glsl);
631
632 glsl -> id = glCreateProgram ();
633 glsl -> object = object;
634 glsl -> draw_type = object_id;
635
636 glsl -> vertex_shader = create_shader (GL_VERTEX_SHADER, vertex);
637 glAttachShader (glsl -> id, glsl -> vertex_shader);
638 if (geometry != NULL)
639 {
640 glsl -> geometry_shader = create_shader (GL_GEOMETRY_SHADER, geometry);
641 glAttachShader (glsl -> id, glsl -> geometry_shader);
642 }
643 glsl -> fragment_shader = create_shader (GL_FRAGMENT_SHADER, fragment);
644 glAttachShader (glsl -> id, glsl -> fragment_shader);
645
646 glBindFragDataLocation (glsl -> id, 0, "fragment_color");
647 glLinkProgram(glsl -> id);
648
649 glsl -> vert_type = type_of_vertices;
650
651 glGenVertexArrays (1, & glsl -> vao);
652
653 glBindVertexArray (glsl -> vao);
654
655 glsl -> array_pointer = alloc_shader_pointer (glsl -> array_pointer, narray);
656 glsl -> uniform_loc = alloc_shader_pointer (glsl -> uniform_loc, nunif);
657
658 // For other than background always the MVP matrix as uniform 0
659 if (object_id != GLSL_BACK) glsl -> uniform_loc[0] = glGetUniformLocation (glsl -> id, "mvp");
660 // and always the vertices as array 0
661 glsl -> array_pointer[0] = glGetAttribLocation (glsl -> id, "vert");
662
663 glsl -> light_uniform = NULL;
664 if (lightning) glsl -> light_uniform = glsl_add_lights (glsl);
665
666 glsl -> obj = duplicate_object_3d (obj);
667 if (glsl -> draw_type != GLSL_STRING) obj = free_object_3d (obj);
668
669 glsl -> draw_instanced = FALSE;
670
671 int nvbo = 1;
672 if (glsl -> obj -> num_indices > 0) nvbo ++;
673 if (glsl -> obj -> num_instances > 0)
674 {
675 nvbo ++;
676 if (glsl -> obj -> num_instances > 1) glsl -> draw_instanced = TRUE;
677 }
678
679 glsl -> vbo = allocgluint (nvbo);
680 glGenBuffers (nvbo, glsl -> vbo);
681
682 switch (object_id)
683 {
684 case GLSL_SPHERES:
685 // narray = 4
686 glsl_bind_spheres (glsl, glsl -> obj);
687 break;
688 case GLSL_POINTS:
689 // narray = 4
690 glsl_bind_points (glsl, glsl -> obj);
691 break;
692 case GLSL_LINES:
693 // narray = 3
694 glsl_bind_lines (glsl, glsl -> obj);
695 break;
696 case GLSL_CYLINDERS:
697 // narray = 6
698 glsl_bind_cylinders (glsl, glsl -> obj);
699 break;
700 case GLSL_CAPS:
701 // narray = 5
702 glsl_bind_caps (glsl, glsl -> obj);
703 break;
704 case GLSL_POLYEDRA:
705 glsl_bind_polyhedra (glsl, glsl -> obj);
706 break;
707 case GLSL_STRING:
708 glsl_bind_string (glsl, glsl -> obj);
709 break;
710 case GLSL_BACK:
711 glsl_bind_background (glsl, glsl -> obj);
712 break;
713 }
714 glDetachShader (glsl -> id,glsl -> vertex_shader);
715 if (geometry != NULL) glDetachShader (glsl -> id, glsl -> geometry_shader);
716 glDetachShader (glsl -> id, glsl -> fragment_shader);
717
718 return glsl;
719}
720
729gboolean in_md_shaders (project * this_proj, int id)
730{
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;
738 return FALSE;
739}
740
749{
750 int i, j;
751 project * this_proj = get_project_by_id(view -> proj);
752 for (i=0; i<NGLOBAL_SHADERS; i++)
753 {
754 if (in_md_shaders (this_proj, i))
755 {
756 for (j=0; j< this_proj -> steps; j++) view -> n_shaders[i][j] = -1;
757 }
758 }
759}
760
770void re_create_md_shaders (int nshaders, int shaders[nshaders], project * this_proj)
771{
772 int i, j, k;
773 for (i=0; i<nshaders; i++)
774 {
775 k = shaders[i];
776 this_proj -> modelgl -> create_shaders[k] = TRUE;
777 for (j=0; j<this_proj -> steps; j++)
778 {
779 this_proj -> modelgl -> n_shaders[k][j] = -1;
780 }
781 }
782}
783
792void cleaning_shaders (glwin * view, int shader)
793{
794 int i, j, k;
795 i = (in_md_shaders(get_project_by_id(view -> proj), shader)) ? step : 0;
796 if (view -> ogl_glsl[shader][i] != NULL)
797 {
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]);
800 }
801 view -> n_shaders[shader][i] = (in_md_shaders(get_project_by_id(view -> proj), shader)) ? -1 : 0;
802}
803
812{
813 int i;
814 for (i=0; i<NGLOBAL_SHADERS; i++)
815 {
816 view -> create_shaders[i] = TRUE;
817 }
818}
819
828{
829 int shaders[6] = {ATOMS, BONDS, SELEC, POLYS, RINGS, VOLMS};
831 view -> create_shaders[LABEL] = TRUE;
832 view -> create_shaders[PICKS] = TRUE;
833 view -> create_shaders[MEASU] = TRUE;
834 update (view);
835 int i;
836 if (is_atom_win_active(view) || (view -> mode == EDITION && (view -> anim -> last -> img -> selected[1] -> selected || view -> selection_mode == 5)))
837 {
838 if (view -> measure_win != NULL)
839 {
840 for (i=0; i<3; i++)
841 {
842 if (view -> measure_win -> selection_tree[i] != NULL) update_selection_tree (view, 1, i);
843 }
844 }
845 }
846}
847
855void init_shaders (glwin * view)
856{
857 int i, j;
858 project * this_proj = get_project_by_id (view -> proj);
859 for (i=0; i<NGLOBAL_SHADERS; i++)
860 {
861 view -> ogl_glsl[i] = NULL;
862 if (in_md_shaders (this_proj, i))
863 {
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++)
867 {
868 view -> n_shaders[i][j] = -1;
869 }
870 }
871 else
872 {
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);
877 }
878 view -> create_shaders[i] = TRUE;
879 }
880}
881
890{
891 if (glsl -> draw_type == GLSL_POINTS)
892 {
893 return FALSE;
894 }
895 else if (glsl -> draw_type == GLSL_LINES)
896 {
897 return FALSE;
898 }
899 else if (glsl -> draw_type == GLSL_LIGHT)
900 {
901 return FALSE;
902 }
903 else
904 {
905 return TRUE;
906 }
907}
908
917{
918 int j, k;
919 vec3_t l_pos, l_dir;
920
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++)
934 {
936 glUniform1i (glsl -> light_uniform[k], plot -> l_ghtning.spot[j] -> type);
937 if (plot -> l_ghtning.spot[j] -> fix == 0)
938 {
939 l_pos = m4_mul_pos (wingl -> model_matrix, plot -> l_ghtning.spot[j] -> position);
940 }
941 else
942 {
943 l_pos = m4_mul_pos (wingl -> model_view_matrix, plot -> l_ghtning.spot[j] -> position);
944 }
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)
947 {
948 l_dir = m4_mul_pos (wingl -> model_matrix, plot -> l_ghtning.spot[j] -> direction);
949 }
950 else
951 {
952 l_dir = m4_mul_pos (wingl -> model_view_matrix, plot -> l_ghtning.spot[j] -> direction);
953 }
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));
962 }
963}
964
965uint16_t stipple_pattern[NDOTS]={ 0xAAAA, 0x1111, 0x0000, 0x55FF, 0x24FF, 0x3F3F, 0x33FF, 0x27FF};
969
978{
979 wingl -> label_projection_matrix = create_label_matrices ();
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);
988}
989
998void render_this_shader (glsl_program * glsl, int ids)
999{
1000 int j, k;
1001 if (glsl -> object == MAXIS)
1002 {
1003 j = 0;
1005 {
1006 k = wingl -> atom_win -> active;
1007 if (wingl -> atom_win -> show_axis[k])
1008 {
1009 j = wingl -> atom_win -> axis[k];
1010 }
1011 }
1012 wingl -> axis_proj_model_view_matrix = create_axis_matrices (j);
1013 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> axis_proj_model_view_matrix.m00);
1014 j = (plot -> xyz -> axis == WIREFRAME) ? 1 : 3;
1015 if (ids > j) shading_glsl_text (glsl);
1016 }
1017 else if (glsl -> object == LABEL)
1018 {
1019 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
1020 shading_glsl_text (glsl);
1021 }
1022 else if (glsl -> object == BACKG)
1023 {
1024 for (j=0; j<2; j++)
1025 {
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);
1030 }
1031 glUniform1i (glsl -> uniform_loc[2], plot -> back -> direction);
1032 glUniform1f (glsl -> uniform_loc[3], plot -> back -> position);
1033 }
1034 else if (glsl -> object == MEASU)
1035 {
1036 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
1037 if (glsl -> vert_type == GL_TRIANGLE_STRIP)
1038 {
1039 shading_glsl_text (glsl);
1040 }
1041 else
1042 {
1043 glUniform1i (glsl -> uniform_loc[1], this_factor);
1044 glUniform1ui (glsl -> uniform_loc[2], stipple_pattern[this_pattern]);
1045 if (glsl -> vert_type == GL_TRIANGLES)
1046 {
1047 wingl -> label_projection_matrix = create_label_matrices ();
1048 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, & wingl -> label_projection_matrix.m00);
1049 }
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);
1052 if (plot -> rep == PERSPECTIVE)
1053 {
1054 glUniform1f (glsl -> uniform_loc[6], 1.0);
1055 }
1056 else
1057 {
1058 glUniform1f (glsl -> uniform_loc[6], plot -> p_depth);
1059 }
1060 }
1061 }
1062 else if (glsl -> object == LIGHT)
1063 {
1064 if (plot -> light_loc[ids])
1065 {
1066 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_matrix.m00);
1067 }
1068 else
1069 {
1070 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
1071 }
1072 }
1073 else
1074 {
1075 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
1076 }
1077
1078 if (glsl -> line_width != 0.0) glLineWidth (glsl -> line_width);
1079
1080 if (glsl -> light_uniform != NULL) set_lights_data (glsl);
1081
1082 glBindVertexArray (glsl -> vao);
1083
1084 if (glsl_disable_cull_face (glsl)) glDisable (GL_CULL_FACE);
1085 if (plot -> render == LINE)
1086 {
1087 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
1088 glLineWidth (1.0);
1089 }
1090 else if (plot -> render == PTS)
1091 {
1092 glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
1093 }
1094 else
1095 {
1096 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1097 }
1098
1099 if (glsl -> draw_type == GLSL_SPHERES || glsl -> draw_type == GLSL_CYLINDERS || glsl -> draw_type == GLSL_CAPS)
1100 {
1101 gboolean poly_offset = (! plot -> ray_tracing && (glsl -> draw_type == GLSL_CYLINDERS || glsl -> draw_type == GLSL_CAPS));
1102 if (poly_offset)
1103 {
1104 glEnable (GL_POLYGON_OFFSET_FILL);
1105 glPolygonOffset (1.0, 1.0);
1106 }
1107 if (glsl -> draw_instanced)
1108 {
1109 glDrawElementsInstanced (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0, glsl -> obj -> num_instances);
1110 }
1111 else
1112 {
1113 glDrawElements (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0);
1114 }
1115 if (poly_offset)
1116 {
1117 glDisable (GL_POLYGON_OFFSET_FILL);
1118 }
1119 }
1120 else if (glsl -> draw_type == GLSL_POINTS || glsl -> draw_type == GLSL_LINES || glsl -> draw_type == GLSL_STRING)
1121 {
1122 if (glsl -> draw_type == GLSL_STRING)
1123 {
1124 glEnable (ogl_texture);
1125 glActiveTexture (GL_TEXTURE0);
1126 glBindTexture (ogl_texture, glsl -> obj -> texture);
1127 }
1128#ifdef GTK4
1129 else
1130 {
1131 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1132 }
1133#endif
1134 if (glsl -> draw_instanced)
1135 {
1136 j = (glsl -> draw_type == GLSL_STRING) ? 4 : 3*(glsl -> draw_type+1);
1137 glDrawArraysInstanced (glsl -> vert_type, 0, j, glsl -> obj -> num_instances);
1138 }
1139 else
1140 {
1141 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1142 }
1143#ifdef GTK4
1144 if (glsl -> draw_type == GLSL_POINTS || glsl -> draw_type == GLSL_LINES)
1145 {
1146 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1147 }
1148#endif
1149 }
1150 else
1151 {
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);
1155 }
1156 if (glsl_disable_cull_face (glsl)) glEnable (GL_CULL_FACE);
1157 glBindVertexArray (0);
1158}
1159
1167void draw_vertices (int id)
1168{
1169 int i, j;
1170 glsl_program * glsl;
1171 if (id != MEASU)
1172 {
1173 i = (in_md_shaders(proj_gl, id)) ? step : 0;
1174 for (j=0; j<wingl -> n_shaders[id][i]; j++)
1175 {
1176 if (wingl -> ogl_glsl[id][i][j])
1177 {
1178 glsl = wingl -> ogl_glsl[id][i][j];
1179 glUseProgram (glsl -> id);
1180 render_this_shader (glsl, j);
1181 }
1182 }
1183 }
1184 else
1185 {
1186 for (i=0; i<2; i++)
1187 {
1188 this_pattern = plot -> mpattern[i];
1189 this_tilt = plot -> mtilt[i];
1190 this_factor = plot -> mfactor[i];
1191 for (j=0; j<wingl -> n_shaders[id][i]; j++)
1192 {
1193 if (wingl -> ogl_glsl[id][i][j])
1194 {
1195 glsl = wingl -> ogl_glsl[id][i][j];
1196 glUseProgram (glsl -> id);
1197 render_this_shader (glsl, j);
1198 }
1199 }
1200 }
1201 }
1202}
mat4_t create_axis_matrices(int type)
create axis OpenGL rendering matrices
Definition d_axis.c:101
mat4_t create_label_matrices()
create label projection matrices
Definition d_label.c:56
ColRGBA col
Definition d_measures.c:77
int * shift
Definition d_measures.c:72
dint rep
Definition dlp_edit.c:2242
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:547
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:579
double pi
Definition global.c:202
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:385
Global variable declarations Global convenience function declarations Global data structure defin...
gboolean is_atom_win_active(glwin *view)
is the model edition window visible ?
Definition atom_edit.c:71
project * proj
GLuint * allocgluint(int val)
allocate a GLuint * pointer
Definition glview.c:131
gboolean in_md_shaders(project *this_proj, int id)
is this shader MD dependent ?
#define NDOTS
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:461
GLenum ogl_texture
Definition glview.c:122
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
image * plot
Definition ogl_draw.c:72
project * proj_gl
Definition ogl_draw.c:66
glwin * wingl
Definition ogl_draw.c:65
@ EDITION
Definition glview.h:167
render
Definition glview.h:191
@ LINE
Definition glview.h:193
@ PTS
Definition glview.h:194
@ PERSPECTIVE
Definition glview.h:161
int step
Definition ogl_draw.c:76
void update_selection_tree(glwin *view, int pi, int id)
update measurements tree view
Definition w_measures.c:376
@ WIREFRAME
Definition glview.h:183
shaders
The different types of shaders in the atomes program.
Definition glwin.h:88
@ BONDS
Definition glwin.h:90
@ PICKS
Definition glwin.h:97
@ LABEL
Definition glwin.h:98
@ VOLMS
Definition glwin.h:102
@ POLYS
Definition glwin.h:92
@ MAXIS
Definition glwin.h:94
@ SELEC
Definition glwin.h:91
@ MDBOX
Definition glwin.h:93
@ MEASU
Definition glwin.h:99
@ ATOMS
Definition glwin.h:89
@ RINGS
Definition glwin.h:96
@ BACKG
Definition glwin.h:103
@ LIGHT
Definition glwin.h:100
#define NGLOBAL_SHADERS
Definition glwin.h:69
Messaging function declarations.
position
Definition m_proj.c:48
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
#define LIGHT_DATA
GLuint * glsl_add_lights(glsl_program *glsl)
add lightning to an OpenGL shader program
void init_shaders(glwin *view)
initialize all the OpenGL shaders
int this_factor
void set_lights_data(glsl_program *glsl)
set lightning data for an OpenGL progam
int this_pattern
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
#define MATERIAL_DATA
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
Definition ogl_shading.c:93
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
#define LIGHT_INFO
uint16_t stipple_pattern[NDOTS]
#define FOG_DATA
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.
int this_tilt
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...
#define CYLI_BUFF_SIZE
Definition ogl_shading.h:51
@ GLSL_LIGHT
Definition ogl_shading.h:45
@ GLSL_CAPS
Definition ogl_shading.h:42
@ GLSL_POINTS
Definition ogl_shading.h:38
@ GLSL_STRING
Definition ogl_shading.h:44
@ GLSL_LINES
Definition ogl_shading.h:40
@ GLSL_POLYEDRA
Definition ogl_shading.h:43
@ GLSL_SPHERES
Definition ogl_shading.h:39
@ GLSL_BACK
Definition ogl_shading.h:46
@ GLSL_CYLINDERS
Definition ogl_shading.h:41
Definition glwin.h:332
Definition glwin.h:967
float y
Definition math_3d.h:130
float x
Definition math_3d.h:130
float z
Definition math_3d.h:130
int status
Definition w_advance.c:173
GtkWidget * img
Definition workspace.c:70