[dasher: 8/11] MacOS: fix canvas resizing by re-setting-up OpenGL framebuffers
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 8/11] MacOS: fix canvas resizing by re-setting-up OpenGL framebuffers
- Date: Sat, 31 Jul 2010 14:07:53 +0000 (UTC)
commit a851a9b7f369d1febd0e5e3f84c7645baefac756
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Sat Jun 5 20:56:54 2010 +0100
MacOS: fix canvas resizing by re-setting-up OpenGL framebuffers
Src/MacOSX/DasherViewOpenGL.h | 5 +++-
Src/MacOSX/DasherViewOpenGL.mm | 52 +++++++++++++++++++++++-----------------
2 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/Src/MacOSX/DasherViewOpenGL.h b/Src/MacOSX/DasherViewOpenGL.h
index 8d58522..4eb5b8e 100755
--- a/Src/MacOSX/DasherViewOpenGL.h
+++ b/Src/MacOSX/DasherViewOpenGL.h
@@ -42,7 +42,10 @@ typedef struct {
GLuint frameBuffers[2];
GLuint textures[2];
GLfloat texcoords[8];
-
+
+ ///current (last successful) framebuffer width & height
+ int fw,fh;
+
colour_t *colourTable;
NSMutableDictionary *_letterDict;
diff --git a/Src/MacOSX/DasherViewOpenGL.mm b/Src/MacOSX/DasherViewOpenGL.mm
index abaf937..2c2e1a8 100755
--- a/Src/MacOSX/DasherViewOpenGL.mm
+++ b/Src/MacOSX/DasherViewOpenGL.mm
@@ -290,32 +290,15 @@
[self gl_init];
[self flushCaches];
[self setFrameSize:aFrame.size];
- int w = P2Ceiling(aFrame.size.width), h = P2Ceiling(aFrame.size.height);
- glGenFramebuffersEXT(2, frameBuffers);
- glGenTextures(2, textures);
+ //note these give us framebuffer _references_...
+ glGenFramebuffersEXT(2, frameBuffers);
+ glGenTextures(2, textures);
+ //...i.e. they don't identify any storage at this point!
+ fw = fh = -1;
- for (int i=0; i<2; i++)
- {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffers[i]);
- glBindTexture(GL_TEXTURE_2D, textures[i]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textures[i], 0);
- if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
- {
- NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
- return nil;
- }
- }
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
- GLfloat tc_x = aFrame.size.width/(double)w, tc_y = aFrame.size.height/(double)h;
- texcoords[0] = 0.0; texcoords[1] = tc_y;
- texcoords[2] = tc_x; texcoords[3] = tc_y;
- texcoords[4] = 0.0; texcoords[5] = 0.0;
- texcoords[6] = tc_x; texcoords[7] = 0.0;
_keyboardHelper = new CKeyboardHelper();
}
return self;
@@ -458,6 +441,31 @@
- (void) gl_reshape:(int)w :(int)h
{
[[self openGLContext] makeCurrentContext];
+ int tw = P2Ceiling(w), th = P2Ceiling(h);
+ if (tw!=fw || th!=fh) {
+ //need to (re)allocate storage for framebuffer...
+ for (int i=0; i<2; i++)
+ {
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffers[i]);
+ glBindTexture(GL_TEXTURE_2D, textures[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textures[i], 0);
+ if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
+ {
+ NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
+ //...and do what, to report failure? we can't render anything, so Dasher is useless...?
+ }
+ }
+ fw=tw; fh=th;
+ }
+ GLfloat tc_x = w/(double)tw, tc_y = h/(double)th;
+ texcoords[0] = 0.0; texcoords[1] = tc_y;
+ texcoords[2] = tc_x; texcoords[3] = tc_y;
+ texcoords[4] = 0.0; texcoords[5] = 0.0;
+ texcoords[6] = tc_x; texcoords[7] = 0.0;
+
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]