diff options
author | Gerard Ziemski <[email protected]> | 2003-11-08 19:47:35 +0000 |
---|---|---|
committer | Gerard Ziemski <[email protected]> | 2003-11-08 19:47:35 +0000 |
commit | 532413bb45e35852429ec062ca27d95f6900a9b6 (patch) | |
tree | e97d32a8ba84a2d2139a7b86028c6295d87ec3f1 /src | |
parent | 61181baab239670cbc24d84110ac923c2972aa4e (diff) |
use USE_GL_TEXTURE_RECTANGLE_EXT for PBuffers - needed for GLJPanel
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@72 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
-rw-r--r-- | src/native/jogl/MacOSXWindowSystemInterface.m | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/src/native/jogl/MacOSXWindowSystemInterface.m b/src/native/jogl/MacOSXWindowSystemInterface.m index 2d812ec58..f72170b69 100644 --- a/src/native/jogl/MacOSXWindowSystemInterface.m +++ b/src/native/jogl/MacOSXWindowSystemInterface.m @@ -2,8 +2,13 @@ #import <OpenGL/gl.h> #import "ContextUpdater.h" -#ifndef GL_TEXTURE_RECTANGLE_EXT - #define GL_TEXTURE_RECTANGLE_EXT 0x84F5 +// see MacOSXPbufferGLContext.java createPbuffer +#define USE_GL_TEXTURE_RECTANGLE_EXT + +#ifdef USE_GL_TEXTURE_RECTANGLE_EXT + #ifndef GL_TEXTURE_RECTANGLE_EXT + #define GL_TEXTURE_RECTANGLE_EXT 0x84F5 + #endif #endif typedef int Bool; @@ -32,7 +37,7 @@ void* createContext(void* shareContext, void* view) return NULL; } } - + if (gAutoreleasePool == NULL) { gAutoreleasePool = [[NSAutoreleasePool alloc] init]; @@ -56,11 +61,6 @@ void* createContext(void* shareContext, void* view) 0 }; - if (nsView == NULL) - { - attribs[12] = 0; // no stencil, no accums for pBuffers - } - NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; NSOpenGLContext* nsContext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nsChareCtx]; @@ -73,9 +73,10 @@ void* createContext(void* shareContext, void* view) [nsView unlockFocus]; } - + [nsContext retain]; +//fprintf(stderr, " nsContext=%p\n", nsContext); return nsContext; } @@ -140,6 +141,7 @@ void updateContextUnregister(void* context, void* view, void* updater) [contextUpdater release]; } +#ifndef USE_GL_TEXTURE_RECTANGLE_EXT static int getNextPowerOf2(int number) { if (((number-1) & number) == 0) @@ -155,23 +157,28 @@ static int getNextPowerOf2(int number) } return (1<<power); } +#endif void* createPBuffer(void* context, int width, int height) { -//fprintf(stderr, "createPBuffer context=%p width=%d height=%d\n", context, width, height); +///fprintf(stderr, "createPBuffer context=%p width=%d height=%d\n", context, width, height); #ifdef AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER) NSOpenGLContext *nsContext = (NSOpenGLContext*)context; - //unsigned long taget = GL_TEXTURE_RECTANGLE_EXT; +#ifdef USE_GL_TEXTURE_RECTANGLE_EXT + unsigned long taget = GL_TEXTURE_RECTANGLE_EXT; +#else unsigned long taget = GL_TEXTURE_2D; // texture size must be a multiple of power of 2 - width = getNextPowerOf2(width); - height = getNextPowerOf2(height); - + width = getNextPowerOf2(width); + height = getNextPowerOf2(height); +#endif + NSOpenGLPixelBuffer* pBuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:taget textureInternalFormat:GL_RGBA textureMaxMipMapLevel:0 pixelsWide:width pixelsHigh:height]; [nsContext setPixelBuffer:pBuffer cubeMapFace:0 mipMapLevel:0 currentVirtualScreen:0]; - + [nsContext update]; + return pBuffer; #else return NULL; @@ -200,7 +207,9 @@ int bindPBuffer(void* context, void* buffer) #ifdef AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER) NSOpenGLContext *nsContext = (NSOpenGLContext*)context; NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer; - + + glPushMatrix(); + GLuint pBufferTextureName; glGenTextures(1, &pBufferTextureName); @@ -214,6 +223,15 @@ int bindPBuffer(void* context, void* buffer) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable([pBuffer textureTarget]); +#ifdef USE_GL_TEXTURE_RECTANGLE_EXT + GLint matrixMode; + glGetIntegerv(GL_MATRIX_MODE, &matrixMode); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glScalef([pBuffer pixelsWide], [pBuffer pixelsHigh], 1.0f); // GL_TEXTURE_RECTANGLE_EXT wants texture coordinates in texture image space (not 0 to 1) + glMatrixMode(matrixMode); +#endif + return pBufferTextureName; #else return 0; @@ -227,8 +245,9 @@ void unbindPBuffer(void* context, void* buffer, int texture) NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer; GLuint pBufferTextureName = (GLuint)texture; - //glDisable([pBuffer textureTarget]); glDeleteTextures(1, &pBufferTextureName); + + glPopMatrix(); #endif } |