summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-08-06 23:16:59 +0200
committerGuillaume Seguin <guillaume@segu.in>2007-08-06 23:16:59 +0200
commita9a4ad6fc366bb3599ea2b2dc6a07808e7b39ac0 (patch)
treee7df9ae323467ea7a83acca73a62f03b01cac5ee
parent0da0834bc489bb35b1dc32300ffce99076ed0fef (diff)
downloadgshaderedit-a9a4ad6fc366bb3599ea2b2dc6a07808e7b39ac0.tar.gz
gshaderedit-a9a4ad6fc366bb3599ea2b2dc6a07808e7b39ac0.tar.bz2
* Update previewArea class
o Use drawable_begin and drawable_end everywhere they are needed o Draw cairo surface after dumping it
-rw-r--r--gShaderEdit/previewarea.py53
1 files changed, 31 insertions, 22 deletions
diff --git a/gShaderEdit/previewarea.py b/gShaderEdit/previewarea.py
index 52a04d7..2880e38 100644
--- a/gShaderEdit/previewarea.py
+++ b/gShaderEdit/previewarea.py
@@ -129,21 +129,39 @@ class previewArea (gtk.gtkgl.DrawingArea):
self.connect ("expose_event", self.on_expose_event)
self.connect ("configure_event", self.on_configure_event)
+ def drawable_begin (self):
+ '''Call gl_begin on current GL Drawable'''
+ gldrawable = self.get_gl_drawable ()
+ glcontext = self.get_gl_context ()
+ if not gldrawable.gl_begin (glcontext):
+ return False
+ else:
+ return gldrawable
+
+ def drawable_end (self):
+ '''Call gl_end on current GL Drawable'''
+ gldrawable = self.get_gl_drawable ()
+ return gldrawable.gl_end ()
+
def delete_texture (self):
'''Delete current texture'''
if self.tex_id:
+ self.drawable_begin ()
glDeleteTextures (self.tex_id)
self.tex_id = None
+ self.drawable_end ()
def load_texture (self, file = None, surface = None):
'''Load a texture from a file'''
self.delete_texture ()
+ self.drawable_begin ()
if file:
tex = create_texture_from_file (file)
elif surface:
tex = create_texture_from_surface (surface)
else:
raise RuntimeError, _("File and surface can't both be None")
+ self.drawable_end ()
self.tex_id, self.tex_width, self.tex_height = tex
def get_tex_coord (self):
@@ -159,9 +177,7 @@ class previewArea (gtk.gtkgl.DrawingArea):
self.queue_draw ()
def draw (self):
- gldrawable = self.get_gl_drawable ()
- glcontext = self.get_gl_context ()
- gldrawable.gl_begin (glcontext)
+ gldrawable = self.drawable_begin ()
glClear (GL_COLOR_BUFFER_BIT)
if self.program and self.program.id.value != 0:
glEnable (self.program.type)
@@ -177,7 +193,7 @@ class previewArea (gtk.gtkgl.DrawingArea):
glFlush ()
if self.program and self.program.id.value != 0:
glDisable (self.program.type)
- gldrawable.gl_end ()
+ self.drawable_end ()
def draw_texture (self):
'''Draw the texture'''
@@ -201,18 +217,13 @@ class previewArea (gtk.gtkgl.DrawingArea):
def on_configure_event (self, *args):
'''Configure event callback, set current GL viewport'''
- gldrawable = self.get_gl_drawable ()
- glcontext = self.get_gl_context ()
- gldrawable.gl_begin (glcontext)
+ self.drawable_begin ()
glViewport (0, 0, self.viewport_width, self.viewport_height)
- gldrawable.gl_end ()
+ self.drawable_end ()
def on_realize (self, *args):
'''Initialize GL context'''
- gldrawable = self.get_gl_drawable ()
- glcontext = self.get_gl_context ()
-
- if not gldrawable.gl_begin (glcontext):
+ if not self.drawable_begin ():
return
check_gl_extensions ()
@@ -233,7 +244,8 @@ class previewArea (gtk.gtkgl.DrawingArea):
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
- gldrawable.gl_end ()
+
+ self.drawable_end ()
self.queue_draw ()
@@ -242,7 +254,6 @@ class previewArea (gtk.gtkgl.DrawingArea):
if not self.surface:
self.draw ()
self.dump ()
- return
cr = self.window.cairo_create ()
cr.rectangle (event.area.x, event.area.y,
event.area.width, event.area.height)
@@ -257,6 +268,7 @@ class previewArea (gtk.gtkgl.DrawingArea):
def dump (self):
'''Dump current GL context pixels into a cairo surface'''
+ self.drawable_begin ()
glPixelStorei (GL_PACK_ALIGNMENT, 1)
tex_x, tex_y = self.get_tex_coord ()
# Dump pixels to a string
@@ -277,27 +289,24 @@ class previewArea (gtk.gtkgl.DrawingArea):
cr.transform (matrix)
cr.set_source_surface (s)
cr.paint ()
+ self.drawable_end ()
# Useful user functions
def create_program (self, source):
'''Create a fragment program for the given source'''
if self.program and self.program.source == source:
return
- gldrawable = self.get_gl_drawable ()
- glcontext = self.get_gl_context ()
- gldrawable.gl_begin (glcontext)
+ self.drawable_begin ()
self.delete_program (redraw = False)
self.program = FragmentProgram (self.parent, source)
- gldrawable.gl_end ()
+ self.drawable_end ()
self.redraw ()
def delete_program (self, redraw = True):
'''Clean current program if required'''
if self.program:
- gldrawable = self.get_gl_drawable ()
- glcontext = self.get_gl_context ()
- gldrawable.gl_begin (glcontext)
+ self.drawable_begin ()
del self.program
- gldrawable.gl_end ()
+ self.drawable_end ()
if redraw:
self.redraw ()