Compare commits
	
		
			4 Commits
		
	
	
		
			9c4dbd51c8
			...
			opengl-pre
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 01613d1977 | |||
| a6899a3f7c | |||
| 4aa63db8dd | |||
| f42d61192a | 
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							| @@ -6,3 +6,6 @@ | ||||
| 	path = 3rdparty/libfort | ||||
| 	url = https://git.shimatta.de/3rd-party/libfort | ||||
| 	branch = develop | ||||
| [submodule "3rdparty/poly2tri"] | ||||
| 	path = 3rdparty/poly2tri | ||||
| 	url = https://git.shimatta.de/3rd-party/poly2tri.git | ||||
|   | ||||
							
								
								
									
										1
									
								
								3rdparty/poly2tri
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								3rdparty/poly2tri
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule 3rdparty/poly2tri added at 3380f5c805
									
								
							| @@ -1,4 +1,8 @@ | ||||
| project(gds-render LANGUAGES C) | ||||
| if (POLICY CMP0048) | ||||
|   cmake_policy(SET CMP0048 NEW) | ||||
| endif (POLICY CMP0048) | ||||
|  | ||||
| project(gds-render LANGUAGES C CXX) | ||||
|  | ||||
| if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) | ||||
|   set(CMAKE_INSTALL_PREFIX "/usr/" CACHE PATH "..." FORCE) | ||||
| @@ -24,7 +28,7 @@ if(NOT WIN32) | ||||
|   set(BoldWhite   "${Esc}[1;37m") | ||||
| endif() | ||||
|  | ||||
| cmake_minimum_required(VERSION 2.8) | ||||
| cmake_minimum_required(VERSION 3.0) | ||||
| find_package(PkgConfig REQUIRED) | ||||
| pkg_search_module(GLIB REQUIRED glib-2.0) | ||||
| pkg_check_modules(GTK3 REQUIRED gtk+-3.0) | ||||
| @@ -71,8 +75,6 @@ SET_SOURCE_FILES_PROPERTIES(${SOURCE_GENERATED} PROPERTIES GENERATED 1) | ||||
|  | ||||
| add_subdirectory(test) | ||||
|  | ||||
| add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) | ||||
|  | ||||
| add_subdirectory(resources) | ||||
| add_subdirectory(doxygen) | ||||
| add_subdirectory(translations) | ||||
| @@ -81,6 +83,14 @@ set(FORT_ENABLE_TESTING OFF CACHE INTERNAL "") | ||||
|  | ||||
| add_subdirectory(3rdparty/libfort) | ||||
|  | ||||
| if(OPENGL_PREVIEW) | ||||
| 	message("${Green}OpenGL preview activated${ColorReset}") | ||||
| 	add_definitions(-DGDS_RENDER_OPGENGL_PREVIEW) | ||||
| 	add_subdirectory(preview-rendering) | ||||
| endif(OPENGL_PREVIEW) | ||||
|  | ||||
| add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) | ||||
|  | ||||
| link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS}) | ||||
| add_definitions(${GLIB2_CFLAGS_OTHER}) | ||||
|  | ||||
| @@ -88,6 +98,10 @@ add_executable(${PROJECT_NAME} ${SOURCE} ${SOURCE_GENERATED}) | ||||
| add_dependencies(${PROJECT_NAME} glib-resources) | ||||
| add_dependencies(${PROJECT_NAME} version) | ||||
| add_dependencies(${PROJECT_NAME} translations) | ||||
| if(OPENGL_PREVIEW) | ||||
| 	add_dependencies(${PROJECT_NAME} opengl-preview) | ||||
| 	target_link_libraries(${PROJECT_NAME} opengl-preview) | ||||
| endif(OPENGL_PREVIEW) | ||||
|  | ||||
| install (TARGETS ${PROJECT_NAME}  | ||||
| 	RUNTIME	 | ||||
|   | ||||
| @@ -44,6 +44,10 @@ | ||||
| #include <gds-render/geometric/cell-geometrics.h> | ||||
| #include <gds-render/version.h> | ||||
|  | ||||
| #ifdef GDS_RENDER_OPGENGL_PREVIEW | ||||
| #include <preview-rendering/preview-rendering-gui.h> | ||||
| #endif | ||||
|  | ||||
| /** @brief Columns of selection tree view */ | ||||
| enum cell_store_columns { | ||||
| 	CELL_SEL_LIBRARY = 0, | ||||
| @@ -68,6 +72,9 @@ struct _GdsRenderGui { | ||||
|  | ||||
| 	/* Custom fields */ | ||||
| 	GtkWindow *main_window; | ||||
| #ifdef GDS_RENDER_OPGENGL_PREVIEW | ||||
| 	OpenGlPreviewGui *preview_gui; | ||||
| #endif | ||||
| 	GtkWidget *convert_button; | ||||
| 	GtkWidget *open_button; | ||||
| 	GtkWidget *load_layer_button; | ||||
| @@ -189,8 +196,8 @@ static gboolean cell_store_filter_visible_func(GtkTreeModel *model, GtkTreeIter | ||||
|  | ||||
| 	gtk_tree_model_get(model, iter, CELL_SEL_CELL, &cell, CELL_SEL_LIBRARY, &lib, -1); | ||||
|  | ||||
|     /* Show always, if this is a pure lib entry */ | ||||
|     if (lib && !cell) { | ||||
| 	/* Show always, if this is a pure lib entry */ | ||||
| 	if (lib && !cell) { | ||||
| 		result = TRUE; | ||||
| 		goto exit_filter; | ||||
| 	} | ||||
| @@ -665,6 +672,9 @@ static void gds_render_gui_dispose(GObject *gobject) | ||||
| 	g_clear_object(&self->save_layer_button); | ||||
| 	g_clear_object(&self->open_button); | ||||
| 	g_clear_object(&self->select_all_button); | ||||
| #ifdef GDS_RENDER_OPGENGL_PREVIEW | ||||
| 	g_clear_object(&self->preview_gui); | ||||
| #endif | ||||
|  | ||||
| 	if (self->main_window) { | ||||
| 		g_signal_handlers_destroy(self->main_window); | ||||
| @@ -768,7 +778,15 @@ static void gds_render_gui_init(GdsRenderGui *self) | ||||
| 	GtkWidget *activity_bar_box; | ||||
| 	GtkWidget *auto_color_button; | ||||
| 	GtkWidget *auto_naming_button; | ||||
| #ifdef GDS_RENDER_OPGENGL_PREVIEW | ||||
| 	OpenGlPreviewGui *preview_gui; | ||||
|  | ||||
| 	preview_gui = opengl_preview_gui_new(); | ||||
| 	/* No need to reference the preview gui. It is already referenced upon creation */ | ||||
| 	self->preview_gui = preview_gui; | ||||
|  | ||||
| 	opengl_preview_gui_show(preview_gui); | ||||
| #endif | ||||
| 	main_builder = gtk_builder_new_from_resource("/gui/main.glade"); | ||||
|  | ||||
| 	self->cell_tree_view = GTK_TREE_VIEW(gtk_builder_get_object(main_builder, "cell-tree")); | ||||
|   | ||||
							
								
								
									
										5
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.c
									
									
									
									
									
								
							| @@ -96,6 +96,11 @@ static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_ | ||||
| 	comment_text = g_string_new(_("gds-render is a free tool for rendering GDS2 layout files into vector graphics.")); | ||||
| 	g_string_append_printf(comment_text, _("\n\nFull git commit: %s"), _app_git_commit); | ||||
|  | ||||
| #ifdef GDS_RENDER_OPGENGL_PREVIEW | ||||
| 	g_string_append_printf(comment_text, _("\nOpenGL Previev: Availabe")); | ||||
| #else | ||||
| 	g_string_append_printf(comment_text, _("\nOpenGL Previev: Unavailabe")); | ||||
| #endif | ||||
| 	builder = gtk_builder_new_from_resource("/gui/about.glade"); | ||||
| 	dialog = GTK_DIALOG(gtk_builder_get_object(builder, "about-dialog")); | ||||
| 	gtk_window_set_transient_for(GTK_WINDOW(dialog), NULL); | ||||
|   | ||||
| @@ -1,2 +1,3 @@ | ||||
| add_subdirectory(plugin-example) | ||||
| add_custom_target(plugins DEPENDS pluginexample) | ||||
| cmake_minimum_required(VERSION 3.0) | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| project(pluginexample) | ||||
| cmake_minimum_required(VERSION 2.8) | ||||
| cmake_minimum_required(VERSION 3.0) | ||||
| find_package(PkgConfig REQUIRED) | ||||
| pkg_search_module(PYTHON REQUIRED python3) | ||||
|  | ||||
|   | ||||
							
								
								
									
										18
									
								
								preview-rendering/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								preview-rendering/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| project(opengl-preview) | ||||
| cmake_minimum_required(VERSION 3.0) | ||||
|  | ||||
| find_package(PkgConfig REQUIRED) | ||||
| pkg_check_modules(EPOXY REQUIRED epoxy) | ||||
| pkg_search_module(GLIB REQUIRED glib-2.0) | ||||
| pkg_check_modules(GTK3 REQUIRED gtk+-3.0) | ||||
|  | ||||
| aux_source_directory("src" SRCS) | ||||
|  | ||||
| add_subdirectory(poly2tri-wrapper) | ||||
|  | ||||
| add_library(${PROJECT_NAME} STATIC ${SRCS}) | ||||
| target_include_directories(${PROJECT_NAME} PUBLIC "include") | ||||
| target_include_directories(${PROJECT_NAME} PRIVATE ${EPOXY_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS}) | ||||
| target_link_directories(${PROJECT_NAME} PUBLIC ${EPOXY_LINK_DIRS} ${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS}) | ||||
| target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${EPOXY_LDFLAGS} ${GTK3_LDFLAGS} poly2tri-wrapper) | ||||
|  | ||||
| @@ -0,0 +1,14 @@ | ||||
| #ifndef _PREVIEW_RENDERING_GUI_H_ | ||||
| #define _PREVIEW_RENDERING_GUI_H_ | ||||
|  | ||||
| #include <gtk/gtk.h> | ||||
|  | ||||
| G_DECLARE_FINAL_TYPE(OpenGlPreviewGui, opengl_preview_gui, GDS_RENDER, OPENGL_PREVIEW_GUI, GObject) | ||||
|  | ||||
| #define TYPE_GDS_RENDER_OPENGL_PREVIEW_GUI (opengl_preview_gui_get_type()) | ||||
|  | ||||
| OpenGlPreviewGui *opengl_preview_gui_new(void); | ||||
|  | ||||
| void opengl_preview_gui_show(OpenGlPreviewGui *self); | ||||
|  | ||||
| #endif /* _PREVIEW_RENDERING_GUI_H_ */ | ||||
							
								
								
									
										11
									
								
								preview-rendering/poly2tri-wrapper/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								preview-rendering/poly2tri-wrapper/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| project(poly2tri-wrapper LANGUAGES CXX) | ||||
| cmake_minimum_required(VERSION 3.12) | ||||
|  | ||||
| add_subdirectory(../../3rdparty/poly2tri poly2tri) | ||||
| set(CMAKE_CXX_STANDARD 14) | ||||
|  | ||||
| aux_source_directory("src" WRAPPER_SOURCES) | ||||
|  | ||||
| add_library(${PROJECT_NAME} STATIC ${WRAPPER_SOURCES}) | ||||
| target_link_libraries(${PROJECT_NAME} poly2tri) | ||||
| target_include_directories(${PROJECT_NAME} PUBLIC "include") | ||||
| @@ -0,0 +1,16 @@ | ||||
| #ifndef _POLY2TRI_WRAPPER_H_ | ||||
| #define _POLY2TRI_WRAPPER_H_ | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include <gds-render/gds-utils/gds-types.h> | ||||
|  | ||||
| int tesselator_triangulate_polygon(const struct gds_graphics *gfx, double scale, float **output_vertices, size_t *vertex_count); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } /* extern "C" */ | ||||
| #endif | ||||
|  | ||||
| #endif /* _POLY2TRI_WRAPPER_H_ */ | ||||
							
								
								
									
										132
									
								
								preview-rendering/poly2tri-wrapper/src/poly2tri-wrapper.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								preview-rendering/poly2tri-wrapper/src/poly2tri-wrapper.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,132 @@ | ||||
| #include <iostream> | ||||
| #include <poly2tri/poly2tri.h> | ||||
| #include <poly2tri-wrapper/poly2tri-wrapper.h> | ||||
| //#include <gds-render/gds-utils/gds-types.h> | ||||
| #include <vector> | ||||
|  | ||||
| class Hole { | ||||
| private: | ||||
| 	std::vector <p2t::Point *> hole_vertices; | ||||
| public: | ||||
| 	const std::vector <p2t::Point *> &get_vertices() | ||||
| 	{ | ||||
| 		return hole_vertices; | ||||
| 	} | ||||
|  | ||||
| 	void add_vertex(const p2t::Point &point) | ||||
| 	{ | ||||
| 		auto pt = new p2t::Point(point); | ||||
| 		hole_vertices.push_back(pt); | ||||
| 	} | ||||
|  | ||||
| 	Hole(std::vector<p2t::Point *>::iterator start, std::vector<p2t::Point *>::iterator end) | ||||
| 	{ | ||||
| 		hole_vertices = std::vector<p2t::Point *>(start, end); | ||||
| 	} | ||||
|  | ||||
| }; | ||||
|  | ||||
|  | ||||
| static std::vector<Hole> resolve_holes_in_polyline(std::vector<p2t::Point *> &polyline) | ||||
| { | ||||
| 	bool found = false; | ||||
| 	std::vector<Hole> holes; | ||||
| 	std::vector<std::pair< | ||||
| 			std::vector<p2t::Point *>::iterator, | ||||
| 			std::vector<p2t::Point *>::iterator> | ||||
| 			> points_to_remove; | ||||
|  | ||||
| 	for (auto start_it = polyline.begin(); start_it != polyline.end(); start_it++) { | ||||
| 		for (auto check_it = std::next(start_it); check_it != polyline.end(); check_it++) { | ||||
| 			/* Check if points are equal */ | ||||
| 			if (**start_it == **check_it) { | ||||
| 				if (**std::prev(check_it) == **std::next(start_it)) { | ||||
| 					/* Found a hole. Everything between start_it and check_it can be removed */ | ||||
| 					auto hole = Hole(std::next(start_it)+1, check_it); | ||||
| 					holes.push_back(hole); | ||||
| 					auto tbd = std::make_pair(start_it, check_it); | ||||
| 					points_to_remove.push_back(tbd); | ||||
| 					found = true; | ||||
| 					break; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		if (found) | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| 	/* Remove form polyline */ | ||||
| 	for (auto it_pair_it = points_to_remove.begin(); it_pair_it != points_to_remove.end(); it_pair_it++) { | ||||
| 		auto it_pair = *it_pair_it; | ||||
| 		delete *it_pair.first; | ||||
| 		delete *std::next(it_pair.first); | ||||
| 		polyline.erase(it_pair.first, it_pair.second); | ||||
| 	} | ||||
|  | ||||
| 	if (found) { | ||||
| 		auto new_holes = resolve_holes_in_polyline(polyline); | ||||
| 		holes.insert(holes.end(), new_holes.begin(), new_holes.end()); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	return holes; | ||||
| } | ||||
|  | ||||
| int tesselator_triangulate_polygon(const struct gds_graphics *gfx, double scale, float** output_vertices, size_t *vertex_count) | ||||
| { | ||||
| 	GList *vertex_iter; | ||||
| 	std::vector<p2t::Point*> polyline; | ||||
|  | ||||
| 	if (gfx->gfx_type != GRAPHIC_POLYGON) | ||||
| 		return -1; | ||||
|  | ||||
| 	for (vertex_iter = gfx->vertices; vertex_iter; vertex_iter = g_list_next(vertex_iter)) { | ||||
| 		struct gds_point *gds_pt = (struct gds_point *)vertex_iter->data; | ||||
| 		auto pt = new p2t::Point((double)gds_pt->x/scale, (double)gds_pt->y/scale); | ||||
| 		polyline.push_back(pt); | ||||
| 	} | ||||
|  | ||||
| 	auto holes = resolve_holes_in_polyline(polyline); | ||||
|  | ||||
| 	auto my_cdt = p2t::CDT(polyline); | ||||
|  | ||||
| 	for (auto hole_it = holes.begin(); hole_it != holes.end(); hole_it++) { | ||||
| 		my_cdt.AddHole((*hole_it).get_vertices()); | ||||
| 	} | ||||
|  | ||||
| 	my_cdt.Triangulate(); | ||||
|  | ||||
| 	auto triangles = my_cdt.GetTriangles(); | ||||
|  | ||||
|  | ||||
|  | ||||
| 	/* Free the triangles */ | ||||
| 	for (auto it = triangles.begin(); it != triangles.end(); it++) { | ||||
| 		auto triangle = *it; | ||||
| 		std::cout << "Triangle: " << | ||||
| 			     triangle->GetPoint(0)->x << "|" << triangle->GetPoint(0)->y << "," | ||||
| 			  << triangle->GetPoint(1)->x << "|" << triangle->GetPoint(1)->x << "," | ||||
| 			  << triangle->GetPoint(2)->x << "|" << triangle->GetPoint(2)->y | ||||
| 			  << std::endl; | ||||
| 	} | ||||
|  | ||||
| 	/* Get the amount of triangles */ | ||||
| 	auto count = triangles.size(); | ||||
| 	*output_vertices = (float *)malloc(2*sizeof(float)*3*count); | ||||
|  | ||||
| 	*vertex_count = count * 3; | ||||
| 	/* Free the points in the vector */ | ||||
| 	for (unsigned int i = 0; i < count; i++) { | ||||
| 		for (int j = 0; j < 3; j++) { | ||||
| 			auto pt = triangles[i]->GetPoint(j); | ||||
| 			unsigned int idx = i * 6 + j * 2; | ||||
| 			(*output_vertices)[idx] = (float)pt->x; | ||||
| 			(*output_vertices)[idx + 1] = (float)pt->y; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for (auto it = polyline.begin(); it != polyline.end(); it++) | ||||
| 		delete *it; | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
							
								
								
									
										258
									
								
								preview-rendering/src/preview-rendering-gui.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										258
									
								
								preview-rendering/src/preview-rendering-gui.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,258 @@ | ||||
| #include <preview-rendering/preview-rendering-gui.h> | ||||
| #include <poly2tri-wrapper/poly2tri-wrapper.h> | ||||
| #include <epoxy/gl.h> | ||||
|  | ||||
| struct _OpenGlPreviewGui { | ||||
| 	GObject super; | ||||
| 	GtkWindow *main_window; | ||||
| 	GtkGLArea *gl_area; | ||||
| 	unsigned int polygon_shader_prog; | ||||
| 	unsigned int vao; | ||||
| 	unsigned int vao_vertex_count; | ||||
| 	unsigned int vbo; | ||||
| 	float color[4]; | ||||
| 	gboolean line; | ||||
| }; | ||||
|  | ||||
| G_DEFINE_TYPE(OpenGlPreviewGui, opengl_preview_gui, G_TYPE_OBJECT) | ||||
|  | ||||
| static void opengl_preview_gui_dispose(GObject *gobj) | ||||
| { | ||||
| 	OpenGlPreviewGui *self; | ||||
|  | ||||
| 	self = GDS_RENDER_OPENGL_PREVIEW_GUI(gobj); | ||||
|  | ||||
| 	g_clear_object(&self->gl_area); | ||||
|  | ||||
| 	if (self->main_window) { | ||||
| 		gtk_widget_destroy(GTK_WIDGET(self->main_window)); | ||||
| 		self->main_window = NULL; | ||||
| 	} | ||||
|  | ||||
| 	G_OBJECT_CLASS(opengl_preview_gui_parent_class)->dispose(gobj); | ||||
| } | ||||
|  | ||||
| static void opengl_preview_gui_class_init(OpenGlPreviewGuiClass *klass) | ||||
| { | ||||
| 	GObjectClass *oclass = G_OBJECT_CLASS(klass); | ||||
|  | ||||
| 	oclass->dispose = opengl_preview_gui_dispose; | ||||
| } | ||||
|  | ||||
| static gboolean gl_area_render(GtkGLArea *area, GdkGLContext *context, gpointer user) | ||||
| { | ||||
| 	OpenGlPreviewGui *gui; | ||||
|  | ||||
| 	int loc; | ||||
|  | ||||
| 	gui = GDS_RENDER_OPENGL_PREVIEW_GUI(user); | ||||
| 	gtk_gl_area_make_current(area); | ||||
|  | ||||
| 	glClearColor (0, 0, 0, 1.0); | ||||
| 	glClear (GL_COLOR_BUFFER_BIT); | ||||
| 	glPolygonMode(GL_FRONT_AND_BACK, gui->line ? GL_LINE : GL_FILL); | ||||
| 	glUseProgram(gui->polygon_shader_prog); | ||||
| 	glBindVertexArray(gui->vao); | ||||
| 	loc = glGetUniformLocation(gui->polygon_shader_prog, "const_color"); | ||||
| 	glUniform4fv(loc, 1, gui->color); | ||||
| 	glDrawArrays(GL_TRIANGLES, 0, gui->vao_vertex_count); | ||||
|  | ||||
| 	glFlush(); | ||||
|  | ||||
| 	return TRUE; | ||||
| } | ||||
|  | ||||
| static int compile_shader_from_resource(GLenum shader_type, const char *res_name, unsigned int *shader) | ||||
| { | ||||
| 	int success; | ||||
| 	GBytes *res_bytes; | ||||
| 	const char *data; | ||||
| 	gsize size; | ||||
| 	int size_int; | ||||
| 	int sh; | ||||
|  | ||||
| 	res_bytes = g_resources_lookup_data(res_name, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); | ||||
| 	data = g_bytes_get_data(res_bytes, &size); | ||||
| 	sh = glCreateShader(shader_type); | ||||
| 	size_int = (int)size; | ||||
| 	glShaderSource(sh, 1, &data, &size_int); | ||||
| 	glCompileShader(sh); | ||||
| 	glGetShaderiv(sh, GL_COMPILE_STATUS, &success); | ||||
| 	g_bytes_unref(res_bytes); | ||||
| 	if (shader) | ||||
| 		*shader = sh; | ||||
|  | ||||
| 	return success; | ||||
| } | ||||
|  | ||||
| static gboolean gl_area_realize(GtkGLArea *area, gpointer user) | ||||
| { | ||||
| 	unsigned int vbo; | ||||
| 	unsigned int vs; | ||||
| 	unsigned int fs; | ||||
| 	unsigned int prog; | ||||
| 	unsigned int vao; | ||||
| 	OpenGlPreviewGui *gui; | ||||
| 	int success; | ||||
| 	struct gds_graphics gfx; | ||||
| 	struct gds_point points[20]; | ||||
| 	size_t vertex_count; | ||||
|  | ||||
| 	gui = GDS_RENDER_OPENGL_PREVIEW_GUI(user); | ||||
|  | ||||
| 	gui->color[0] = 0.6f; | ||||
| 	gui->color[1] = 0.5f; | ||||
| 	gui->color[2] = 0.12f; | ||||
| 	gui->color[3] = 1.0f; | ||||
|  | ||||
| 	gtk_gl_area_make_current(area); | ||||
|  | ||||
| 	if (!compile_shader_from_resource(GL_VERTEX_SHADER, "/shaders/polygon.vs", &vs)) { | ||||
| 		g_warning("Error compiling vertex shader"); | ||||
| 	} | ||||
| 	if (!compile_shader_from_resource(GL_FRAGMENT_SHADER, "/shaders/polygon.fs", &fs)) { | ||||
| 		g_warning("Error compiling fragment shader"); | ||||
| 	} | ||||
|  | ||||
| 	prog = glCreateProgram(); | ||||
| 	glAttachShader(prog, vs); | ||||
| 	glAttachShader(prog, fs); | ||||
| 	glLinkProgram(prog); | ||||
| 	glGetProgramiv(prog, GL_LINK_STATUS, &success); | ||||
| 	if (!success) { | ||||
| 		g_warning("Error linking shader"); | ||||
| 	} | ||||
| 	glUseProgram(prog); | ||||
| 	glDeleteShader(vs); | ||||
| 	glDeleteShader(fs); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| 	gui->polygon_shader_prog = prog; | ||||
|  | ||||
|  | ||||
| 	gfx.vertices = NULL; | ||||
| 	points[0].x = -100; | ||||
| 	points[0].y = -100; | ||||
|  | ||||
| 	points[1].x = -100; | ||||
| 	points[1].y = +100; | ||||
|  | ||||
| 	points[2].x = +0; | ||||
| 	points[2].y = +100; | ||||
|  | ||||
| 	points[3].x = +0; | ||||
| 	points[3].y = 20; | ||||
|  | ||||
| 	points[4].x = -20; | ||||
| 	points[4].y = 20; | ||||
|  | ||||
| 	points[5].x = -20; | ||||
| 	points[5].y = -20; | ||||
|  | ||||
| 	points[6].x = 20; | ||||
| 	points[6].y = -20; | ||||
|  | ||||
| 	points[7].x = 20; | ||||
| 	points[7].y = 20; | ||||
|  | ||||
| 	points[8].x = 0; | ||||
| 	points[8].y = 20; | ||||
|  | ||||
| 	points[9].x = 0; | ||||
| 	points[9].y = 100; | ||||
|  | ||||
| 	points[10].x = 100; | ||||
| 	points[10].y = 100; | ||||
|  | ||||
|  | ||||
| 	points[11].x = 100; | ||||
| 	points[11].y = 5; | ||||
|  | ||||
| 	points[12].x = 60; | ||||
| 	points[12].y = 5; | ||||
|  | ||||
| 	points[13].x = 60; | ||||
| 	points[13].y = 20; | ||||
|  | ||||
| 	points[14].x = 50; | ||||
| 	points[14].y = 20; | ||||
|  | ||||
| 	points[15].x = 50; | ||||
| 	points[15].y = 0; | ||||
|  | ||||
| 	points[16].x = 60; | ||||
| 	points[16].y = 0; | ||||
|  | ||||
| 	points[17].x = 60; | ||||
| 	points[17].y = 5; | ||||
|  | ||||
| 	points[18].x = 100; | ||||
| 	points[18].y = 5; | ||||
|  | ||||
|  | ||||
| 	points[19].x = 100; | ||||
| 	points[19].y = -100; | ||||
|  | ||||
| 	gfx.gfx_type = GRAPHIC_POLYGON; | ||||
|  | ||||
| 	for (int i = 0; i < 20; i++) { | ||||
| 		gfx.vertices = g_list_append(gfx.vertices, &points[i]); | ||||
| 	} | ||||
|  | ||||
| 	float *vertices = NULL; | ||||
|  | ||||
| 	tesselator_triangulate_polygon(&gfx, 180.0, &vertices, &vertex_count); | ||||
| 	gui->vao_vertex_count = vertex_count; | ||||
|  | ||||
| 	glGenVertexArrays(1, &vao); | ||||
| 	glBindVertexArray(vao); | ||||
| 	glGenBuffers(1, &vbo); | ||||
| 	glBindBuffer(GL_ARRAY_BUFFER, vbo); | ||||
| 	glBufferData(GL_ARRAY_BUFFER, vertex_count*2*sizeof(float), vertices, GL_STATIC_DRAW); | ||||
| 	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (void *)0); | ||||
| 	glEnableVertexAttribArray(0); | ||||
|  | ||||
| 	free(vertices); | ||||
|  | ||||
| 	gui->vao = vao; | ||||
| 	gui->vbo = vbo; | ||||
|  | ||||
| 	g_list_free(gfx.vertices); | ||||
|  | ||||
| 	return TRUE; | ||||
|  | ||||
| } | ||||
|  | ||||
| static void on_clicked(GtkWidget *sender, gboolean *p) | ||||
| { | ||||
| 	*p = !*p; | ||||
| } | ||||
|  | ||||
| static void opengl_preview_gui_init(OpenGlPreviewGui *self) | ||||
| { | ||||
| 	GtkBuilder *builder; | ||||
|  | ||||
| 	builder = gtk_builder_new_from_resource("/gui/preview-window.glade"); | ||||
| 	self->main_window = GTK_WINDOW(gtk_builder_get_object(builder, "main-window")); | ||||
| 	self->gl_area = GTK_GL_AREA(gtk_builder_get_object(builder, "gl-area")); | ||||
| 	g_signal_connect(self->gl_area, "render", G_CALLBACK(gl_area_render), self); | ||||
| 	g_signal_connect(self->gl_area, "realize", G_CALLBACK(gl_area_realize), self); | ||||
|  | ||||
| 	g_signal_connect(gtk_builder_get_object(builder, "test-button"), "clicked", G_CALLBACK(on_clicked), &self->line); | ||||
| 	self->line = FALSE; | ||||
| 	g_object_ref(self->gl_area); | ||||
| } | ||||
|  | ||||
| OpenGlPreviewGui *opengl_preview_gui_new(void) | ||||
| { | ||||
| 	return GDS_RENDER_OPENGL_PREVIEW_GUI(g_object_new(TYPE_GDS_RENDER_OPENGL_PREVIEW_GUI, NULL)); | ||||
| } | ||||
|  | ||||
| void opengl_preview_gui_show(OpenGlPreviewGui *self) | ||||
| { | ||||
| 	gtk_widget_show(GTK_WIDGET(self->main_window)); | ||||
| } | ||||
							
								
								
									
										8
									
								
								preview-rendering/src/preview-rendering.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								preview-rendering/src/preview-rendering.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| #include <epoxy/gl.h> | ||||
|  | ||||
| int foobar(void) | ||||
| { | ||||
| 	GLuint foo; | ||||
| 	glGenBuffers(1, &foo); | ||||
| 	return 42; | ||||
| } | ||||
							
								
								
									
										43
									
								
								resources/preview-window.glade
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								resources/preview-window.glade
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!-- Generated with glade 3.38.2 --> | ||||
| <interface> | ||||
|   <requires lib="gtk+" version="3.24"/> | ||||
|   <object class="GtkWindow" id="main-window"> | ||||
|     <property name="can-focus">False</property> | ||||
|     <property name="default-width">1024</property> | ||||
|     <property name="default-height">500</property> | ||||
|     <child> | ||||
|       <object class="GtkBox"> | ||||
|         <property name="visible">True</property> | ||||
|         <property name="can-focus">False</property> | ||||
|         <property name="baseline-position">bottom</property> | ||||
|         <child> | ||||
|           <object class="GtkButton" id="test-button"> | ||||
|             <property name="label" translatable="yes">button</property> | ||||
|             <property name="visible">True</property> | ||||
|             <property name="can-focus">True</property> | ||||
|             <property name="receives-default">True</property> | ||||
|           </object> | ||||
|           <packing> | ||||
|             <property name="expand">False</property> | ||||
|             <property name="fill">True</property> | ||||
|             <property name="position">0</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|         <child> | ||||
|           <object class="GtkGLArea" id="gl-area"> | ||||
|             <property name="visible">True</property> | ||||
|             <property name="app-paintable">True</property> | ||||
|             <property name="can-focus">False</property> | ||||
|             <property name="has-alpha">True</property> | ||||
|           </object> | ||||
|           <packing> | ||||
|             <property name="expand">True</property> | ||||
|             <property name="fill">True</property> | ||||
|             <property name="position">1</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|       </object> | ||||
|     </child> | ||||
|   </object> | ||||
| </interface> | ||||
| @@ -5,6 +5,7 @@ | ||||
| 		<file compressed="true">about.glade</file> | ||||
| 		<file>layer-widget.glade</file> | ||||
| 		<file>dialog.glade</file> | ||||
| 		<file compressed="true">preview-window.glade</file> | ||||
| 	</gresource> | ||||
| 	<gresource prefix="/data"> | ||||
| 		<file compressed="true">color-palette.txt</file> | ||||
| @@ -12,6 +13,10 @@ | ||||
| 	<gresource prefix="/images"> | ||||
| 		<file compressed="true" alias="logo.svg">../icon/gds-render.svg</file> | ||||
| 	</gresource> | ||||
| 	<gresource prefix="/shaders"> | ||||
| 		<file compressed="true" alias="polygon.fs">./shaders/polygon.fs.glsl</file> | ||||
| 		<file compressed="true" alias="polygon.vs">./shaders/polygon.vs.glsl</file> | ||||
| 	</gresource> | ||||
| </gresources> | ||||
|  | ||||
|  | ||||
|   | ||||
							
								
								
									
										9
									
								
								resources/shaders/polygon.fs.glsl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								resources/shaders/polygon.fs.glsl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| #version 330 core | ||||
|  | ||||
| out vec4 FragColor; | ||||
| in  vec4 vertex_color; | ||||
|  | ||||
| void main() | ||||
| { | ||||
| 	FragColor = vertex_color; | ||||
| } | ||||
							
								
								
									
										12
									
								
								resources/shaders/polygon.vs.glsl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								resources/shaders/polygon.vs.glsl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| #version 330 core | ||||
|  | ||||
| //uniform mat4 mvp; | ||||
| uniform vec4 const_color; | ||||
|  | ||||
| layout (location = 0) in vec2 input_vertex; | ||||
| out vec4 vertex_color; | ||||
| void main() | ||||
| { | ||||
| 	gl_Position = vec4(input_vertex.x, input_vertex.y, 0.0, 1.0); | ||||
| 	vertex_color = const_color; | ||||
| } | ||||
| @@ -1,4 +1,5 @@ | ||||
| project(gds-render-test) | ||||
| cmake_minimum_required(VERSION 3.0) | ||||
|  | ||||
| add_custom_target(test "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" "-r compact" "-s" DEPENDS ${PROJECT_NAME}) | ||||
|  | ||||
| @@ -22,7 +23,6 @@ if(NOT WIN32) | ||||
|   set(BoldWhite   "${Esc}[1;37m") | ||||
| endif() | ||||
|  | ||||
| cmake_minimum_required(VERSION 2.8) | ||||
| find_package(PkgConfig REQUIRED) | ||||
|  | ||||
| include_directories("${CMAKE_CURRENT_SOURCE_DIR}/catch-framework") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user