diff options
author | Sven Gothel <[email protected]> | 2014-05-21 08:53:54 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-05-21 08:53:54 +0200 |
commit | f9a00b91dcd146c72a50237b62270f33bd0da98e (patch) | |
tree | f4387da868608cea5066ce3a8cb9039a16b529de /src/jogl/native/macosx | |
parent | 0ffba122ea5c4b8cc247234ca9f48ccfcce833cd (diff) |
Bug 742 HiDPI: [Core API Change] Distinguish window-units and pixel-units; Add HiDPI for AWT GLCanvas w/ OSX CALayer
Core API Change:
To support HiDPI thoroughly in JOGL (NativeWindow, JOGL, NEWT)
we need to separate window- and pixel units.
NativeWindow and NativeSurface now have distinguished
access methods for window units and pixel units.
NativeWindow: Using window units
- getWindowWidth() * NEW Method *
- getWindowHeight() * NEW Method *
- getX(), getY(), ...
NativeSurface: Using pixel units
- getWidth() -> getSurfaceWidth() * RENAMED *
- getHeight() -> getSurfaceHeight() * RENAMED *
GLDrawable: Using pixel units
- getWidth() -> getSurfaceWidth() * RENAMED, aligned w/ NativeSurface *
- getHeight() -> getSurfaceHeight() * RENAMED, aligned w/ NativeSurface *
Above changes also removes API collision w/ other windowing TK,
e.g. AWT's getWidth()/getHeight() in GLCanvas
and the same method names in GLDrawable before this change.
+++
Now preliminary 'working':
- AWT GLCanvas
- AWT GLJPanel
Tested manually on OSX w/ and w/o HiDPI Retina:
java com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT -manual -noanim -time 1000000
java com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT -manual -noanim -time 1000000
+++
TODO:
- NEWT
- Change Window.setSize(..) to use pixel units ?
- OSX HiDPI support
- Testing ..
- API refinement
Diffstat (limited to 'src/jogl/native/macosx')
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m | 62 | ||||
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface.h | 2 |
2 files changed, 45 insertions, 19 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m index 7ce8c58cf..fb6fd18e9 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m @@ -194,7 +194,9 @@ extern GLboolean glIsVertexArray (GLuint array); texIDArg: (GLuint) texID opaque: (Bool) opaque texWidth: (int) texWidth - texHeight: (int) texHeight; + texHeight: (int) texHeight + winWidth: (int)winWidth + winHeight: (int)winHeight; - (void)releaseLayer; - (void)deallocPBuffer; @@ -206,7 +208,7 @@ extern GLboolean glIsVertexArray (GLuint array); - (Bool)isGLSourceValid; - (void) setGLEnabled: (Bool) enable; -- (Bool) validateTexSize: (CGRect) lRect; +- (Bool) validateTexSize: (int)newTexWidth height:(int)newTexHeight; - (void) setTextureID: (int) _texID; - (Bool) isSamePBuffer: (NSOpenGLPixelBuffer*) p; @@ -274,7 +276,9 @@ static const GLfloat gl_verts[] = { texIDArg: (GLuint) texID opaque: (Bool) opaque texWidth: (int) _texWidth - texHeight: (int) _texHeight; + texHeight: (int) _texHeight + winWidth: (int) _winWidth + winHeight: (int) _winHeight { pthread_mutexattr_t renderLockAttr; pthread_mutexattr_init(&renderLockAttr); @@ -288,6 +292,13 @@ static const GLfloat gl_verts[] = { gl_texCoords[i] = 0.0f; } } + if( _texWidth != _winWidth ) { +NS_DURING + // Available >= 10.7 + [self setContentsScale: (CGFloat)_texWidth/(CGFloat)_winWidth]; +NS_HANDLER +NS_ENDHANDLER + } parentPixelFmt = [_parentPixelFmt retain]; // until destruction glContext = [[MyNSOpenGLContext alloc] initWithFormat:parentPixelFmt shareContext:parentCtx]; gl3ShaderProgramName = _gl3ShaderProgramName; @@ -301,8 +312,8 @@ static const GLfloat gl_verts[] = { shallDraw = NO; isGLEnabled = YES; dedicatedFrameSet = NO; - dedicatedFrame = CGRectMake(0, 0, _texWidth, _texHeight); - [self validateTexSize: dedicatedFrame]; + dedicatedFrame = CGRectMake(0, 0, _winWidth, _winHeight); + [self validateTexSize: _texWidth height:_texHeight]; [self setTextureID: texID]; newPBuffer = NULL; @@ -383,15 +394,17 @@ static const GLfloat gl_verts[] = { isGLEnabled = enable; } -- (Bool) validateTexSize: (CGRect) lRect +- (Bool) validateTexSize: (int)newTexWidth height:(int)newTexHeight { - const int lRectW = (int) (lRect.size.width + 0.5f); - const int lRectH = (int) (lRect.size.height + 0.5f); Bool changed; - if( lRectH != texHeight || lRectW != texWidth ) { - texWidth = lRectW; - texHeight = lRectH; + if( newTexHeight != texHeight || newTexWidth != texWidth ) { + #ifdef VERBOSE_ON + const int oldTexWidth = texWidth; + const int oldTexHeight = texHeight; + #endif + texWidth = newTexWidth; + texHeight = newTexHeight; changed = YES; GLfloat texCoordWidth, texCoordHeight; @@ -415,10 +428,14 @@ static const GLfloat gl_verts[] = { gl_texCoords[4] = texCoordWidth; gl_texCoords[6] = texCoordWidth; #ifdef VERBOSE_ON - DBG_PRINT("MyNSOpenGLLayer::validateTexSize %p -> tex %dx%d, bounds: %lf/%lf %lfx%lf (%dx%d), dedicatedFrame set:%d %lf/%lf %lfx%lf\n", - self, texWidth, texHeight, - lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height, lRectW, lRectH, - dedicatedFrameSet, dedicatedFrame.origin.x, dedicatedFrame.origin.y, dedicatedFrame.size.width, dedicatedFrame.size.height); +NS_DURING + // Available >= 10.7 + DBG_PRINT("MyNSOpenGLLayer::validateTexSize %p: tex %dx%d -> %dx%d, dedicatedFrame set:%d %lf/%lf %lfx%lf scale %lf\n", + self, oldTexWidth, oldTexHeight, newTexWidth, newTexHeight, + dedicatedFrameSet, dedicatedFrame.origin.x, dedicatedFrame.origin.y, dedicatedFrame.size.width, dedicatedFrame.size.height, + [self contentsScale]); +NS_HANDLER +NS_ENDHANDLER #endif } else { changed = NO; @@ -638,7 +655,15 @@ static const GLfloat gl_verts[] = { GLenum textureTarget; - Bool texSizeChanged = [self validateTexSize: ( dedicatedFrameSet ? dedicatedFrame : [self bounds] ) ]; + CGRect texDim = dedicatedFrameSet ? dedicatedFrame : [self bounds]; + CGFloat _contentsScale = 1; +NS_DURING + // Available >= 10.7 + _contentsScale = [self contentsScale]; +NS_HANDLER +NS_ENDHANDLER + Bool texSizeChanged = [self validateTexSize: (int)(texDim.size.width * _contentsScale + 0.5f) + height:(int)(texDim.size.height * _contentsScale + 0.5f)]; if( texSizeChanged ) { [context update]; } @@ -873,9 +898,10 @@ static const GLfloat gl_verts[] = { @end -NSOpenGLLayer* createNSOpenGLLayer(NSOpenGLContext* ctx, int gl3ShaderProgramName, NSOpenGLPixelFormat* fmt, NSOpenGLPixelBuffer* p, uint32_t texID, Bool opaque, int texWidth, int texHeight) { +NSOpenGLLayer* createNSOpenGLLayer(NSOpenGLContext* ctx, int gl3ShaderProgramName, NSOpenGLPixelFormat* fmt, NSOpenGLPixelBuffer* p, uint32_t texID, Bool opaque, int texWidth, int texHeight, int winWidth, int winHeight) { return [[[MyNSOpenGLLayer alloc] init] setupWithContext:ctx gl3ShaderProgramName: (GLuint)gl3ShaderProgramName pixelFormat: fmt pbuffer: p texIDArg: (GLuint)texID - opaque: opaque texWidth: texWidth texHeight: texHeight]; + opaque: opaque texWidth: texWidth texHeight: texHeight + winWidth: winWidth winHeight: winHeight]; } void setNSOpenGLLayerEnabled(NSOpenGLLayer* layer, Bool enable) { diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.h b/src/jogl/native/macosx/MacOSXWindowSystemInterface.h index 138accb22..b2d7f9db8 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.h +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.h @@ -3,7 +3,7 @@ #import <OpenGL/CGLTypes.h> #import <jni.h> -// #define VERBOSE_ON 1 +#define VERBOSE_ON 1 #ifdef VERBOSE_ON #define DBG_PRINT(...) NSLog(@ __VA_ARGS__) |