2024-10-19 16:05:49 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* graphics header
|
|
|
|
*
|
|
|
|
* This file is part of Gem-graph.
|
|
|
|
*
|
|
|
|
* @cond LICENSE
|
|
|
|
* Copyright © 2021 Libre en Communs <contact@a-lec.org>
|
|
|
|
* Copyright © 2021-2024 Adrien Bourmault <neox@a-lec.org>
|
|
|
|
* Copyright © 2021-2024 Jean Sirmai <jean@a-lec.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* @endcond
|
|
|
|
*/
|
2024-06-30 17:18:18 +02:00
|
|
|
|
2024-04-22 18:40:30 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "base.h"
|
|
|
|
#include <epoxy/gl.h>
|
|
|
|
#include <GL/glu.h>
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
#define VERTEX_SHADER_FILE "src/shader.vert" /**< phantom documentation */
|
|
|
|
#define FRAG_SHADER_FILE "src/shader.frag" /**< phantom documentation */
|
|
|
|
#define GL_TARGET_MAJOR_VERSION 0 /**< phantom documentation */
|
|
|
|
#define GL_TARGET_MINOR_VERSION 4 /**< phantom documentation */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-06-30 12:47:34 +02:00
|
|
|
|
2024-07-08 22:11:10 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* G L A R E A */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
/**
|
2024-04-22 18:40:30 +02:00
|
|
|
* Structure describing a gl_area and its parameters, used to create a table
|
|
|
|
* of Gem-graph client current gl_areas
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
struct graphics_stack_t {
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
int id; /**< phantom documentation */
|
|
|
|
int mode; /**< phantom documentation */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
float rotation_angles[N_AXIS]; /**< Rotation angles on each axis */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
GLuint vao; /**< init_buffers */
|
|
|
|
GLuint position_buffer; /**< shutdown, draw */
|
|
|
|
GLuint color_buffer; /**< shutdown, draw */
|
2024-10-20 01:05:12 +02:00
|
|
|
GLuint program; /**< shutdown, init_shaders, draw */
|
2024-10-14 15:52:00 +02:00
|
|
|
GLuint m; /**< init_shaders, draw */
|
|
|
|
GLuint v; /**< init_shaders, draw */
|
|
|
|
GLuint p; /**< init_shaders, draw */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
struct arrow_t *arrows_ptr; /**< phantom documentation */
|
|
|
|
long arrows_nb; /**< phantom documentation */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
GLfloat *buffer_vertex_origin; /**< phantom documentation */
|
|
|
|
GLfloat *buffer_colors_origin; /**< phantom documentation */
|
|
|
|
GLuint *buffer_lines_origin; /**< phantom documentation */
|
|
|
|
GLuint *buffer_plans_origin; /**< phantom documentation */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
long buffer_vertex_size; /**< phantom documentation */
|
|
|
|
long buffer_colors_size; /**< phantom documentation */
|
|
|
|
long buffer_lines_size; /**< phantom documentation */
|
|
|
|
long buffer_plans_size; /**< phantom documentation */
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
long buffer_vertex_0_arrow; /**< phantom documentation */
|
|
|
|
long buffer_colors_0_arrow; /**< phantom documentation */
|
|
|
|
long buffer_lines_0_arrow; /**< phantom documentation */
|
|
|
|
long buffer_plans_0_arrow; /**< phantom documentation */
|
2024-04-22 18:40:30 +02:00
|
|
|
};
|
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
/**
|
2024-04-22 18:40:30 +02:00
|
|
|
* Dynamic array of ptrs to dynamically allocated gl_area_entry
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
extern struct graphics_stack_t *graphics_stack;
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-22 23:58:04 +02:00
|
|
|
//bool graphics_render_stack(GtkWidget *container_widget);
|
|
|
|
//bool graphics_setup_glarea(int target_mode, GtkWidget *target_widget);
|
2024-07-18 23:51:04 +02:00
|
|
|
int graphics_init(void *error_buffer);
|
|
|
|
void graphics_draw(const int graphics_stack_id);
|
2024-10-22 23:58:04 +02:00
|
|
|
bool graphics_shutdown(const int id, void *error_buffer);
|
2024-07-18 23:51:04 +02:00
|
|
|
bool graphics_init_shaders(const int graphics_stack_id);
|
2024-10-22 23:58:04 +02:00
|
|
|
//bool graphics_init_graphics_stack(void *container_widget, GError *error_buffer);
|
|
|
|
//bool graphics_shutdown_graphics_stack(void *container_widget, GError *error_buffer);
|
|
|
|
//bool graphics_update_axis_stack(GtkWidget *container_widget, int axis, int value);
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_init_buffers(const int graphics_stack_id);
|
|
|
|
void graphics_draw_vertex (const int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
GLfloat x,
|
|
|
|
GLfloat y,
|
|
|
|
GLfloat z);
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/*
|
2024-04-22 18:40:30 +02:00
|
|
|
* Draws the color (r, g, b) associated to a vertex
|
|
|
|
* if (console) prints (r, g, b) values to console
|
|
|
|
*
|
|
|
|
* @param GLfloat r, GLfloat g, GLfloat b
|
|
|
|
*
|
|
|
|
*/
|
2024-10-22 23:58:04 +02:00
|
|
|
|
2024-10-01 11:21:28 +02:00
|
|
|
//void graphics_draw_color (const int graphics_stack_id, GLfloat r, GLfloat g, GLfloat b);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_draw_line (const int graphics_stack_id, GLuint a, GLuint b);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_draw_plan (const int graphics_stack_id, GLuint a, GLuint b, GLuint c);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
/**
|
2024-04-22 18:40:30 +02:00
|
|
|
* Created and compile a shader
|
|
|
|
*
|
2024-10-20 01:05:12 +02:00
|
|
|
* @param graphics_stack_id,
|
|
|
|
* @param shader type
|
|
|
|
* @param src (source code of shader)
|
2024-04-22 18:40:30 +02:00
|
|
|
*
|
|
|
|
* @return shader id
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
static inline GLuint graphics_create_shader(const int graphics_stack_id, int type, const char *src)
|
2024-04-22 18:40:30 +02:00
|
|
|
{
|
|
|
|
GLuint shader;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
shader = glCreateShader(type);
|
|
|
|
glShaderSource(shader, 1, &src, NULL);
|
|
|
|
glCompileShader(shader);
|
|
|
|
|
|
|
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
|
|
|
if(status == GL_FALSE) {
|
|
|
|
int log_len;
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
|
|
|
|
|
|
|
|
buffer = g_malloc(log_len + 1);
|
|
|
|
assert (buffer);
|
|
|
|
glGetShaderInfoLog(shader, log_len, NULL, buffer);
|
|
|
|
|
|
|
|
g_warning("Compile failure in %s shader:\n%s",
|
|
|
|
type == GL_VERTEX_SHADER ? "vertex" : "fragment",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
g_free(buffer);
|
|
|
|
|
|
|
|
glDeleteShader(shader);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
static inline void graphics_print_stack(int graphics_stack_id)
|
2024-04-22 18:40:30 +02:00
|
|
|
{
|
|
|
|
static int n = 0;
|
|
|
|
|
|
|
|
printf("\n[n=%d]***************", n);
|
|
|
|
|
|
|
|
printf("id = %d\tmode = %d\n",
|
2024-07-18 23:51:04 +02:00
|
|
|
graphics_stack[graphics_stack_id].id,
|
|
|
|
graphics_stack[graphics_stack_id].mode);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
|
|
|
printf("rotation_angles = ");
|
|
|
|
for (int i = 0; i < N_AXIS; i++) {
|
2024-07-18 23:51:04 +02:00
|
|
|
printf("%f\t", graphics_stack[graphics_stack_id].rotation_angles[i]);
|
|
|
|
// Rotation angles on each axis
|
2024-04-22 18:40:30 +02:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
printf("vao = %d\n", graphics_stack[graphics_stack_id].vao);
|
|
|
|
printf("position_buffer = %d\n", graphics_stack[graphics_stack_id].position_buffer);
|
|
|
|
printf("color_buffer = %d\n", graphics_stack[graphics_stack_id].color_buffer);
|
|
|
|
printf("program = %d\n", graphics_stack[graphics_stack_id].program);
|
|
|
|
printf("m = %d\n", graphics_stack[graphics_stack_id].m);
|
|
|
|
printf("v = %d\n", graphics_stack[graphics_stack_id].v);
|
|
|
|
printf("p = %d\n", graphics_stack[graphics_stack_id].p);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
printf("arrows_ptr = %p\n", graphics_stack[graphics_stack_id].arrows_ptr);
|
|
|
|
printf("arrows_nb = %ld\n", graphics_stack[graphics_stack_id].arrows_nb);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
printf("buffer_vertex_origin = %p\n", graphics_stack[graphics_stack_id].buffer_vertex_origin);
|
|
|
|
printf("buffer_colors_origin = %p\n", graphics_stack[graphics_stack_id].buffer_colors_origin);
|
|
|
|
printf("buffer_lines_origin = %p\n", graphics_stack[graphics_stack_id].buffer_lines_origin);
|
|
|
|
printf("buffer_plans_origin = %p\n", graphics_stack[graphics_stack_id].buffer_plans_origin);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
printf("buffer_vertex_size = %ld\n", graphics_stack[graphics_stack_id].buffer_vertex_size);
|
|
|
|
printf("buffer_colors_size = %ld\n", graphics_stack[graphics_stack_id].buffer_colors_size);
|
|
|
|
printf("buffer_lines_size = %ld\n", graphics_stack[graphics_stack_id].buffer_lines_size);
|
|
|
|
printf("buffer_plans_size = %ld\n", graphics_stack[graphics_stack_id].buffer_plans_size);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
printf("buffer_vertex_0_arrow = %ld\n", graphics_stack[graphics_stack_id].buffer_vertex_0_arrow);
|
|
|
|
printf("buffer_colors_0_arrow = %ld\n", graphics_stack[graphics_stack_id].buffer_colors_0_arrow);
|
|
|
|
printf("buffer_lines_0_arrow = %ld\n", graphics_stack[graphics_stack_id].buffer_lines_0_arrow);
|
|
|
|
printf("buffer_plans_0_arrow = %ld\n", graphics_stack[graphics_stack_id].buffer_plans_0_arrow);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
|
|
|
printf("********************\n");
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
/**
|
2024-06-30 12:47:34 +02:00
|
|
|
* Initializes a gl_area
|
|
|
|
*
|
2024-10-20 01:05:12 +02:00
|
|
|
* @param *error_buffer gl_area, ptr to the gl_area widget
|
2024-06-30 12:47:34 +02:00
|
|
|
*
|
|
|
|
* @return true if initialized
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
int graphics_init(void *error_buffer);
|
2024-06-30 12:47:34 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_draw_vertex (const int graphics_stack_id,
|
2024-06-30 12:47:34 +02:00
|
|
|
GLfloat x,
|
|
|
|
GLfloat y,
|
|
|
|
GLfloat z);
|
|
|
|
|
2024-10-22 23:58:04 +02:00
|
|
|
void graphics_draw_color (const int graphics_stack_id,
|
|
|
|
GLfloat r,
|
|
|
|
GLfloat g,
|
|
|
|
GLfloat b);
|
2024-06-30 12:47:34 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_draw_line (const int graphics_stack_id, GLuint a, GLuint b);
|
2024-06-30 12:47:34 +02:00
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
/**
|
2024-06-30 12:47:34 +02:00
|
|
|
* Writes values to describe an (a,b,c) plan (triangle) into the plan buffer
|
|
|
|
*
|
2024-10-20 01:05:12 +02:00
|
|
|
* @param graphics_stack_id
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @param c
|
2024-06-30 12:47:34 +02:00
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_draw_plan (const int graphics_stack_id, GLuint a, GLuint b, GLuint c);
|
2024-06-30 12:47:34 +02:00
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
|
|
|
* graphics_model_setup
|
|
|
|
*
|
|
|
|
* @param graphics_stack_id
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
void graphics_model_setup (const int graphics_stack_id);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
|
|
|
* Draws one arrow vertex (x, y, z)
|
|
|
|
* if (console) prints (x, y, z) values to console
|
|
|
|
*
|
|
|
|
* @param graphics_stack_id
|
|
|
|
* @param space_X
|
|
|
|
* @param space_Y
|
|
|
|
* @param space_Z
|
|
|
|
* @param weight
|
|
|
|
* @param site
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
|
|
|
*
|
|
|
|
* @returns i
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
int graphics_draw_one_arrow_vertex (const int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
int space_X,
|
|
|
|
int space_Y,
|
|
|
|
int space_Z,
|
|
|
|
int weight,
|
|
|
|
int site,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int z);
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
|
|
|
* Draws one arrow vertex (x, y, z)
|
|
|
|
* if (console) prints (x, y, z) values to console
|
|
|
|
*
|
|
|
|
* @param graphics_stack_id
|
|
|
|
* @param offset_vertex
|
|
|
|
*
|
|
|
|
* @returns i
|
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
int graphics_draw_one_arrow_line(const int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
int offset_vertex);
|
|
|
|
|
2024-10-14 15:52:00 +02:00
|
|
|
/**
|
2024-04-22 18:40:30 +02:00
|
|
|
* Writes grid ridges to vertex and color buffers
|
|
|
|
*
|
2024-10-20 01:05:12 +02:00
|
|
|
* @param graphics_stack_id
|
|
|
|
* @param offset_vertex
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2024-04-22 18:40:30 +02:00
|
|
|
*
|
2024-10-20 01:05:12 +02:00
|
|
|
* @returns i
|
2024-04-22 18:40:30 +02:00
|
|
|
*/
|
2024-07-18 23:51:04 +02:00
|
|
|
int graphics_draw_space_ridges_vertex (const int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
long offset_vertex,
|
|
|
|
long x,
|
|
|
|
long y,
|
|
|
|
long z);
|
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
int graphics_draw_space_ridges_lines (const int graphics_stack_id);
|
2024-04-22 18:40:30 +02:00
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
long graphics_draw_grids_on_space_faces_vertex (const int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
long x,
|
|
|
|
long y,
|
|
|
|
long z);
|
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
long graphics_draw_grids_on_space_faces_lines (const int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
long offset_vertex,
|
|
|
|
long x,
|
|
|
|
long y,
|
|
|
|
long z);
|
|
|
|
|
2024-10-23 00:06:21 +02:00
|
|
|
/** phantom documentation
|
|
|
|
*
|
|
|
|
* @param graphics_stack_id
|
|
|
|
* @param arrows_nb
|
|
|
|
* @param space_X
|
|
|
|
* @param space_Y
|
|
|
|
* @param space_Z
|
|
|
|
* @param requested_weight
|
|
|
|
* @param site
|
|
|
|
* @param arrow_x
|
|
|
|
* @param arrow_y
|
|
|
|
* @param arrow_z
|
|
|
|
*/
|
2024-10-22 23:58:04 +02:00
|
|
|
int graphics_set_arrow (
|
|
|
|
int graphics_stack_id,
|
2024-04-22 18:40:30 +02:00
|
|
|
int arrows_nb,
|
|
|
|
int space_X,
|
|
|
|
int space_Y,
|
|
|
|
int space_Z,
|
|
|
|
int requested_weight,
|
|
|
|
int site,
|
|
|
|
int arrow_x,
|
|
|
|
int arrow_y,
|
2024-10-22 23:58:04 +02:00
|
|
|
int arrow_z
|
|
|
|
);
|
2024-10-23 00:06:21 +02:00
|
|
|
|