Add cglm library and add uniform setters for shader programs
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					[submodule "cglm/cglm"]
 | 
				
			||||||
 | 
						path = cglm/cglm
 | 
				
			||||||
 | 
						url = https://github.com/recp/cglm.git
 | 
				
			||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
cmake_minimum_required(VERSION 3.5)
 | 
					cmake_minimum_required(VERSION 3.5)
 | 
				
			||||||
project(shimatta-opengl LANGUAGES C)
 | 
					project(shimatta-opengl LANGUAGES C)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					add_subdirectory(cglm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
find_package(PkgConfig REQUIRED)
 | 
					find_package(PkgConfig REQUIRED)
 | 
				
			||||||
pkg_search_module(GLIB REQUIRED glib-2.0)
 | 
					pkg_search_module(GLIB REQUIRED glib-2.0)
 | 
				
			||||||
pkg_check_modules(EPOXY REQUIRED epoxy)
 | 
					pkg_check_modules(EPOXY REQUIRED epoxy)
 | 
				
			||||||
@@ -11,7 +13,7 @@ aux_source_directory("src" SRC_DIR)
 | 
				
			|||||||
add_library(${PROJECT_NAME} SHARED ${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} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
 | 
				
			||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS})
 | 
					target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS})
 | 
				
			||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${EPOXY_LDFLAGS})
 | 
					target_link_libraries(${PROJECT_NAME} PUBLIC ${GLIB_LDFLAGS} ${EPOXY_LDFLAGS} cglm)
 | 
				
			||||||
target_link_directories(${PROJECT_NAME} PUBLIC ${GLIB_LINK_DIRS} ${EPOXY_LINK_DIRS})
 | 
					target_link_directories(${PROJECT_NAME} PUBLIC ${GLIB_LINK_DIRS} ${EPOXY_LINK_DIRS})
 | 
				
			||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB_INCLUDE_DIRS})
 | 
					target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB_INCLUDE_DIRS})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								cglm/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								cglm/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					project(cglm)
 | 
				
			||||||
 | 
					cmake_minimum_required(VERSION 2.8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS})
 | 
				
			||||||
 | 
					link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS})
 | 
				
			||||||
 | 
					add_definitions(${GLIB2_CFLAGS_OTHER})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					aux_source_directory("cglm/src" SOURCES)
 | 
				
			||||||
 | 
					add_library(${PROJECT_NAME} STATIC ${SOURCES})
 | 
				
			||||||
 | 
					add_compile_options(-Wall -std=gnu99 -O3 -Wstrict-aliasing=2 -fstrict-aliasing -pedantic)
 | 
				
			||||||
 | 
					target_include_directories(${PROJECT_NAME} PUBLIC "cglm/include")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					target_link_libraries(${PROJECT_NAME} m)
 | 
				
			||||||
							
								
								
									
										1
									
								
								cglm/cglm
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								cglm/cglm
									
									
									
									
									
										Submodule
									
								
							 Submodule cglm/cglm added at 79c44fdbfa
									
								
							@@ -1,7 +1,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * This file is part of Shimatta OpenGL.
 | 
					 * This file is part of Shimatta OpenGL.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
* Foobar is free software: you can redistribute it and/or modify
 | 
					* Shimatta OpenGL is free software: you can redistribute it and/or modify
 | 
				
			||||||
* it under the terms of the GNU General Public License version 2 as
 | 
					* it under the terms of the GNU General Public License version 2 as
 | 
				
			||||||
* published by the Free Software Foundation.
 | 
					* published by the Free Software Foundation.
 | 
				
			||||||
*
 | 
					*
 | 
				
			||||||
@@ -16,6 +16,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <glib.h>
 | 
					#include <glib.h>
 | 
				
			||||||
#include <glib-object.h>
 | 
					#include <glib-object.h>
 | 
				
			||||||
 | 
					#include <cglm/cglm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_BEGIN_DECLS
 | 
					G_BEGIN_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -72,4 +73,36 @@ int shimatta_opengl_program_use(ShimattaOpenglProgram *program);
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
gboolean shimatta_opengl_program_is_compiled(ShimattaOpenglProgram *program);
 | 
					gboolean shimatta_opengl_program_is_compiled(ShimattaOpenglProgram *program);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @brief Get the location of a uniform of a given shader program
 | 
				
			||||||
 | 
					 * @param program Shader program
 | 
				
			||||||
 | 
					 * @param uniform_name Name of the uniform parameter
 | 
				
			||||||
 | 
					 * @return Location. -1 if error.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int shimatta_opengl_program_get_uniform_location(ShimattaOpenglProgram *program, const char *uniform_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @brief Get the location of an Attribute of a given shader program
 | 
				
			||||||
 | 
					 * @param program Shader program
 | 
				
			||||||
 | 
					 * @param attrib_name Name of the attribute
 | 
				
			||||||
 | 
					 * @return Location of attribute. -1 if error.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int shimatta_opengl_program_get_attrib_location(ShimattaOpenglProgram *program, const char *attrib_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_float(ShimattaOpenglProgram *program, const char *uniform, float value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_int(ShimattaOpenglProgram *program, const char *uniform, int value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_vec2(ShimattaOpenglProgram *program, const char *uniform, vec2 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_vec3(ShimattaOpenglProgram *program, const char *uniform, vec3 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_vec4(ShimattaOpenglProgram *program, const char *uniform, vec4 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_mat2(ShimattaOpenglProgram *program, const char *uniform, mat2 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_mat3(ShimattaOpenglProgram *program, const char *uniform, mat3 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_mat4(ShimattaOpenglProgram *program, const char *uniform, mat4 value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_END_DECLS
 | 
					G_END_DECLS
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * This file is part of Shimatta OpenGL.
 | 
					 * This file is part of Shimatta OpenGL.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
* Foobar is free software: you can redistribute it and/or modify
 | 
					* Shimatta OpenGL is free software: you can redistribute it and/or modify
 | 
				
			||||||
* it under the terms of the GNU General Public License version 2 as
 | 
					* it under the terms of the GNU General Public License version 2 as
 | 
				
			||||||
* published by the Free Software Foundation.
 | 
					* published by the Free Software Foundation.
 | 
				
			||||||
*
 | 
					*
 | 
				
			||||||
@@ -343,3 +343,139 @@ return_value:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return ret_val;
 | 
						return ret_val;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int shimatta_opengl_program_get_uniform_location(ShimattaOpenglProgram *program, const char *uniform_name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
						ShimattaOpenglProgramPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), -1001);
 | 
				
			||||||
 | 
						if (!uniform_name)
 | 
				
			||||||
 | 
							return -1002;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!shimatta_opengl_program_is_compiled(program)) {
 | 
				
			||||||
 | 
							g_warning("Trying to get Uniform location of %s for not loaded shader program", uniform_name);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						priv = shimatta_opengl_program_get_instance_private(program);
 | 
				
			||||||
 | 
						ret = glGetUniformLocation(priv->shader_id, (const GLchar *)uniform_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int shimatta_opengl_program_get_attrib_location(ShimattaOpenglProgram *program, const char *attrib_name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
						ShimattaOpenglProgramPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), -1001);
 | 
				
			||||||
 | 
						if (!attrib_name)
 | 
				
			||||||
 | 
							return -1002;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!shimatta_opengl_program_is_compiled(program)) {
 | 
				
			||||||
 | 
							g_warning("Trying to get Attribute location of %s for not loaded shader program", attrib_name);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						priv = shimatta_opengl_program_get_instance_private(program);
 | 
				
			||||||
 | 
						ret = glGetAttribLocation(priv->shader_id, (const GLchar *)attrib_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_float(ShimattaOpenglProgram *program, const char *uniform, float value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniform1f(loc, value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_int(ShimattaOpenglProgram *program, const char *uniform, int value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniform1i(loc, value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_vec2(ShimattaOpenglProgram *program, const char *uniform, vec2 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniform2fv(loc, 1, value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_vec3(ShimattaOpenglProgram *program, const char *uniform, vec3 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniform3fv(loc, 1, value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_vec4(ShimattaOpenglProgram *program, const char *uniform, vec4 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniform4fv(loc, 1, value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_mat2(ShimattaOpenglProgram *program, const char *uniform, mat2 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniformMatrix2fv(loc, 1, GL_FALSE, &value[0][0]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_mat3(ShimattaOpenglProgram *program, const char *uniform, mat3 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniformMatrix3fv(loc, 1, GL_FALSE, &value[0][0]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shimatta_opengl_program_set_uniform_mat4(ShimattaOpenglProgram *program, const char *uniform, mat4 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
 | 
				
			||||||
 | 
						g_return_if_fail(uniform != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						loc = shimatta_opengl_program_get_uniform_location(program, uniform);
 | 
				
			||||||
 | 
						if (loc >= 0)
 | 
				
			||||||
 | 
							glUniformMatrix4fv(loc, 1, GL_FALSE, &value[0][0]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user