Compare commits
	
		
			4 Commits
		
	
	
		
			46-open-fi
			...
			opengl-pre
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 01613d1977 | |||
| a6899a3f7c | |||
| 4aa63db8dd | |||
| f42d61192a | 
							
								
								
									
										5
									
								
								.github/workflows/cmake.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.github/workflows/cmake.yml
									
									
									
									
										vendored
									
									
								
							@@ -19,10 +19,7 @@ jobs:
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - name: Checkout Repository
 | 
			
		||||
      uses: actions/checkout@v2
 | 
			
		||||
      with:
 | 
			
		||||
        submodules: recursive
 | 
			
		||||
    - uses: actions/checkout@v2
 | 
			
		||||
    
 | 
			
		||||
    - name: Install system dependencies
 | 
			
		||||
      if: runner.os == 'Linux'
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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	
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										158
									
								
								gds-render-gui.c
									
									
									
									
									
								
							
							
						
						
									
										158
									
								
								gds-render-gui.c
									
									
									
									
									
								
							@@ -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;
 | 
			
		||||
	}
 | 
			
		||||
@@ -274,13 +281,25 @@ const struct gds_cell_statistics cc =  {
 | 
			
		||||
 */
 | 
			
		||||
static void on_load_gds(gpointer button, gpointer user)
 | 
			
		||||
{
 | 
			
		||||
	(void)button;
 | 
			
		||||
	GList *cell;
 | 
			
		||||
	GtkTreeIter libiter;
 | 
			
		||||
	GtkTreeIter celliter;
 | 
			
		||||
	GList *lib;
 | 
			
		||||
	struct gds_library *gds_lib;
 | 
			
		||||
	struct gds_cell *gds_c;
 | 
			
		||||
	GdsRenderGui *self;
 | 
			
		||||
	GtkWidget *open_dialog;
 | 
			
		||||
	GtkFileChooser *file_chooser;
 | 
			
		||||
	GtkFileFilter *filter;
 | 
			
		||||
	GtkStyleContext *button_style;
 | 
			
		||||
	gint dialog_result;
 | 
			
		||||
	int gds_result;
 | 
			
		||||
	char *filename;
 | 
			
		||||
	unsigned int cell_error_level;
 | 
			
		||||
 | 
			
		||||
	const struct gds_library_parsing_opts gds_parsing_options = {
 | 
			
		||||
		.simplified_polygons = 1,
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	self = RENDERER_GUI(user);
 | 
			
		||||
	if (!self)
 | 
			
		||||
@@ -307,9 +326,59 @@ static void on_load_gds(gpointer button, gpointer user)
 | 
			
		||||
	/* Get File name */
 | 
			
		||||
	filename = gtk_file_chooser_get_filename(file_chooser);
 | 
			
		||||
 | 
			
		||||
	gds_render_gui_open_gds(self, filename);
 | 
			
		||||
	gtk_tree_store_clear(self->cell_tree_store);
 | 
			
		||||
	clear_lib_list(&self->gds_libraries);
 | 
			
		||||
 | 
			
		||||
	/* Parse new GDSII file */
 | 
			
		||||
	gds_result = parse_gds_from_file(filename, &self->gds_libraries, &gds_parsing_options);
 | 
			
		||||
 | 
			
		||||
	/* Delete file name afterwards */
 | 
			
		||||
	g_free(filename);
 | 
			
		||||
	if (gds_result)
 | 
			
		||||
		goto end_destroy;
 | 
			
		||||
 | 
			
		||||
	/* remove suggested action from Open button */
 | 
			
		||||
	button_style = gtk_widget_get_style_context(GTK_WIDGET(button));
 | 
			
		||||
	gtk_style_context_remove_class(button_style, "suggested-action");
 | 
			
		||||
 | 
			
		||||
	for (lib = self->gds_libraries; lib != NULL; lib = lib->next) {
 | 
			
		||||
		gds_lib = (struct gds_library *)lib->data;
 | 
			
		||||
		/* Create top level iter */
 | 
			
		||||
		gtk_tree_store_append(self->cell_tree_store, &libiter, NULL);
 | 
			
		||||
 | 
			
		||||
		gtk_tree_store_set(self->cell_tree_store, &libiter,
 | 
			
		||||
				   CELL_SEL_LIBRARY, gds_lib,
 | 
			
		||||
				   -1);
 | 
			
		||||
 | 
			
		||||
		/* Check this library. This might take a while */
 | 
			
		||||
		(void)gds_tree_check_cell_references(gds_lib);
 | 
			
		||||
		(void)gds_tree_check_reference_loops(gds_lib);
 | 
			
		||||
 | 
			
		||||
		for (cell = gds_lib->cells; cell != NULL; cell = cell->next) {
 | 
			
		||||
			gds_c = (struct gds_cell *)cell->data;
 | 
			
		||||
			gtk_tree_store_append(self->cell_tree_store, &celliter, &libiter);
 | 
			
		||||
 | 
			
		||||
			/* Get the checking results for this cell */
 | 
			
		||||
			cell_error_level = 0;
 | 
			
		||||
			if (gds_c->checks.unresolved_child_count)
 | 
			
		||||
				cell_error_level |= LIB_CELL_RENDERER_ERROR_WARN;
 | 
			
		||||
 | 
			
		||||
			/* Check if it is completely b0rken */
 | 
			
		||||
			if (gds_c->checks.affected_by_reference_loop)
 | 
			
		||||
				cell_error_level |= LIB_CELL_RENDERER_ERROR_ERR;
 | 
			
		||||
 | 
			
		||||
			/* Add cell to tree store model */
 | 
			
		||||
			gtk_tree_store_set(self->cell_tree_store, &celliter,
 | 
			
		||||
					   CELL_SEL_CELL, gds_c,
 | 
			
		||||
					   CELL_SEL_CELL_ERROR_STATE, cell_error_level,
 | 
			
		||||
					   CELL_SEL_LIBRARY, gds_c->parent_library,
 | 
			
		||||
					   CELL_SEL_STAT, &gds_c->stats,
 | 
			
		||||
					   -1);
 | 
			
		||||
		} /* for cells */
 | 
			
		||||
	} /* for libraries */
 | 
			
		||||
 | 
			
		||||
	/* Create Layers in Layer Box */
 | 
			
		||||
	layer_selector_generate_layer_widgets(self->layer_selector, self->gds_libraries);
 | 
			
		||||
 | 
			
		||||
end_destroy:
 | 
			
		||||
	/* Destroy dialog and filter */
 | 
			
		||||
@@ -603,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);
 | 
			
		||||
@@ -696,76 +768,6 @@ GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui)
 | 
			
		||||
	return gui->main_window;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void gds_render_gui_open_gds(GdsRenderGui *self, const char *path)
 | 
			
		||||
{
 | 
			
		||||
	GList *cell;
 | 
			
		||||
	GtkTreeIter libiter;
 | 
			
		||||
	GtkTreeIter celliter;
 | 
			
		||||
	GList *lib;
 | 
			
		||||
	struct gds_library *gds_lib;
 | 
			
		||||
	struct gds_cell *gds_c;
 | 
			
		||||
	GtkStyleContext *button_style;
 | 
			
		||||
	int gds_result;
 | 
			
		||||
	unsigned int cell_error_level;
 | 
			
		||||
 | 
			
		||||
	const struct gds_library_parsing_opts gds_parsing_options = {
 | 
			
		||||
		.simplified_polygons = 1,
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	gtk_tree_store_clear(self->cell_tree_store);
 | 
			
		||||
	clear_lib_list(&self->gds_libraries);
 | 
			
		||||
 | 
			
		||||
	/* Parse new GDSII file */
 | 
			
		||||
	gds_result = parse_gds_from_file(path, &self->gds_libraries, &gds_parsing_options);
 | 
			
		||||
 | 
			
		||||
	/* Delete file name afterwards */
 | 
			
		||||
	if (gds_result)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	/* remove suggested action from Open button */
 | 
			
		||||
	button_style = gtk_widget_get_style_context(self->open_button);
 | 
			
		||||
	gtk_style_context_remove_class(button_style, "suggested-action");
 | 
			
		||||
 | 
			
		||||
	for (lib = self->gds_libraries; lib != NULL; lib = lib->next) {
 | 
			
		||||
		gds_lib = (struct gds_library *)lib->data;
 | 
			
		||||
		/* Create top level iter */
 | 
			
		||||
		gtk_tree_store_append(self->cell_tree_store, &libiter, NULL);
 | 
			
		||||
 | 
			
		||||
		gtk_tree_store_set(self->cell_tree_store, &libiter,
 | 
			
		||||
				   CELL_SEL_LIBRARY, gds_lib,
 | 
			
		||||
				   -1);
 | 
			
		||||
 | 
			
		||||
		/* Check this library. This might take a while */
 | 
			
		||||
		(void)gds_tree_check_cell_references(gds_lib);
 | 
			
		||||
		(void)gds_tree_check_reference_loops(gds_lib);
 | 
			
		||||
 | 
			
		||||
		for (cell = gds_lib->cells; cell != NULL; cell = cell->next) {
 | 
			
		||||
			gds_c = (struct gds_cell *)cell->data;
 | 
			
		||||
			gtk_tree_store_append(self->cell_tree_store, &celliter, &libiter);
 | 
			
		||||
 | 
			
		||||
			/* Get the checking results for this cell */
 | 
			
		||||
			cell_error_level = 0;
 | 
			
		||||
			if (gds_c->checks.unresolved_child_count)
 | 
			
		||||
				cell_error_level |= LIB_CELL_RENDERER_ERROR_WARN;
 | 
			
		||||
 | 
			
		||||
			/* Check if it is completely b0rken */
 | 
			
		||||
			if (gds_c->checks.affected_by_reference_loop)
 | 
			
		||||
				cell_error_level |= LIB_CELL_RENDERER_ERROR_ERR;
 | 
			
		||||
 | 
			
		||||
			/* Add cell to tree store model */
 | 
			
		||||
			gtk_tree_store_set(self->cell_tree_store, &celliter,
 | 
			
		||||
					   CELL_SEL_CELL, gds_c,
 | 
			
		||||
					   CELL_SEL_CELL_ERROR_STATE, cell_error_level,
 | 
			
		||||
					   CELL_SEL_LIBRARY, gds_c->parent_library,
 | 
			
		||||
					   CELL_SEL_STAT, &gds_c->stats,
 | 
			
		||||
					   -1);
 | 
			
		||||
		} /* for cells */
 | 
			
		||||
	} /* for libraries */
 | 
			
		||||
 | 
			
		||||
	/* Create Layers in Layer Box */
 | 
			
		||||
	layer_selector_generate_layer_widgets(self->layer_selector, self->gds_libraries);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void gds_render_gui_init(GdsRenderGui *self)
 | 
			
		||||
{
 | 
			
		||||
	GtkBuilder *main_builder;
 | 
			
		||||
@@ -776,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"));
 | 
			
		||||
 
 | 
			
		||||
@@ -364,7 +364,6 @@ static GList *append_cell(GList *curr_list, struct gds_cell **cell_ptr)
 | 
			
		||||
		cell->checks.affected_by_reference_loop = GDS_CELL_CHECK_NOT_RUN;
 | 
			
		||||
		cell->stats.reference_count = 0;
 | 
			
		||||
		cell->stats.total_vertex_count = 0;
 | 
			
		||||
		cell->stats.total_gfx_count = 0;
 | 
			
		||||
		cell->stats.gfx_count = 0;
 | 
			
		||||
		cell->stats.vertex_count = 0;
 | 
			
		||||
	} else
 | 
			
		||||
 
 | 
			
		||||
@@ -54,13 +54,6 @@ GdsRenderGui *gds_render_gui_new();
 | 
			
		||||
 */
 | 
			
		||||
GtkWindow *gds_render_gui_get_main_window(GdsRenderGui *gui);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief gds_render_gui_open_gds Open a GDS file. Emulates the manual load via GUI open button
 | 
			
		||||
 * @param self GUI instance
 | 
			
		||||
 * @param path file path
 | 
			
		||||
 */
 | 
			
		||||
void gds_render_gui_open_gds(GdsRenderGui *self, const char *path);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										41
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								main.c
									
									
									
									
									
								
							@@ -40,8 +40,6 @@
 | 
			
		||||
struct application_data {
 | 
			
		||||
		GtkApplication *app;
 | 
			
		||||
		GList *gui_list;
 | 
			
		||||
		gint num_files_to_open;
 | 
			
		||||
		GFile **files;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -98,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);
 | 
			
		||||
@@ -160,7 +163,6 @@ static void gapp_activate(GApplication *app, gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
	GtkWindow *main_window;
 | 
			
		||||
	GdsRenderGui *gui;
 | 
			
		||||
	char *open_file_path;
 | 
			
		||||
	struct application_data * const appdata = (struct application_data *)user_data;
 | 
			
		||||
 | 
			
		||||
	gui = gds_render_gui_new();
 | 
			
		||||
@@ -169,32 +171,11 @@ static void gapp_activate(GApplication *app, gpointer user_data)
 | 
			
		||||
	g_signal_connect(gui, "window-closed", G_CALLBACK(gui_window_closed_callback), &appdata->gui_list);
 | 
			
		||||
 | 
			
		||||
	main_window = gds_render_gui_get_main_window(gui);
 | 
			
		||||
	if (appdata->num_files_to_open >= 1) {
 | 
			
		||||
		/* Open first file. Multiple files are not supported and ignored */
 | 
			
		||||
		open_file_path = g_file_get_path(appdata->files[0]);
 | 
			
		||||
		gds_render_gui_open_gds(gui, open_file_path);
 | 
			
		||||
		g_free(open_file_path);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	gtk_application_add_window(GTK_APPLICATION(app), main_window);
 | 
			
		||||
	gtk_widget_show(GTK_WIDGET(main_window));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Activation of GUI when opening a file from commandline
 | 
			
		||||
 * @param app he GApplication reference
 | 
			
		||||
 * @param user_data Used to store the individual GUI instances.
 | 
			
		||||
 */
 | 
			
		||||
static void gapp_activate_open(GApplication *app, GFile** files, gint n_files, const gchar* hint, gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
	(void)hint;
 | 
			
		||||
	struct application_data *appdata = (struct application_data *)user_data;
 | 
			
		||||
 | 
			
		||||
	appdata->files = files;
 | 
			
		||||
	appdata->num_files_to_open = n_files;
 | 
			
		||||
 | 
			
		||||
	gapp_activate(app, user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Start the graphical interface.
 | 
			
		||||
 *
 | 
			
		||||
@@ -212,9 +193,7 @@ static int start_gui(int argc, char **argv)
 | 
			
		||||
	GString *application_domain;
 | 
			
		||||
	int app_status;
 | 
			
		||||
	static struct application_data appdata = {
 | 
			
		||||
		.gui_list = NULL,
 | 
			
		||||
		.num_files_to_open = 0,
 | 
			
		||||
		.files = NULL,
 | 
			
		||||
		.gui_list = NULL
 | 
			
		||||
	};
 | 
			
		||||
	GMenu *menu;
 | 
			
		||||
	GMenu *m_quit;
 | 
			
		||||
@@ -227,11 +206,10 @@ static int start_gui(int argc, char **argv)
 | 
			
		||||
	application_domain = g_string_new(NULL);
 | 
			
		||||
	g_string_printf(application_domain, "de.shimatta.gds_render_%s", _app_git_commit);
 | 
			
		||||
 | 
			
		||||
	gapp = gtk_application_new(application_domain->str, G_APPLICATION_HANDLES_OPEN);
 | 
			
		||||
	gapp = gtk_application_new(application_domain->str, G_APPLICATION_FLAGS_NONE);
 | 
			
		||||
	g_string_free(application_domain, TRUE);
 | 
			
		||||
 | 
			
		||||
	g_application_register(G_APPLICATION(gapp), NULL, NULL);
 | 
			
		||||
	g_signal_connect(gapp, "open", G_CALLBACK(gapp_activate_open), &appdata);
 | 
			
		||||
	g_signal_connect(gapp, "activate", G_CALLBACK(gapp_activate), &appdata);
 | 
			
		||||
 | 
			
		||||
	if (g_application_get_is_remote(G_APPLICATION(gapp)) == TRUE) {
 | 
			
		||||
@@ -338,8 +316,7 @@ int main(int argc, char **argv)
 | 
			
		||||
		goto ret_status;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* A minimum of a file name and a cell or analyze command are needed to use CLI */
 | 
			
		||||
	if (argc >= 2 && (analyze || cellname || output_paths)) {
 | 
			
		||||
	if (argc >= 2) {
 | 
			
		||||
		if (scale < 1) {
 | 
			
		||||
			printf(_("Scale < 1 not allowed. Setting to 1\n"));
 | 
			
		||||
			scale = 1;
 | 
			
		||||
 
 | 
			
		||||
@@ -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