diff --git a/opengl/CyOpenGL.pyx b/opengl/CyOpenGL.pyx index ef2fd8e3..c453642c 100644 --- a/opengl/CyOpenGL.pyx +++ b/opengl/CyOpenGL.pyx @@ -23,6 +23,8 @@ from math import sqrt, ceil, floor, pi, sin, cos, tan from random import random import time +from tkinter_gl import GLCanvas + Togl_dir = os.path.abspath(os.path.dirname(togl.__file__)) import tkinter as Tk_ diff --git a/opengl/modern/simple_image_shader_widget.pyx b/opengl/modern/simple_image_shader_widget.pyx index 72404869..79d25bd1 100644 --- a/opengl/modern/simple_image_shader_widget.pyx +++ b/opengl/modern/simple_image_shader_widget.pyx @@ -1,4 +1,4 @@ -class SimpleImageShaderWidget(RawOpenGLWidget): +class SimpleImageShaderWidget(GLCanvas): """ An image shader is a GLSL program that does all of its computation in the fragment shader. @@ -41,9 +41,10 @@ class SimpleImageShaderWidget(RawOpenGLWidget): } """ - def __init__(self, master, - **kw): - RawOpenGLWidget.__init__(self, master, **kw) + report_gl_errors = False + + def __init__(self, parent, **kw): + super().__init__(parent, **kw) self._vertex_buffer = VertexBuffer() self._vertex_buffer.load(((3,-1), (-1,3), (-1,-1))) @@ -153,8 +154,7 @@ class SimpleImageShaderWidget(RawOpenGLWidget): raise Exception("Incomplete framebuffer") # Render into the framebuffer - self.redraw(width, height, - skip_swap_buffers = True) + self.draw_impl(width, height) glFinish() # Allocate memory and read framebuffer into it @@ -208,9 +208,8 @@ class SimpleImageShaderWidget(RawOpenGLWidget): self.make_current() - self.redraw(width, height, - skip_swap_buffers = True, - include_depth_value = True) + self.draw_impl(width, height, + include_depth_value = True) glFinish() glReadPixels(x, height - y, 1, 1, @@ -219,10 +218,9 @@ class SimpleImageShaderWidget(RawOpenGLWidget): return (depth, width, height) - def redraw(self, width, height, - skip_swap_buffers = False, - include_depth_value = False): - + def draw_impl(self, width, height, + include_depth_value = False): + if self.report_time_callback: start_time = time.time() @@ -260,8 +258,16 @@ class SimpleImageShaderWidget(RawOpenGLWidget): glFinish() self.report_time_callback(time.time() - start_time) - if not skip_swap_buffers: - self.swap_buffers() + def draw(self): + width = self.winfo_width() + height = self.winfo_height() + + self.make_current() + self.draw_impl(width, height) + self.swap_buffers() + + if self.report_gl_errors: + print_gl_errors("draw") def get_uniform_bindings(self, view_width, view_height): return { diff --git a/python/raytracing/finite_viewer.py b/python/raytracing/finite_viewer.py index d4ae168a..37d6f70a 100644 --- a/python/raytracing/finite_viewer.py +++ b/python/raytracing/finite_viewer.py @@ -65,7 +65,7 @@ def __init__(self, container, manifold, UniformDictController( self.widget.ui_parameter_dict, 'fov', - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, scale=self.fov_scale, label=self.fov_label, format_string='%.1f') @@ -121,7 +121,7 @@ def create_cusp_areas_frame(self, parent): return frame def checkbox_update(self): - self.widget.redraw_if_initialized() + self.widget.draw() self.focus_viewer() def create_fillings_frame(self, parent): @@ -207,7 +207,7 @@ def create_skeleton_frame(self, parent): row=row, left_end=0.0, right_end=0.35, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, format_string='%.3f') row += 1 @@ -219,7 +219,7 @@ def create_skeleton_frame(self, parent): row=row, left_end=0.0, right_end=1.35, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, format_string='%.3f') row += 1 @@ -231,7 +231,7 @@ def create_skeleton_frame(self, parent): row=row, left_end=0.0, right_end=0.5, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) return frame @@ -251,7 +251,7 @@ def create_quality_frame(self, parent): row=row, left_end=1, right_end=100, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -262,7 +262,7 @@ def create_quality_frame(self, parent): row=row, left_end=1.0, right_end=28.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -273,7 +273,7 @@ def create_quality_frame(self, parent): row=row, left_end=1.0, right_end=4.25, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) return frame @@ -295,7 +295,7 @@ def create_light_frame(self, parent): row=row, left_end=0.0, right_end=0.25, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, format_string='%.3f') row += 1 @@ -307,7 +307,7 @@ def create_light_frame(self, parent): row=row, left_end=0.3, right_end=4.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -318,7 +318,7 @@ def create_light_frame(self, parent): row=row, left_end=0.1, right_end=2.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -329,7 +329,7 @@ def create_light_frame(self, parent): row=row, left_end=0.3, right_end=3.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) return frame @@ -578,7 +578,7 @@ def redraw(self): self.widget.view_state = self.widget.raytracing_data.update_view_state( self.widget.view_state, self.m) - self.widget.redraw_if_initialized() + self.widget.draw() self.widget.after(250, self.redraw) diff --git a/python/raytracing/hyperboloid_navigation.py b/python/raytracing/hyperboloid_navigation.py index 6b5fa7fa..dded2c21 100644 --- a/python/raytracing/hyperboloid_navigation.py +++ b/python/raytracing/hyperboloid_navigation.py @@ -149,7 +149,7 @@ class HyperboloidNavigation: IdealRaytracingData. This is needed to update data such as the view matrix using self.raytracing_data.update_view_state(...). - - self.redraw_if_initialized() to redraw. + - self.draw() to redraw. - self.read_depth_value(x, y) to return the depth value at a pixel. It is used for orbiting about that point. - self.compute_translation_and_inverse_from_pick_point(size, xy, depth) @@ -317,7 +317,7 @@ def process_key_events_and_redraw(self): self.view_state, m) # Redraw - self.redraw_if_initialized() + self.draw() # And schedule another call of this function. # If we don't leave Tk a couple of milliseconds in between, @@ -383,7 +383,7 @@ def tkKeyPress(self, event): self.view = (self.view + 1) % 3 print("Color for rays that have not hit geometry:", _viewModes[self.view]) - self.redraw_if_initialized() + self.draw() if event.keysym == 'p': from snappy.CyOpenGL import get_gl_string @@ -507,7 +507,7 @@ def tkButtonMotion1(self, event): else: return - self.redraw_if_initialized() + self.draw() def tkButtonRelease1(self, event): self.mouse_mode = None diff --git a/python/raytracing/inside_viewer.py b/python/raytracing/inside_viewer.py index a6ceb85a..75ee68b7 100644 --- a/python/raytracing/inside_viewer.py +++ b/python/raytracing/inside_viewer.py @@ -90,7 +90,7 @@ def __init__(self, container, manifold, self.view_scale_slider, self.view_scale_label, self.view_scale_value_label, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) self.widget.report_time_callback = FpsLabelUpdater( self.fps_label) @@ -230,7 +230,7 @@ def create_cusps_frame(self, parent): def perspective_type_changed(self): self.view_scale_controller.update() - self.widget.redraw_if_initialized() + self.widget.draw() def set_perspective_type_and_view_scale(self, perspective_type, view_scale): self.widget.ui_uniform_dict['perspectiveType'][1] = perspective_type @@ -252,7 +252,7 @@ def set_camera_cusp_view(self, which_cusp): self.set_perspective_type_and_view_scale(1, extra_scale * view_scale) def checkbox_update(self): - self.widget.redraw_if_initialized() + self.widget.draw() self.focus_viewer() def create_fillings_frame(self, parent): @@ -420,7 +420,7 @@ def create_eyeball_frame(self, parent): text='Freeze camera body', row=row, column=0, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, gridargs = {'padx' : 8}).checkbox ToolTip(freeze_checkbox, msg=("Keep paper plane/eyeball at the same position " @@ -434,7 +434,7 @@ def create_eyeball_frame(self, parent): text='Crosshairs', row=row, column=1, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, gridargs = {'padx' : 8}) row += 1 @@ -458,7 +458,7 @@ def create_skeleton_frame(self, parent): row=row, left_end=0.0, right_end=0.35, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, format_string='%.3f').scale ToolTip(scale, msg=("Partially show faces of the tetrahedra.")) @@ -486,7 +486,7 @@ def create_skeleton_frame(self, parent): row=row, left_end=0.0, right_end=0.2, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, format_string='%.3f')) row += 1 @@ -499,7 +499,7 @@ def create_skeleton_frame(self, parent): text='desaturate', row=row, column=1, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 return frame @@ -520,7 +520,7 @@ def create_quality_frame(self, parent): row=row, left_end=1, right_end=150, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -531,7 +531,7 @@ def create_quality_frame(self, parent): row=row, left_end=1.0, right_end=28.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -542,7 +542,7 @@ def create_quality_frame(self, parent): row=row, left_end=1.0, right_end=4.25, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) return frame @@ -564,7 +564,7 @@ def create_light_frame(self, parent): row=row, left_end=0.0, right_end=0.25, - update_function=self.widget.redraw_if_initialized, + update_function=self.widget.draw, format_string='%.3f') row += 1 @@ -576,7 +576,7 @@ def create_light_frame(self, parent): row=row, left_end=0.3, right_end=4.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -587,7 +587,7 @@ def create_light_frame(self, parent): row=row, left_end=0.1, right_end=2.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) row += 1 UniformDictController.create_horizontal_scale( @@ -598,7 +598,7 @@ def create_light_frame(self, parent): row=row, left_end=0.3, right_end=3.0, - update_function=self.widget.redraw_if_initialized) + update_function=self.widget.draw) return frame @@ -944,7 +944,7 @@ def redraw(self): self.widget.view_state = self.widget.raytracing_data.update_view_state( self.widget.view_state, self.m) - self.widget.redraw_if_initialized() + self.widget.draw() self.widget.after(250, self.redraw) diff --git a/python/raytracing/raytracing_view.py b/python/raytracing/raytracing_view.py index 73b3caed..47e1d5bc 100644 --- a/python/raytracing/raytracing_view.py +++ b/python/raytracing/raytracing_view.py @@ -241,18 +241,18 @@ def _unguarded_initialize_raytracing_data(self): def update_shader_and_redraw(self): self._update_shader() - self.redraw_if_initialized() + self.draw() def recompute_raytracing_data_and_redraw(self): self._initialize_raytracing_data() self.fix_view_state() - self.redraw_if_initialized() + self.draw() def recompute_raytracing_data_update_shader_and_redraw(self): self._initialize_raytracing_data() self._update_shader() self.fix_view_state() - self.redraw_if_initialized() + self.draw() def compute_translation_and_inverse_from_pick_point( self, size, frag_coord, depth): @@ -352,7 +352,7 @@ def _update_geodesic_data(self): def update_geodesic_data_and_redraw(self): success = self._update_geodesic_data() self._update_shader() - self.redraw_if_initialized() + self.draw() return success def disable_edges_for_geodesics(self): diff --git a/setup.py b/setup.py index 3592c5bb..e93c2f3a 100644 --- a/setup.py +++ b/setup.py @@ -502,7 +502,7 @@ def add(self, source_file, dependency_mod_time=0.0): install_requires = ['plink>=2.4.2', 'spherogram>=2.2', 'FXrays>=1.3', 'snappy_manifolds>=1.2', 'low_index>=1.2', - 'pypng', 'decorator', 'packaging'] + 'pypng', 'decorator', 'packaging', 'tkinter_gl'] try: import sage except ImportError: