Compare commits
6 Commits
933120ed85
...
dev
Author | SHA1 | Date | |
---|---|---|---|
5c464f6fbb | |||
0ec3e39284 | |||
4bf745dbf3 | |||
86a07a035a | |||
163b45b010 | |||
f9f6375529 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "shimatta-opengl"]
|
||||
path = shimatta-opengl
|
||||
url = ssh://git@git.shimatta.de/mhu/shimatta-opengl.git
|
@@ -9,9 +9,26 @@ pkg_check_modules(EPOXY REQUIRED epoxy)
|
||||
add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
|
||||
aux_source_directory("src" SRC_DIR)
|
||||
|
||||
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message("${Yellow}Debug mode for shader locations used!${ColorReset}")
|
||||
add_definitions(-DSHADER_DIRECTORY=\"${CMAKE_CURRENT_BINARY_DIR}/shaders\")
|
||||
message("${BoldMagenta}${CMAKE_CURRENT_BINARY_DIR}/shaders used as shader directory${ColorReset}")
|
||||
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message("Global shader directory used. Make sure files in /usr/share/gtk-graph-view/shaders are available")
|
||||
add_definitions(-DSHADER_DIRECTORY=\"/usr/share/gtk-graph-view/shaders\")
|
||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${SRC_DIR})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${EPOXY_LDFLAGS} shimatta-opengl)
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${EPOXY_LINK_DIRS})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS})
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/shaders/passthrough3d.vertex.glsl"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/shaders/passthrough3d.vertex.glsl" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/shaders/monochrome.fragment.glsl"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/shaders/monochrome.fragment.glsl" COPYONLY)
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of GtkGraphView.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* GtkGraphView is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
|
10
lib/shaders/monochrome.fragment.glsl
Normal file
10
lib/shaders/monochrome.fragment.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragmentColor = vec4(color.r, color.g, color.b, 1.0);
|
||||
}
|
8
lib/shaders/passthrough2d.vertex.glsl
Normal file
8
lib/shaders/passthrough2d.vertex.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec2 inputVertex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(inputVertex.x, inputVertex.y, 0.0, 1.0);
|
||||
}
|
8
lib/shaders/passthrough3d.vertex.glsl
Normal file
8
lib/shaders/passthrough3d.vertex.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 inputVertex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(inputVertex.x, inputVertex.y, inputVertex.z, 1.0);
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of GtkGraphView.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* GtkGraphView is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
@@ -17,6 +17,11 @@
|
||||
#include <gtk-graph-view.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <shimatta-opengl-program.h>
|
||||
#include <shimatta-opengl-colored-triangle.h>
|
||||
|
||||
#ifndef SHADER_DIRECTORY
|
||||
#define SHADER_DIRECTORY "/usr/share/gtk-graph-view/shaders"
|
||||
#endif
|
||||
|
||||
struct _GtkGraphView {
|
||||
GtkBox super;
|
||||
@@ -29,6 +34,9 @@ typedef struct {
|
||||
*/
|
||||
GtkWidget *gl_area;
|
||||
GdkRGBA background_color;
|
||||
ShimattaOpenglProgram *passthrough_prog;
|
||||
ShimattaOpenglGraphics *test;
|
||||
|
||||
} GtkGraphViewPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GtkGraphView, gtk_graph_view, GTK_TYPE_BOX)
|
||||
@@ -59,6 +67,9 @@ static gboolean gl_render(GtkGLArea *gl_area, GdkGLContext *context, GtkGraphVie
|
||||
|
||||
gl_area_set_clear_color(gl_area, &priv->background_color);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
shimatta_opengl_graphics_draw(priv->test);
|
||||
|
||||
glFlush();
|
||||
|
||||
return TRUE;
|
||||
@@ -91,6 +102,14 @@ static void gtk_graph_view_set_property(GObject *obj, guint property_id, const G
|
||||
}
|
||||
}
|
||||
|
||||
void gtk_graph_view_dispose(GObject *obj)
|
||||
{
|
||||
GtkGraphView *graph_view = GTK_GRAPH_VIEW(obj);
|
||||
GtkGraphViewPrivate *priv = gtk_graph_view_get_instance_private(graph_view);
|
||||
|
||||
G_OBJECT_CLASS(gtk_graph_view_parent_class)->dispose(obj);
|
||||
}
|
||||
|
||||
static GParamSpec *gtk_graph_view_properties[N_PROPERTIES] = {NULL};
|
||||
|
||||
/**
|
||||
@@ -104,6 +123,7 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *klass)
|
||||
oclass = G_OBJECT_CLASS(klass);
|
||||
oclass->set_property = gtk_graph_view_set_property;
|
||||
oclass->get_property = gtk_graph_view_get_property;
|
||||
oclass->dispose = gtk_graph_view_dispose;
|
||||
|
||||
gtk_graph_view_properties[PROP_BG_COLOR] =
|
||||
g_param_spec_boxed("background-color", "background color", "Background color of Graph View",
|
||||
@@ -112,11 +132,48 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *klass)
|
||||
g_object_class_install_properties(oclass, N_PROPERTIES, gtk_graph_view_properties);
|
||||
}
|
||||
|
||||
static void gl_area_realize(GtkGLArea *area, gpointer data)
|
||||
static void gl_area_realize(GtkGLArea *area, GtkGraphView *graph_view)
|
||||
{
|
||||
(void)data;
|
||||
gtk_gl_area_make_current(area);
|
||||
GtkGraphViewPrivate *priv;
|
||||
char error_text[512];
|
||||
int status;
|
||||
const vec3 color = {1.0f, 0.0f, 0.0f};
|
||||
const vec3 vertecies[3] = {
|
||||
{-0.5f, 0.0f, 0.0f},
|
||||
{0.5f, 0.0f, 0.0f},
|
||||
{0.0, 0.5f, 0.0f},
|
||||
};
|
||||
|
||||
gtk_gl_area_make_current(area);
|
||||
priv = gtk_graph_view_get_instance_private(graph_view);
|
||||
|
||||
priv->passthrough_prog = shimatta_opengl_program_new_from_file(SHADER_DIRECTORY"/passthrough3d.vertex.glsl",
|
||||
NULL,
|
||||
SHADER_DIRECTORY"/monochrome.fragment.glsl");
|
||||
status = shimatta_opengl_program_compile(priv->passthrough_prog, error_text, sizeof(error_text));
|
||||
if (status) {
|
||||
g_warning("Error compiling shader: %s", error_text);
|
||||
}
|
||||
|
||||
priv->test = shimatta_opengl_colored_triangle_new(priv->passthrough_prog, color, vertecies);
|
||||
shimatta_opengl_graphics_realize(priv->test);
|
||||
}
|
||||
|
||||
static void gl_area_unrealize(GtkGLArea *area, GtkGraphView *graph_view)
|
||||
{
|
||||
GtkGraphViewPrivate *priv;
|
||||
|
||||
gtk_gl_area_make_current(area);
|
||||
priv = gtk_graph_view_get_instance_private(graph_view);
|
||||
|
||||
g_clear_object(&priv->passthrough_prog);
|
||||
}
|
||||
|
||||
static void gl_area_resize(GtkGLArea *area, GtkGraphView *graph_view)
|
||||
{
|
||||
(void)graph_view;
|
||||
|
||||
gtk_gl_area_queue_render(area);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +190,8 @@ static void gtk_graph_view_init(GtkGraphView *obj)
|
||||
priv->gl_area = gtk_gl_area_new();
|
||||
g_signal_connect(priv->gl_area, "render", G_CALLBACK(gl_render), obj);
|
||||
g_signal_connect(priv->gl_area, "realize", G_CALLBACK(gl_area_realize), obj);
|
||||
g_signal_connect(priv->gl_area, "unrealize", G_CALLBACK(gl_area_unrealize), obj);
|
||||
g_signal_connect(priv->gl_area, "resize", G_CALLBACK(gl_area_resize), obj);
|
||||
gtk_container_add(GTK_CONTAINER(obj), priv->gl_area);
|
||||
gtk_box_set_child_packing(GTK_BOX(obj), priv->gl_area, TRUE, TRUE, 0, GTK_PACK_START);
|
||||
gtk_widget_show(priv->gl_area);
|
||||
|
1
shimatta-opengl
Submodule
1
shimatta-opengl
Submodule
Submodule shimatta-opengl added at 97ac18d3d2
@@ -1,17 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(shimatta-opengl LANGUAGES C)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(GLIB REQUIRED glib-2.0)
|
||||
pkg_check_modules(EPOXY REQUIRED epoxy)
|
||||
|
||||
add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
|
||||
aux_source_directory("src" SRC_DIR)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${SRC_DIR})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${EPOXY_LDFLAGS})
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${GLIB_LINK_DIRS} ${EPOXY_LINK_DIRS})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB_INCLUDE_DIRS})
|
||||
|
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* This file is part of Shimatta OpenGL.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Shimatta OpenGL 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GtkGraphView. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SHIMATTA_TYPE_OPENGL_PROGRAM (shimatta_opengl_program_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE(ShimattaOpenglProgram, shimatta_opengl_program, SHIMATTA, OPENGL_PROGRAM, GObject);
|
||||
|
||||
/**
|
||||
* @brief generate a new shader program using the source code for the shaders
|
||||
* @param vertex_shader Vertex shader source code
|
||||
* @param geometry_shader Geometry shader source code
|
||||
* @param fragment_shader Fragement shader source code
|
||||
* @return New shader program
|
||||
*/
|
||||
ShimattaOpenglProgram *shimatta_opengl_program_new_from_data(const char *vertex_shader,
|
||||
const char *geometry_shader,
|
||||
const char *fragment_shader);
|
||||
|
||||
/**
|
||||
* @brief shimatta_opengl_program_new_from_file
|
||||
* @param vertex_shader Source file for the vertex shader
|
||||
* @param geometry_shader Source file for the geometry shader
|
||||
* @param fragment_shader source file for the fragment shader
|
||||
* @return New shader program
|
||||
* @note The files have tobe accessible when calling @ref shimatta_opengl_program_compile
|
||||
*/
|
||||
ShimattaOpenglProgram *shimatta_opengl_program_new_from_file(const char *vertex_shader,
|
||||
const char *geometry_shader,
|
||||
const char *fragment_shader);
|
||||
|
||||
/**
|
||||
* @brief Compile the OpenGL Program
|
||||
* @param program Shader Program
|
||||
* @param error_text Error message from compilation. May be NULL.
|
||||
* @param error_text_size Size in bytes of the error_text buffer. May be 0.
|
||||
* @return 0 if successful. If Error error text will hold the error. 1 is returned if program is already compiled
|
||||
*/
|
||||
int shimatta_opengl_program_compile(ShimattaOpenglProgram *program, char *error_text, size_t error_text_size);
|
||||
|
||||
/**
|
||||
* @brief Active shader program.
|
||||
*
|
||||
* The activation only works, if the program is compiled successfully
|
||||
*
|
||||
* @param program Shader program
|
||||
* @return 0 if successful
|
||||
*/
|
||||
int shimatta_opengl_program_use(ShimattaOpenglProgram *program);
|
||||
|
||||
/**
|
||||
* @brief Check if shader program is compiled
|
||||
* @param program Shader program
|
||||
* @return true if successfully built
|
||||
*/
|
||||
gboolean shimatta_opengl_program_is_compiled(ShimattaOpenglProgram *program);
|
||||
|
||||
G_END_DECLS
|
@@ -1,311 +0,0 @@
|
||||
/*
|
||||
* This file is part of Shimatta OpenGL.
|
||||
*
|
||||
* Foobar is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Shimatta OpenGL 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GtkGraphView. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <shimatta-opengl-program.h>
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
struct _ShimattaOpenglProgram {
|
||||
GObject super;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GLuint shader_id;
|
||||
gboolean compiled;
|
||||
char *fragment_file;
|
||||
char *vertex_file;
|
||||
char *geometry_file;
|
||||
char *fragment_src;
|
||||
char *vertex_src;
|
||||
char *geometry_src;
|
||||
|
||||
} ShimattaOpenglProgramPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ShimattaOpenglProgram, shimatta_opengl_program, G_TYPE_OBJECT);
|
||||
|
||||
static void shimatta_opengl_program_dispose(GObject *self)
|
||||
{
|
||||
ShimattaOpenglProgram *prog;
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
|
||||
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(self));
|
||||
|
||||
prog = SHIMATTA_OPENGL_PROGRAM(self);
|
||||
priv = shimatta_opengl_program_get_instance_private(prog);
|
||||
if (priv->compiled) {
|
||||
priv->compiled = false;
|
||||
glDeleteProgram(priv->shader_id);
|
||||
}
|
||||
|
||||
if (priv->fragment_src)
|
||||
g_free(priv->fragment_src);
|
||||
if (priv->geometry_src)
|
||||
g_free(priv->geometry_src);
|
||||
if (priv->vertex_src)
|
||||
g_free(priv->vertex_src);
|
||||
if (priv->vertex_file)
|
||||
g_free(priv->vertex_file);
|
||||
if (priv->fragment_file)
|
||||
g_free(priv->fragment_file);
|
||||
if (priv->geometry_file)
|
||||
g_free(priv->geometry_file);
|
||||
|
||||
}
|
||||
|
||||
static void shimatta_opengl_program_class_init(ShimattaOpenglProgramClass *klass)
|
||||
{
|
||||
(void)klass;
|
||||
GObjectClass *oclass;
|
||||
|
||||
oclass = G_OBJECT_CLASS(klass);
|
||||
oclass->dispose = shimatta_opengl_program_dispose;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void shimatta_opengl_program_init(ShimattaOpenglProgram *self)
|
||||
{
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
|
||||
priv = shimatta_opengl_program_get_instance_private(self);
|
||||
|
||||
priv->shader_id = 0;
|
||||
priv->vertex_src = NULL;
|
||||
priv->vertex_file = NULL;
|
||||
priv->fragment_src = NULL;
|
||||
priv->geometry_src = NULL;
|
||||
priv->fragment_file = NULL;
|
||||
priv->geometry_file = NULL;
|
||||
priv->compiled = false;
|
||||
}
|
||||
|
||||
ShimattaOpenglProgram *shimatta_opengl_program_new_from_data(const char *vertex_shader, const char *geometry_shader,
|
||||
const char *fragment_shader)
|
||||
{
|
||||
ShimattaOpenglProgram *ret;
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
|
||||
ret = g_object_new(SHIMATTA_TYPE_OPENGL_PROGRAM, NULL);
|
||||
priv = shimatta_opengl_program_get_instance_private(ret);
|
||||
|
||||
priv->fragment_src = g_strdup(fragment_shader);
|
||||
priv->geometry_src = g_strdup(geometry_shader);
|
||||
priv->vertex_src= g_strdup(vertex_shader);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ShimattaOpenglProgram *shimatta_opengl_program_new_from_file(const char *vertex_shader, const char *geometry_shader,
|
||||
const char *fragment_shader)
|
||||
{
|
||||
ShimattaOpenglProgram *ret;
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
|
||||
ret = g_object_new(SHIMATTA_TYPE_OPENGL_PROGRAM, NULL);
|
||||
priv = shimatta_opengl_program_get_instance_private(ret);
|
||||
|
||||
priv->vertex_file = g_strdup(vertex_shader);
|
||||
priv->geometry_file = g_strdup(geometry_shader);
|
||||
priv->fragment_file = g_strdup(fragment_shader);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int shimatta_opengl_program_use(ShimattaOpenglProgram *program)
|
||||
{
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), -1001);
|
||||
|
||||
if (!shimatta_opengl_program_is_compiled(program))
|
||||
return -1;
|
||||
|
||||
priv = shimatta_opengl_program_get_instance_private(program);
|
||||
|
||||
glUseProgram(priv->shader_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
gboolean shimatta_opengl_program_is_compiled(ShimattaOpenglProgram *program)
|
||||
{
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), FALSE);
|
||||
priv = shimatta_opengl_program_get_instance_private(program);
|
||||
|
||||
return priv->compiled;
|
||||
}
|
||||
|
||||
static char *load_shader_from_source_file(const char *src_file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static int compile_shader(const char *src, char *error_text, size_t error_text_size, gboolean use_error,
|
||||
GLuint shader_type, GLuint *shader_id_out)
|
||||
{
|
||||
GLuint shader_id;
|
||||
GLint success;
|
||||
int ret = 0;
|
||||
|
||||
if (!shader_id_out || !src)
|
||||
return -1000;
|
||||
|
||||
shader_id = glCreateShader(shader_type);
|
||||
glShaderSource(shader_id, 1, &src, NULL);
|
||||
glCompileShader(shader_id);
|
||||
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
ret = -1;
|
||||
if (use_error) {
|
||||
glGetShaderInfoLog(shader_id, error_text_size, NULL, error_text);
|
||||
}
|
||||
glDeleteShader(shader_id);
|
||||
} else {
|
||||
*shader_id_out = shader_id;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int shimatta_opengl_program_compile(ShimattaOpenglProgram *program, char *error_text, size_t error_text_size)
|
||||
{
|
||||
gboolean use_error = FALSE;
|
||||
ShimattaOpenglProgramPrivate *priv;
|
||||
char *shader_source_code;
|
||||
int ret_val = 0;
|
||||
int status;
|
||||
GLint success;
|
||||
GLuint vertex_shader, fragment_shader, geometry_shader;
|
||||
gboolean vertex_built = FALSE, fragment_built = FALSE, geometry_built = FALSE;
|
||||
|
||||
g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), -1001);
|
||||
|
||||
if (error_text && error_text_size > 0)
|
||||
use_error = TRUE;
|
||||
|
||||
priv = shimatta_opengl_program_get_instance_private(program);
|
||||
|
||||
if (priv->compiled == TRUE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
priv->shader_id = glCreateProgram();
|
||||
|
||||
if (priv->vertex_src) {
|
||||
shader_source_code = priv->vertex_src;
|
||||
} else if (priv->vertex_file) {
|
||||
shader_source_code = load_shader_from_source_file(priv->vertex_file);
|
||||
if (!shader_source_code) {
|
||||
ret_val = -1;
|
||||
goto return_value;
|
||||
}
|
||||
|
||||
} else {
|
||||
shader_source_code = NULL;
|
||||
}
|
||||
|
||||
/* Build the vertex shader */
|
||||
if (shader_source_code) {
|
||||
status = compile_shader(shader_source_code, error_text, error_text_size, use_error, GL_VERTEX_SHADER,
|
||||
&vertex_shader);
|
||||
|
||||
free(shader_source_code);
|
||||
|
||||
if (status) {
|
||||
ret_val = -2;
|
||||
goto return_value;
|
||||
}
|
||||
vertex_built = TRUE;
|
||||
glAttachShader(priv->shader_id, vertex_shader);
|
||||
}
|
||||
|
||||
/* Build the fragment shader */
|
||||
if (priv->fragment_src) {
|
||||
shader_source_code = priv->fragment_src;
|
||||
} else if (priv->fragment_file) {
|
||||
shader_source_code = load_shader_from_source_file(priv->fragment_file);
|
||||
if (!shader_source_code) {
|
||||
ret_val = -1;
|
||||
goto return_value;
|
||||
}
|
||||
} else {
|
||||
shader_source_code = NULL;
|
||||
}
|
||||
|
||||
if (shader_source_code) {
|
||||
status = compile_shader(shader_source_code, error_text, error_text_size, use_error, GL_FRAGMENT_SHADER,
|
||||
&fragment_shader);
|
||||
|
||||
free(shader_source_code);
|
||||
|
||||
if (status) {
|
||||
ret_val = -2;
|
||||
goto return_value;
|
||||
}
|
||||
fragment_built = TRUE;
|
||||
glAttachShader(priv->shader_id, fragment_shader);
|
||||
}
|
||||
|
||||
/* Build the geometry shader */
|
||||
if (priv->geometry_src) {
|
||||
shader_source_code = priv->geometry_src;
|
||||
} else if (priv->geometry_file) {
|
||||
shader_source_code = load_shader_from_source_file(priv->geometry_file);
|
||||
if (!shader_source_code) {
|
||||
ret_val = -1;
|
||||
goto return_value;
|
||||
}
|
||||
} else {
|
||||
shader_source_code = NULL;
|
||||
}
|
||||
|
||||
if (shader_source_code) {
|
||||
status = compile_shader(shader_source_code, error_text, error_text_size, use_error, GL_GEOMETRY_SHADER,
|
||||
&geometry_shader);
|
||||
|
||||
free(shader_source_code);
|
||||
|
||||
if (status) {
|
||||
ret_val = -2;
|
||||
goto return_value;
|
||||
}
|
||||
geometry_built = TRUE;
|
||||
glAttachShader(priv->shader_id, geometry_shader);
|
||||
}
|
||||
|
||||
glLinkProgram(priv->shader_id);
|
||||
glGetShaderiv(priv->shader_id, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
if (use_error)
|
||||
glGetShaderInfoLog(priv->shader_id, error_text_size, NULL, error_text);
|
||||
ret_val = -3;
|
||||
glDeleteProgram(priv->shader_id);
|
||||
} else {
|
||||
priv->compiled = TRUE;
|
||||
}
|
||||
|
||||
return_value:
|
||||
if (vertex_built)
|
||||
glDeleteShader(vertex_shader);
|
||||
if (geometry_built)
|
||||
glDeleteShader(geometry_shader);
|
||||
if (fragment_built)
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
return ret_val;
|
||||
}
|
Reference in New Issue
Block a user