atomes 1.2.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-2025 by CNRS and University of Strasbourg */
15
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 set_light_uniform_location (GLuint * lightning, int id, int j, int k, char * string);
44 void glsl_bind_points (glsl_program * glsl, object_3d * obj);
45 void glsl_bind_spheres (glsl_program * glsl, object_3d * obj);
46 void glsl_bind_lines (glsl_program * glsl, object_3d * obj);
47 void glsl_bind_cylinders (glsl_program * glsl, object_3d * obj);
48 void glsl_bind_caps (glsl_program * glsl, object_3d * obj);
49 void glsl_bind_polyhedra (glsl_program * glsl, object_3d * obj);
50 void glsl_bind_background (glsl_program * glsl, object_3d * obj);
51 void update_string_instances (glsl_program * glsl, object_3d * obj);
52 void glsl_bind_string (glsl_program * glsl, object_3d * obj);
53 void re_create_all_md_shaders (glwin * view);
54 void re_create_md_shaders (int nshaders, int shaders[nshaders], project * this_proj);
55 void cleaning_shaders (glwin * view, int shader);
56 void recreate_all_shaders (glwin * view);
57 void init_default_shaders (glwin * view);
58 void init_shaders (glwin * view);
59 void set_lights_data (glsl_program * glsl);
60 void shading_glsl_text (glsl_program * glsl);
61 void render_this_shader (glsl_program * glsl, int ids);
62 void draw_vertices (int id);
63
64 glsl_program * init_shader_program (int object, int object_id,
65 const GLchar * vertex, const GLchar * geometry, const GLchar * fragment,
66 GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d * obj);
67
68 object_3d * duplicate_object_3d (object_3d * old_obj);
69
70*/
71
72#include "global.h"
73#include "interface.h"
74#include "glview.h"
75#include "ogl_shading.h"
76
77/* Create and compile a shader */
86GLuint create_shader (int type, const GLchar * src)
87{
88 GLuint shader;
89 int status;
90
91 shader = glCreateShader (type);
92 glShaderSource (shader, 1, & src, NULL);
93 glCompileShader (shader);
94
95 glGetShaderiv (shader, GL_COMPILE_STATUS, & status);
96 if (status == GL_FALSE)
97 {
98 int log_len;
99 char *buffer;
100 glGetShaderiv (shader, GL_INFO_LOG_LENGTH, & log_len);
101 buffer = g_malloc (log_len + 1);
102 glGetShaderInfoLog (shader, log_len, NULL, buffer);
103 g_warning ("Compile failure in %s shader:\n%s",
104 type == GL_VERTEX_SHADER ? "vertex" : "fragment",
105 buffer);
106
107 g_free (buffer);
108 glDeleteShader (shader);
109 return 0;
110 }
111 return shader;
112}
113
122GLuint * alloc_shader_pointer (GLuint * pointer, int shaders)
123{
124 if (pointer != NULL)
125 {
126 g_free (pointer);
127 pointer = NULL;
128 }
129 return allocgluint(shaders);
130}
131
132#define LIGHT_INFO 3
133#define MATERIAL_DATA 6
134#define FOG_DATA 5
135#define LIGHT_DATA 10
136
137
149void set_light_uniform_location (GLuint * lightning, int id, int j, int k, char * string)
150{
151 lightning[LIGHT_INFO+MATERIAL_DATA+FOG_DATA+LIGHT_DATA*j+k] = glGetUniformLocation (id, g_strdup_printf ("AllLights[%d].%s", j, string));
152}
153
162{
163 int tot = MATERIAL_DATA + plot -> l_ghtning.lights * LIGHT_DATA + LIGHT_INFO + FOG_DATA;
164 GLuint * lightning = allocgluint(tot);
165 lightning[0] = glGetUniformLocation (glsl -> id, "m_view");
166 lightning[1] = glGetUniformLocation (glsl -> id, "lights_on");
167 lightning[2] = glGetUniformLocation (glsl -> id, "mat.albedo");
168 lightning[3] = glGetUniformLocation (glsl -> id, "mat.metallic");
169 lightning[4] = glGetUniformLocation (glsl -> id, "mat.roughness");
170 lightning[5] = glGetUniformLocation (glsl -> id, "mat.back_light");
171 lightning[6] = glGetUniformLocation (glsl -> id, "mat.gamma");
172 lightning[7] = glGetUniformLocation (glsl -> id, "mat.alpha");
173 lightning[8] = glGetUniformLocation (glsl -> id, "fog.mode");
174 lightning[9] = glGetUniformLocation (glsl -> id, "fog.based");
175 lightning[10] = glGetUniformLocation (glsl -> id, "fog.density");
176 lightning[11] = glGetUniformLocation (glsl -> id, "fog.depth");
177 lightning[12] = glGetUniformLocation (glsl -> id, "fog.color");
178 lightning[13] = glGetUniformLocation (glsl -> id, "numLights");
179 int j;
180 for (j=0; j<plot -> l_ghtning.lights; j++)
181 {
182 set_light_uniform_location (lightning, glsl -> id, j, 0, "type");
183 set_light_uniform_location (lightning, glsl -> id, j, 1, "position");
184 set_light_uniform_location (lightning, glsl -> id, j, 2, "direction");
185 set_light_uniform_location (lightning, glsl -> id, j, 3, "intensity");
186 set_light_uniform_location (lightning, glsl -> id, j, 4, "constant");
187 set_light_uniform_location (lightning, glsl -> id, j, 5, "linear");
188 set_light_uniform_location (lightning, glsl -> id, j, 6, "quadratic");
189 set_light_uniform_location (lightning, glsl -> id, j, 7, "cone_angle");
190 set_light_uniform_location (lightning, glsl -> id, j, 8, "spot_inner");
191 set_light_uniform_location (lightning, glsl -> id, j, 9, "spot_outer");
192 }
193 return lightning;
194}
195
205{
206 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "offset");
207 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "size");
208 glsl -> array_pointer[3] = glGetAttribLocation (glsl -> id, "vertColor");
209
210 // The points vertices
211 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
212 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
213 glEnableVertexAttribArray(glsl -> array_pointer[0]);
214 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
215 // The instances (pos + col)
216 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
217 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances * sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
218 glEnableVertexAttribArray (glsl -> array_pointer[1]);
219 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
220 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
221 glEnableVertexAttribArray (glsl -> array_pointer[2]);
222 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
223 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
224 glEnableVertexAttribArray (glsl -> array_pointer[3]);
225 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (4*sizeof(GLfloat)));
226 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
227}
228
238{
239 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "offset");
240 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "radius");
241 glsl -> array_pointer[3] = glGetAttribLocation (glsl -> id, "vertColor");
242
243 // The sphere vertices
244 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
245 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
246 glEnableVertexAttribArray(glsl -> array_pointer[0]);
247 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
248 // The sphere indices
249 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
250 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
251 // The instances (pos + col)
252 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
253 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances * sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
254 glEnableVertexAttribArray (glsl -> array_pointer[1]);
255 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
256 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
257 glEnableVertexAttribArray (glsl -> array_pointer[2]);
258 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
259 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
260 glEnableVertexAttribArray (glsl -> array_pointer[3]);
261 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (4*sizeof(GLfloat)));
262 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
263}
264
274{
275 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "vertColor");
276 // The line vertices
277 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
278 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
279 glEnableVertexAttribArray(glsl -> array_pointer[0]);
280 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *sizeof(GLfloat), (GLvoid*) 0);
281 glEnableVertexAttribArray(glsl -> array_pointer[1]);
282 glVertexAttribPointer(glsl -> array_pointer[1], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size *sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
283
284 if (glsl -> object == MEASU)
285 {
286 glsl -> uniform_loc[1] = glGetUniformLocation (glsl -> id, "factor");
287 glsl -> uniform_loc[2] = glGetUniformLocation (glsl -> id, "pattern");
288 glsl -> uniform_loc[3] = glGetUniformLocation (glsl -> id, "text_proj");
289 glsl -> uniform_loc[4] = glGetUniformLocation (glsl -> id, "un_view");
290 glsl -> uniform_loc[5] = glGetUniformLocation (glsl -> id, "viewp");
291 glsl -> uniform_loc[6] = glGetUniformLocation (glsl -> id, "depth");
292 }
293}
294
304{
305 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "offset");
306 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "height");
307 glsl -> array_pointer[3] = glGetAttribLocation (glsl -> id, "radius");
308 glsl -> array_pointer[4] = glGetAttribLocation (glsl -> id, "quat");
309 glsl -> array_pointer[5] = glGetAttribLocation (glsl -> id, "vertColor");
310
311 // The cylinder vertices
312 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
313 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
314 glEnableVertexAttribArray(glsl -> array_pointer[0]);
315 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
316
317 // The cylinder indices
318 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
319 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
320
321 // The instances (pos + lenght, + rad + rot + col)
322 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
323 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances * sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
324 glEnableVertexAttribArray (glsl -> array_pointer[1]);
325 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
326 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
327 glEnableVertexAttribArray (glsl -> array_pointer[2]);
328 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
329 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
330 glEnableVertexAttribArray (glsl -> array_pointer[3]);
331 glVertexAttribPointer (glsl -> array_pointer[3], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (4*sizeof(GLfloat)));
332 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
333 glEnableVertexAttribArray (glsl -> array_pointer[4]);
334 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (5*sizeof(GLfloat)));
335 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
336 glEnableVertexAttribArray (glsl -> array_pointer[5]);
337 glVertexAttribPointer (glsl -> array_pointer[5], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (9*sizeof(GLfloat)));
338 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
339}
340
350{
351 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "offset");
352 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "radius");
353 glsl -> array_pointer[3] = glGetAttribLocation (glsl -> id, "quat");
354 glsl -> array_pointer[4] = glGetAttribLocation (glsl -> id, "vertColor");
355
356 // The cylinder vertices
357 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
358 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
359 glEnableVertexAttribArray(glsl -> array_pointer[0]);
360 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
361
362 // The cylinder indices
363 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glsl -> vbo[1]);
364 glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj -> num_indices*sizeof(GLint), obj -> indices, GL_STATIC_DRAW);
365
366 // The instances (pos + length, + rad + rot + col)
367 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[2]);
368 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances * sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
369 glEnableVertexAttribArray (glsl -> array_pointer[1]);
370 glVertexAttribPointer (glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
371 glVertexAttribDivisor (glsl -> array_pointer[1], 1);
372 glEnableVertexAttribArray (glsl -> array_pointer[2]);
373 glVertexAttribPointer (glsl -> array_pointer[2], 1, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
374 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
375 glEnableVertexAttribArray (glsl -> array_pointer[3]);
376 glVertexAttribPointer (glsl -> array_pointer[3], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (4*sizeof(GLfloat)));
377 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
378 glEnableVertexAttribArray (glsl -> array_pointer[4]);
379 glVertexAttribPointer (glsl -> array_pointer[4], 4, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (8*sizeof(GLfloat)));
380 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
381}
382
392{
393 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "vertNormal");
394 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "vertColor");
395
396 // The polyhedra vertices (triangles + normal orientation)
397 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
398 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
399 glEnableVertexAttribArray(glsl -> array_pointer[0]);
400 glVertexAttribPointer(glsl -> array_pointer[0], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
401 glEnableVertexAttribArray(glsl -> array_pointer[1]);
402 glVertexAttribPointer(glsl -> array_pointer[1], 3, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
403 glEnableVertexAttribArray(glsl -> array_pointer[2]);
404 glVertexAttribPointer(glsl -> array_pointer[2], 4, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) (6*sizeof(GLfloat)));
405}
406
416{
417
418 glsl -> uniform_loc[0] = glGetUniformLocation (glsl -> id, "first_color");
419 glsl -> uniform_loc[1] = glGetUniformLocation (glsl -> id, "second_color");
420 glsl -> uniform_loc[2] = glGetUniformLocation (glsl -> id, "gradient");
421 glsl -> uniform_loc[3] = glGetUniformLocation (glsl -> id, "position");
422
423 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
424 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
425 glEnableVertexAttribArray(glsl -> array_pointer[0]);
426 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
427}
428
438{
439 // The instances (pos)
440 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[1]);
441 glBufferData(GL_ARRAY_BUFFER, obj -> inst_buffer_size * obj -> num_instances * sizeof(GLfloat), obj -> instances, GL_STATIC_DRAW);
442 glEnableVertexAttribArray (glsl -> array_pointer[2]);
443
444 glVertexAttribPointer (glsl -> array_pointer[2], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
445 glVertexAttribDivisor (glsl -> array_pointer[2], 1);
446 if (glsl -> object == MEASU)
447 {
448 glEnableVertexAttribArray (glsl -> array_pointer[3]);
449 glVertexAttribPointer (glsl -> array_pointer[3], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (3*sizeof(GLfloat)));
450 glVertexAttribDivisor (glsl -> array_pointer[3], 1);
451 glEnableVertexAttribArray (glsl -> array_pointer[4]);
452 glVertexAttribPointer (glsl -> array_pointer[4], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (6*sizeof(GLfloat)));
453 glVertexAttribDivisor (glsl -> array_pointer[4], 1);
454 if (obj -> inst_buffer_size == 12)
455 {
456 glEnableVertexAttribArray (glsl -> array_pointer[5]);
457 glVertexAttribPointer (glsl -> array_pointer[5], 3, GL_FLOAT, GL_FALSE, obj -> inst_buffer_size*sizeof(GLfloat), (GLvoid*) (9*sizeof(GLfloat)));
458 glVertexAttribDivisor (glsl -> array_pointer[5], 1);
459 }
460 }
461}
462
472{
473 glActiveTexture (GL_TEXTURE0);
474 glBindTexture (ogl_texture, obj -> texture);
475 glsl -> uniform_loc[1] = glGetUniformLocation (glsl -> id, "tex");
476 glUniform1i (glsl -> uniform_loc[1], 0);
477 glsl -> uniform_loc[2] = glGetUniformLocation (glsl -> id, "text_proj");
478 glsl -> uniform_loc[3] = glGetUniformLocation (glsl -> id, "un_view");
479 glsl -> uniform_loc[4] = glGetUniformLocation (glsl -> id, "viewp");
480 glsl -> uniform_loc[5] = glGetUniformLocation (glsl -> id, "pos_shift");
481 glsl -> uniform_loc[6] = glGetUniformLocation (glsl -> id, "vert_color");
482
483 glsl -> array_pointer[1] = glGetAttribLocation (glsl -> id, "tcoord");
484 glsl -> array_pointer[2] = glGetAttribLocation (glsl -> id, "offset");
485 if (glsl -> object == MEASU)
486 {
487 glsl -> uniform_loc[7] = glGetUniformLocation (glsl -> id, "tilted");
488 glsl -> array_pointer[3] = glGetAttribLocation (glsl -> id, "at_a");
489 glsl -> array_pointer[4] = glGetAttribLocation (glsl -> id, "at_b");
490 if (obj -> inst_buffer_size == 12) glsl -> array_pointer[5] = glGetAttribLocation (glsl -> id, "at_c");
491 }
492
493 // The string (rendered using triangles and textures + colors)
494 glBindBuffer(GL_ARRAY_BUFFER, glsl -> vbo[0]);
495 glBufferData(GL_ARRAY_BUFFER, obj -> vert_buffer_size * obj -> num_vertices*sizeof(GLfloat), obj -> vertices, GL_STATIC_DRAW);
496 glEnableVertexAttribArray(glsl -> array_pointer[0]);
497 glVertexAttribPointer(glsl -> array_pointer[0], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) 0);
498 glEnableVertexAttribArray(glsl -> array_pointer[1]);
499 glVertexAttribPointer(glsl -> array_pointer[1], 2, GL_FLOAT, GL_FALSE, obj -> vert_buffer_size*sizeof(GLfloat), (GLvoid*) (2*sizeof(GLfloat)));
500 update_string_instances (glsl, obj);
501}
502
511{
512 object_3d * new_obj = g_malloc0 (sizeof*new_obj);
513 new_obj -> quality = old_obj -> quality;
514 // Vertices
515 new_obj -> num_vertices = old_obj -> num_vertices;
516 new_obj -> vert_buffer_size = old_obj -> vert_buffer_size;
517 new_obj -> vertices = duplicate_float (new_obj -> num_vertices*old_obj -> vert_buffer_size, old_obj -> vertices);
518 // Indices
519 new_obj -> num_indices = old_obj -> num_indices;
520 new_obj -> ind_buffer_size = old_obj -> ind_buffer_size;
521 if (old_obj -> indices != NULL)
522 {
523 new_obj -> indices = duplicate_int (new_obj -> num_indices*old_obj -> ind_buffer_size, old_obj -> indices);
524 }
525 // Instances
526 new_obj -> num_instances = old_obj -> num_instances;
527 new_obj -> inst_buffer_size = old_obj -> inst_buffer_size;
528 if (old_obj -> instances != NULL)
529 {
530 new_obj -> instances = duplicate_float (new_obj -> num_instances*old_obj -> inst_buffer_size, old_obj -> instances);
531 }
532 new_obj -> texture = old_obj -> texture;
533 int i;
534 for (i=0; i<5; i++) new_obj -> shift[i] = old_obj -> shift[i];
535 return new_obj;
536}
537
556glsl_program * init_shader_program (int object, int object_id,
557 const GLchar * vertex, const GLchar * geometry, const GLchar * fragment,
558 GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d * obj)
559{
560 glsl_program * glsl = g_malloc0 (sizeof * glsl);
561
562 glsl -> id = glCreateProgram ();
563 glsl -> object = object;
564 glsl -> draw_type = object_id;
565
566 glsl -> vertex_shader = create_shader (GL_VERTEX_SHADER, vertex);
567 glAttachShader (glsl -> id, glsl -> vertex_shader);
568 if (geometry != NULL)
569 {
570 glsl -> geometry_shader = create_shader (GL_GEOMETRY_SHADER, geometry);
571 glAttachShader (glsl -> id, glsl -> geometry_shader);
572 }
573 glsl -> fragment_shader = create_shader (GL_FRAGMENT_SHADER, fragment);
574 glAttachShader (glsl -> id, glsl -> fragment_shader);
575
576 glBindFragDataLocation (glsl -> id, 0, "fragment_color");
577 glLinkProgram(glsl -> id);
578
579 glsl -> vert_type = type_of_vertices;
580
581 glGenVertexArrays (1, & glsl -> vao);
582
583 glBindVertexArray (glsl -> vao);
584
585 glsl -> array_pointer = alloc_shader_pointer (glsl -> array_pointer, narray);
586 glsl -> uniform_loc = alloc_shader_pointer (glsl -> uniform_loc, nunif);
587
588 // For other than background always the MVP matrix as uniform 0
589 if (object_id != GLSL_BACK) glsl -> uniform_loc[0] = glGetUniformLocation (glsl -> id, "mvp");
590 // and always the vertices as array 0
591 glsl -> array_pointer[0] = glGetAttribLocation (glsl -> id, "vert");
592
593 glsl -> light_uniform = NULL;
594 if (lightning) glsl -> light_uniform = glsl_add_lights (glsl);
595
596 glsl -> obj = duplicate_object_3d (obj);
597
598 glsl -> draw_instanced = FALSE;
599
600 int nvbo = 1;
601 if (glsl -> obj -> num_indices > 0) nvbo ++;
602 if (glsl -> obj -> num_instances > 0)
603 {
604 nvbo ++;
605 if (glsl -> obj -> num_instances > 1) glsl -> draw_instanced = TRUE;
606 }
607
608 glsl -> vbo = allocgluint (nvbo);
609 glGenBuffers (nvbo, glsl -> vbo);
610
611 switch (object_id)
612 {
613 case GLSL_SPHERES:
614 // narray = 4
615 glsl_bind_spheres (glsl, glsl -> obj);
616 break;
617 case GLSL_POINTS:
618 // narray = 4
619 glsl_bind_points (glsl, glsl -> obj);
620 break;
621 case GLSL_LINES:
622 // narray = 3
623 glsl_bind_lines (glsl, glsl -> obj);
624 break;
625 case GLSL_CYLINDERS:
626 // narray = 6
627 glsl_bind_cylinders (glsl, glsl -> obj);
628 break;
629 case GLSL_CAPS:
630 // narray = 5
631 glsl_bind_caps (glsl, glsl -> obj);
632 break;
633 case GLSL_POLYEDRA:
634 glsl_bind_polyhedra (glsl, glsl -> obj);
635 break;
636 case GLSL_STRING:
637 glsl_bind_string (glsl, glsl -> obj);
638 break;
639 case GLSL_BACK:
640 glsl_bind_background (glsl, glsl -> obj);
641 break;
642 }
643 glDetachShader (glsl -> id,glsl -> vertex_shader);
644 if (geometry != NULL) glDetachShader (glsl -> id, glsl -> geometry_shader);
645 glDetachShader (glsl -> id, glsl -> fragment_shader);
646
647 return glsl;
648}
649
658gboolean in_md_shaders (project * this_proj, int id)
659{
660 if (id == ATOMS) return TRUE;
661 if (id == BONDS) return TRUE;
662 if (id == POLYS) return TRUE;
663 if (id == RINGS) return TRUE;
664 if (id == SELEC) return TRUE;
665 if (id == MDBOX) return this_proj -> cell.npt;
666 if (id == VOLMS) return TRUE;
667 return FALSE;
668}
669
678{
679 int i, j;
680 project * this_proj = get_project_by_id(view -> proj);
681 for (i=0; i<NGLOBAL_SHADERS; i++)
682 {
683 if (in_md_shaders (this_proj, i))
684 {
685 for (j=0; j< this_proj -> steps; j++) view -> n_shaders[i][j] = -1;
686 }
687 }
688}
689
699void re_create_md_shaders (int nshaders, int shaders[nshaders], project * this_proj)
700{
701 int i, j, k;
702 for (i=0; i<nshaders; i++)
703 {
704 k = shaders[i];
705 this_proj -> modelgl -> create_shaders[k] = TRUE;
706 for (j=0; j<this_proj -> steps; j++)
707 {
708 this_proj -> modelgl -> n_shaders[k][j] = -1;
709 }
710 }
711}
712
721void cleaning_shaders (glwin * view, int shader)
722{
723 int i = (in_md_shaders(get_project_by_id(view -> proj), shader)) ? step : 0;
724 if (view -> ogl_glsl[shader][i] != NULL)
725 {
726 g_free (view -> ogl_glsl[shader][i]);
727 view -> ogl_glsl[shader][i] = NULL;
728 }
729 view -> n_shaders[shader][i] = (in_md_shaders(get_project_by_id(view -> proj), shader)) ? -1 : 0;
730}
731
740{
741 int i;
742 for (i=0; i<NGLOBAL_SHADERS; i++)
743 {
744 view -> create_shaders[i] = TRUE;
745 }
746}
747
756{
757 int shaders[6] = {ATOMS, BONDS, SELEC, POLYS, RINGS, VOLMS};
759 view -> create_shaders[LABEL] = TRUE;
760 view -> create_shaders[PICKS] = TRUE;
761 view -> create_shaders[MEASU] = TRUE;
762 update (view);
763 int i;
764 if (is_atom_win_active(view) || (view -> mode == EDITION && (view -> anim -> last -> img -> selected[1] -> selected || view -> selection_mode == 5)))
765 {
766 if (view -> measure_win != NULL)
767 {
768 for (i=0; i<3; i++)
769 {
770 if (view -> measure_win -> selection_tree[i] != NULL) update_selection_tree (view, 1, i);
771 }
772 }
773 }
774}
775
783void init_shaders (glwin * view)
784{
785 int i, j;
786 project * this_proj = get_project_by_id (view -> proj);
787 for (i=0; i<NGLOBAL_SHADERS; i++)
788 {
789 view -> ogl_glsl[i] = NULL;
790 if (in_md_shaders (this_proj, i))
791 {
792 view -> ogl_glsl[i] = g_malloc0 (this_proj -> steps*sizeof*view -> ogl_glsl[i]);
793 view -> n_shaders[i] = allocint (this_proj -> steps);
794 for (j=0; j<this_proj -> steps; j++)
795 {
796 view -> n_shaders[i][j] = -1;
797 }
798 }
799 else
800 {
801 j = (i == MEASU) ? 2 : 1;
802 view -> ogl_glsl[i] = g_malloc0 (j*sizeof*view -> ogl_glsl[i]);
803 view -> ogl_glsl[i][0] = NULL;
804 view -> n_shaders[i] = allocint (j);
805 }
806 view -> create_shaders[i] = TRUE;
807 }
808}
809
818{
819 if (glsl -> draw_type == GLSL_POINTS)
820 {
821 return FALSE;
822 }
823 else if (glsl -> draw_type == GLSL_LINES)
824 {
825 return FALSE;
826 }
827 else if (glsl -> draw_type == GLSL_LIGHT)
828 {
829 return FALSE;
830 }
831 else
832 {
833 return TRUE;
834 }
835}
836
845{
846 int j, k;
847 vec3_t l_pos, l_dir;
848 k = (glsl -> draw_type == GLSL_LIGHT) ? 0 : plot -> m_terial.param[0];
849 glUniformMatrix4fv (glsl -> light_uniform[0], 1, GL_FALSE, & wingl -> model_view_matrix.m00);
850 glUniform1i (glsl -> light_uniform[1], k);
851 glUniform3f (glsl -> light_uniform[2], plot -> m_terial.albedo.x, plot -> m_terial.albedo.y, plot -> m_terial.albedo.z);
852 for (j=0; j<5; j++) glUniform1f (glsl -> light_uniform[3+j], plot -> m_terial.param[j+1]);
853 glUniform1i (glsl -> light_uniform[8], plot -> f_g.mode);
854 glUniform1i (glsl -> light_uniform[9], plot -> f_g.based);
855 glUniform1f (glsl -> light_uniform[10], plot -> f_g.density/plot -> p_depth);
856 glUniform2f (glsl -> light_uniform[11], plot -> f_g.depth[0]*plot -> p_depth/100.0 + plot -> p_depth, plot -> f_g.depth[1]*plot -> p_depth/100.0+ plot -> p_depth);
857 glUniform3f (glsl -> light_uniform[12], plot -> f_g.color.x, plot -> f_g.color.y, plot -> f_g.color.z);
858 glUniform1i (glsl -> light_uniform[13], plot -> l_ghtning.lights);
859 for (j=0; j<plot -> l_ghtning.lights; j++)
860 {
862 glUniform1i (glsl -> light_uniform[k], plot -> l_ghtning.spot[j].type);
863 if (plot -> l_ghtning.spot[j].fix == 0)
864 {
865 l_pos = m4_mul_pos (wingl -> model_matrix, plot -> l_ghtning.spot[j].position);
866 }
867 else
868 {
869 l_pos = m4_mul_pos (wingl -> model_view_matrix, plot -> l_ghtning.spot[j].position);
870 }
871 glUniform3f (glsl -> light_uniform[k+1], l_pos.x, l_pos.y, l_pos.z);
872 if (plot -> l_ghtning.spot[j].fix == 0)
873 {
874 l_dir = m4_mul_pos (wingl -> model_matrix, plot -> l_ghtning.spot[j].direction);
875 }
876 else
877 {
878 l_dir = m4_mul_pos (wingl -> model_view_matrix, plot -> l_ghtning.spot[j].direction);
879 }
880 glUniform3f (glsl -> light_uniform[k+2], l_dir.x, l_dir.y, l_dir.z);
881 glUniform3f (glsl -> light_uniform[k+3], plot -> l_ghtning.spot[j].intensity.x, plot -> l_ghtning.spot[j].intensity.y, plot -> l_ghtning.spot[j].intensity.z);
882 glUniform1f (glsl -> light_uniform[k+4], plot -> l_ghtning.spot[j].attenuation.x);
883 glUniform1f (glsl -> light_uniform[k+5], plot -> l_ghtning.spot[j].attenuation.y);
884 glUniform1f (glsl -> light_uniform[k+6], plot -> l_ghtning.spot[j].attenuation.z);
885 glUniform1f (glsl -> light_uniform[k+7], cos(plot -> l_ghtning.spot[j].spot_data.x*pi/180.0));
886 glUniform1f (glsl -> light_uniform[k+8], cos(plot -> l_ghtning.spot[j].spot_data.y*pi/180.0));
887 glUniform1f (glsl -> light_uniform[k+9], cos(plot -> l_ghtning.spot[j].spot_data.z*pi/180.0));
888 }
889}
890
891uint16_t stipple_pattern[NDOTS]={ 0xAAAA, 0x1111, 0x0000, 0x55FF, 0x24FF, 0x3F3F, 0x33FF, 0x27FF};
895
904{
905 wingl -> label_projection_matrix = create_label_matrices ();
906 glUniformMatrix4fv (glsl -> uniform_loc[2], 1, GL_FALSE, & wingl -> label_projection_matrix.m00);
907 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, & wingl -> un_view_matrix.m00);
908 glUniform4f (glsl -> uniform_loc[4], wingl -> view_port.w, wingl -> view_port.x, wingl -> view_port.y, wingl -> view_port.z);
909 glUniform4f (glsl -> uniform_loc[5], glsl -> obj -> shift[0], glsl -> obj -> shift[1],
910 glsl -> obj -> shift[2], glsl -> obj -> shift[3]);
911 glUniform4f (glsl -> uniform_loc[6], glsl -> col -> red, glsl -> col -> green,
912 glsl -> col -> blue, glsl -> col -> alpha);
913 if (glsl -> object == MEASU) glUniform1i (glsl -> uniform_loc[7], this_tilt);
914}
915
924void render_this_shader (glsl_program * glsl, int ids)
925{
926 int j, k;
927 if (glsl -> object == MAXIS)
928 {
929 j = 0;
931 {
932 k = wingl -> atom_win -> active;
933 if (wingl -> atom_win -> show_axis[k])
934 {
935 j = wingl -> atom_win -> axis[k];
936 }
937 }
938 wingl -> axis_proj_model_view_matrix = create_axis_matrices (j);
939 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> axis_proj_model_view_matrix.m00);
940 j = (plot -> xyz -> axis == WIREFRAME) ? 1 : 3;
941 if (ids > j) shading_glsl_text (glsl);
942 }
943 else if (glsl -> object == LABEL)
944 {
945 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
946 shading_glsl_text (glsl);
947 }
948 else if (glsl -> object == BACKG)
949 {
950 for (j=0; j<2; j++)
951 {
952 glUniform4f (glsl -> uniform_loc[j], plot -> back -> gradient_color[j].red,
953 plot -> back -> gradient_color[j].green,
954 plot -> back -> gradient_color[j].blue,
955 plot -> back -> gradient_color[j].alpha);
956 }
957 glUniform1i (glsl -> uniform_loc[2], plot -> back -> direction);
958 glUniform1f (glsl -> uniform_loc[3], plot -> back -> position);
959 }
960 else if (glsl -> object == MEASU)
961 {
962 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
963 if (glsl -> vert_type == GL_TRIANGLE_STRIP)
964 {
965 shading_glsl_text (glsl);
966 }
967 else
968 {
969 glUniform1i (glsl -> uniform_loc[1], this_factor);
970 glUniform1ui (glsl -> uniform_loc[2], stipple_pattern[this_pattern]);
971 if (glsl -> vert_type == GL_TRIANGLES)
972 {
973 wingl -> label_projection_matrix = create_label_matrices ();
974 glUniformMatrix4fv (glsl -> uniform_loc[3], 1, GL_FALSE, & wingl -> label_projection_matrix.m00);
975 }
976 glUniformMatrix4fv (glsl -> uniform_loc[4], 1, GL_FALSE, & wingl -> un_view_matrix.m00);
977 glUniform4f (glsl -> uniform_loc[5], wingl -> view_port.w, wingl -> view_port.x, wingl -> view_port.y, wingl -> view_port.z);
978 if (plot -> rep == PERSPECTIVE)
979 {
980 glUniform1f (glsl -> uniform_loc[6], 1.0);
981 }
982 else
983 {
984 glUniform1f (glsl -> uniform_loc[6], plot -> p_depth);
985 }
986 }
987 }
988 else if (glsl -> object == LIGHT)
989 {
990 if (plot -> light_loc[ids])
991 {
992 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_matrix.m00);
993 }
994 else
995 {
996 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
997 }
998 }
999 else
1000 {
1001 glUniformMatrix4fv (glsl -> uniform_loc[0], 1, GL_FALSE, & wingl -> proj_model_view_matrix.m00);
1002 }
1003
1004 if (glsl -> line_width != 0.0) glLineWidth (glsl -> line_width);
1005
1006 if (glsl -> light_uniform != NULL) set_lights_data (glsl);
1007
1008 glBindVertexArray (glsl -> vao);
1009
1010 if (glsl_disable_cull_face (glsl)) glDisable (GL_CULL_FACE);
1011 if (plot -> render == LINE)
1012 {
1013 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
1014 glLineWidth (1.0);
1015 }
1016 else if (plot -> render == PTS)
1017 {
1018 glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
1019 }
1020 else
1021 {
1022 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1023 }
1024
1025 if (glsl -> draw_type == GLSL_SPHERES || glsl -> draw_type == GLSL_CYLINDERS || glsl -> draw_type == GLSL_CAPS)
1026 {
1027 if (glsl -> draw_instanced)
1028 {
1029 glDrawElementsInstanced (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0, glsl -> obj -> num_instances);
1030 }
1031 else
1032 {
1033 glDrawElements (glsl -> vert_type, glsl -> obj -> num_indices, GL_UNSIGNED_INT, 0);
1034 }
1035 }
1036 else if (glsl -> draw_type == GLSL_POINTS || glsl -> draw_type == GLSL_LINES || glsl -> draw_type == GLSL_STRING)
1037 {
1038 if (glsl -> draw_type == GLSL_STRING)
1039 {
1040 glEnable (ogl_texture);
1041 glActiveTexture (GL_TEXTURE0);
1042 glBindTexture (ogl_texture, glsl -> obj -> texture);
1043 }
1044 if (glsl -> draw_instanced)
1045 {
1046 j = (glsl -> draw_type == GLSL_STRING) ? 4 : 3*(glsl -> draw_type+1);
1047 glDrawArraysInstanced (glsl -> vert_type, 0, j, glsl -> obj -> num_instances);
1048 }
1049 else
1050 {
1051 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1052 }
1053 }
1054 else
1055 {
1056 if (glsl -> draw_type == GLSL_BACK) glDisable (GL_DEPTH_TEST);
1057 glDrawArrays (glsl -> vert_type, 0, glsl -> obj -> num_vertices);
1058 if (glsl -> draw_type == GLSL_BACK) glEnable (GL_DEPTH_TEST);
1059 }
1060 if (glsl_disable_cull_face (glsl)) glEnable (GL_CULL_FACE);
1061 glBindVertexArray (0);
1062}
1063
1071void draw_vertices (int id)
1072{
1073 int i, j;
1074 glsl_program * glsl;
1075 if (id != MEASU)
1076 {
1077 i = (in_md_shaders(proj_gl, id)) ? step : 0;
1078 for (j=0; j<wingl -> n_shaders[id][i]; j++)
1079 {
1080 if (wingl -> ogl_glsl[id][i][j])
1081 {
1082 glsl = wingl -> ogl_glsl[id][i][j];
1083 glUseProgram (glsl -> id);
1084 render_this_shader (glsl, j);
1085 }
1086 }
1087 }
1088 else
1089 {
1090 for (i=0; i<2; i++)
1091 {
1092 this_pattern = plot -> mpattern[i];
1093 this_tilt = plot -> mtilt[i];
1094 this_factor = plot -> mfactor[i];
1095 for (j=0; j<wingl -> n_shaders[id][i]; j++)
1096 {
1097 if (wingl -> ogl_glsl[id][i][j])
1098 {
1099 glsl = wingl -> ogl_glsl[id][i][j];
1100 glUseProgram (glsl -> id);
1101 render_this_shader (glsl, j);
1102 }
1103 }
1104 }
1105 }
1106}
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:2227
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:560
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:592
double pi
Definition global.c:195
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
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
#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:450
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:70
project * proj_gl
Definition ogl_draw.c:64
glwin * wingl
Definition ogl_draw.c:63
@ 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:74
void update_selection_tree(glwin *view, int pi, int id)
update measurements tree view
Definition w_measures.c:381
@ 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
void draw_vertices(int id)
Draw OpenGL shader program.
#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:86
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...
@ 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:333
Definition glwin.h:965
float y
Definition math_3d.h:130
float x
Definition math_3d.h:130
float z
Definition math_3d.h:130
GtkWidget * show_axis
Definition tab-4.c:97
int status
Definition w_advance.c:178
GtkWidget * img
Definition workspace.c:70