[Hdrflow-svn] SF.net SVN: hdrflow: [158] trunk/app/HDRFlow
Status: Pre-Alpha
Brought to you by:
glslang
From: <gl...@us...> - 2007-06-24 15:31:55
|
Revision: 158 http://hdrflow.svn.sourceforge.net/hdrflow/?rev=158&view=rev Author: glslang Date: 2007-06-24 08:31:51 -0700 (Sun, 24 Jun 2007) Log Message: ----------- + Cocoa OpenGL initialisation Modified Paths: -------------- trunk/app/HDRFlow/English.lproj/MainMenu.nib/classes.nib trunk/app/HDRFlow/English.lproj/MainMenu.nib/info.nib trunk/app/HDRFlow/English.lproj/MainMenu.nib/keyedobjects.nib trunk/app/HDRFlow/HDRFlow.xcodeproj/project.pbxproj Added Paths: ----------- trunk/app/HDRFlow/CustomOpenGLView.h trunk/app/HDRFlow/CustomOpenGLView.m trunk/app/HDRFlow/ViewportOpenGLView.h trunk/app/HDRFlow/ViewportOpenGLView.m Added: trunk/app/HDRFlow/CustomOpenGLView.h =================================================================== --- trunk/app/HDRFlow/CustomOpenGLView.h (rev 0) +++ trunk/app/HDRFlow/CustomOpenGLView.h 2007-06-24 15:31:51 UTC (rev 158) @@ -0,0 +1,33 @@ + +// HDRFlow - A image processing application + +// Copyright (c) 2007 Goncalo N. M. de Carvalho +// Released under the GPL. +// For more information, see http://www.cryogenicgraphics.com/hdrflow. + +#import <Cocoa/Cocoa.h> + +@class NSOpenGLContext, NSOpenGLPixelFormat; + +@interface CustomOpenGLView : NSView +{ +@private + NSOpenGLContext* context_; + NSOpenGLPixelFormat* pixelFormat_; +} + ++ ( NSOpenGLPixelFormat* ) defaultPixelFormat; + +- ( id ) initWithFrame: ( NSRect ) frameRect pixelFormat: ( NSOpenGLPixelFormat* ) format; + +- ( void ) setOpenGLContext: ( NSOpenGLContext* ) context; +- ( NSOpenGLContext* ) openGLContext; +- ( void ) clearGLContext; +- ( void ) prepareOpenGL; + +- ( void ) update; + +- ( void ) setPixelFormat: ( NSOpenGLPixelFormat* ) format; +- ( NSOpenGLPixelFormat* ) pixelFormat; + +@end Added: trunk/app/HDRFlow/CustomOpenGLView.m =================================================================== --- trunk/app/HDRFlow/CustomOpenGLView.m (rev 0) +++ trunk/app/HDRFlow/CustomOpenGLView.m 2007-06-24 15:31:51 UTC (rev 158) @@ -0,0 +1,143 @@ + +// HDRFlow - A image processing application + +// Copyright (c) 2007 Goncalo N. M. de Carvalho +// Released under the GPL. +// For more information, see http://www.cryogenicgraphics.com/hdrflow. + +#import <OpenGL/OpenGL.h> +#import <OpenGL/gl.h> + +#import "CustomOpenGLView.h" + +@implementation CustomOpenGLView + ++ ( NSOpenGLPixelFormat* ) defaultPixelFormat +{ + NSOpenGLPixelFormatAttribute attribs[ ] = { 0 }; + return [ [ ( NSOpenGLPixelFormat* ) [ NSOpenGLPixelFormat alloc ] initWithAttributes: attribs ] autorelease ]; +} + +- ( id ) initWithFrame: ( NSRect ) frameRect pixelFormat: ( NSOpenGLPixelFormat* ) format +{ + self = [ super initWithFrame: frameRect ]; + if( self != nil ) + pixelFormat_ = [ format retain ]; + [ [ NSNotificationCenter defaultCenter ] addObserver: self selector: @selector( _surfaceNeedsUpdate: ) name: NSViewGlobalFrameDidChangeNotification object: self ]; + return self; +} + +- ( void ) dealloc +{ + [ [ NSNotificationCenter defaultCenter ] removeObserver: self name: NSViewGlobalFrameDidChangeNotification object: self ]; + [ self clearGLContext ]; + [ pixelFormat_ release ]; + + [ super dealloc ]; +} + +- ( void ) setOpenGLContext: ( NSOpenGLContext* ) context +{ + [ self clearGLContext ]; + context_ = [ context retain ]; +} + +- ( NSOpenGLContext* ) openGLContext +{ + if( context_ == NULL ) + { + context_ = [ [ NSOpenGLContext alloc ] initWithFormat: pixelFormat_ != nil ? pixelFormat_ : [ [ self class ] defaultPixelFormat ] shareContext: nil ]; + [ context_ makeCurrentContext ]; + [ self prepareOpenGL ]; + } + + return context_; +} + +- ( void ) clearGLContext +{ + if( context_ != nil ) + { + if( [ context_ view ] == self ) + [ context_ clearDrawable ]; + + [ context_ release ]; + context_ = nil; + } +} + +- ( void ) prepareOpenGL +{ +} + +- ( BOOL ) isOpaque +{ + return YES; +} + +- ( void ) setPixelFormat: ( NSOpenGLPixelFormat* ) pixelFormat +{ + [ pixelFormat_ release ]; + pixelFormat_ = [ pixelFormat retain ]; +} + +- ( NSOpenGLPixelFormat* ) pixelFormat +{ + return pixelFormat_; +} + +- ( void ) lockFocus +{ + NSOpenGLContext* context = [ self openGLContext ]; + + [ super lockFocus ]; + + if( [ context view ] != self ) + [ context setView: self ]; + + [ context makeCurrentContext ]; +} + +- ( void ) update +{ + if( [ context_ view ] == self ) + [ context_ update ]; +} + +- ( void ) _surfaceNeedsUpdate: ( NSNotification* ) notification +{ + [ self update ]; +} + +- ( void ) encodeWithCoder: ( NSCoder* ) coder +{ + [ super encodeWithCoder: coder ]; + if( ![ coder allowsKeyedCoding ] ) + { + [ coder encodeValuesOfObjCTypes: "@iii", &pixelFormat_ ]; + } + else + { + [ coder encodeObject: pixelFormat_ forKey: @"NSPixelFormat" ]; + } +} + +- ( id ) initWithCoder: ( NSCoder* ) coder +{ + self = [ super initWithCoder: coder ]; + + if( ![ coder allowsKeyedCoding ] ) + { + [ coder decodeValuesOfObjCTypes: "@iii", &pixelFormat_ ]; + } + else + { + pixelFormat_ = [ [ coder decodeObjectForKey: @"NSPixelFormat" ] retain ]; + } + + [ [ NSNotificationCenter defaultCenter ] addObserver: self selector: @selector( _surfaceNeedsUpdate: ) name: NSViewGlobalFrameDidChangeNotification object: self ]; + + return self; +} + +@end Modified: trunk/app/HDRFlow/English.lproj/MainMenu.nib/classes.nib =================================================================== --- trunk/app/HDRFlow/English.lproj/MainMenu.nib/classes.nib 2007-06-23 20:31:49 UTC (rev 157) +++ trunk/app/HDRFlow/English.lproj/MainMenu.nib/classes.nib 2007-06-24 15:31:51 UTC (rev 158) @@ -1,4 +1,8 @@ { - IBClasses = ({CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }); + IBClasses = ( + {CLASS = CustomOpenGLView; LANGUAGE = ObjC; SUPERCLASS = NSView; }, + {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, + {CLASS = ViewportOpenGLView; LANGUAGE = ObjC; SUPERCLASS = CustomOpenGLView; } + ); IBVersion = 1; } \ No newline at end of file Modified: trunk/app/HDRFlow/English.lproj/MainMenu.nib/info.nib =================================================================== --- trunk/app/HDRFlow/English.lproj/MainMenu.nib/info.nib 2007-06-23 20:31:49 UTC (rev 157) +++ trunk/app/HDRFlow/English.lproj/MainMenu.nib/info.nib 2007-06-24 15:31:51 UTC (rev 158) @@ -3,20 +3,20 @@ <plist version="1.0"> <dict> <key>IBDocumentLocation</key> - <string>94 103 356 240 0 0 1280 1002 </string> + <string>472 85 356 240 0 0 1440 878 </string> <key>IBEditorPositions</key> <dict> <key>29</key> - <string>93 343 318 44 0 0 1280 1002 </string> + <string>109 299 338 44 0 0 1440 878 </string> </dict> <key>IBFramework Version</key> - <string>401.0</string> + <string>446.1</string> <key>IBOpenObjects</key> <array> + <integer>21</integer> <integer>29</integer> - <integer>21</integer> </array> <key>IBSystem Version</key> - <string>8A259</string> + <string>8R2218</string> </dict> </plist> Modified: trunk/app/HDRFlow/English.lproj/MainMenu.nib/keyedobjects.nib =================================================================== (Binary files differ) Modified: trunk/app/HDRFlow/HDRFlow.xcodeproj/project.pbxproj =================================================================== --- trunk/app/HDRFlow/HDRFlow.xcodeproj/project.pbxproj 2007-06-23 20:31:49 UTC (rev 157) +++ trunk/app/HDRFlow/HDRFlow.xcodeproj/project.pbxproj 2007-06-24 15:31:51 UTC (rev 158) @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 678A4AA70C2B18B50011E9F7 /* CustomOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 678A4AA60C2B18B50011E9F7 /* CustomOpenGLView.m */; }; + 67DC61B90C2EAC94005CFE6E /* ViewportOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 67DC61B80C2EAC94005CFE6E /* ViewportOpenGLView.m */; }; + 67DC62180C2EC0D9005CFE6E /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67DC62170C2EC0D9005CFE6E /* OpenGL.framework */; }; 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; @@ -22,6 +25,11 @@ 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; }; 32CA4F630368D1EE00C91783 /* HDRFlow_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HDRFlow_Prefix.pch; sourceTree = "<group>"; }; + 678A4AA60C2B18B50011E9F7 /* CustomOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = CustomOpenGLView.m; sourceTree = "<group>"; }; + 67DC61B10C2EAB5E005CFE6E /* ViewportOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewportOpenGLView.h; sourceTree = "<group>"; }; + 67DC61B80C2EAC94005CFE6E /* ViewportOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewportOpenGLView.m; sourceTree = "<group>"; }; + 67DC62170C2EC0D9005CFE6E /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; }; + 67F6CCF70C285D6C00098F90 /* CustomOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CustomOpenGLView.h; sourceTree = "<group>"; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; }; 8D1107320486CEB800E47090 /* HDRFlow.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HDRFlow.app; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -32,6 +40,7 @@ buildActionMask = 2147483647; files = ( 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, + 67DC62180C2EC0D9005CFE6E /* OpenGL.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -41,6 +50,10 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 67F6CCF70C285D6C00098F90 /* CustomOpenGLView.h */, + 678A4AA60C2B18B50011E9F7 /* CustomOpenGLView.m */, + 67DC61B10C2EAB5E005CFE6E /* ViewportOpenGLView.h */, + 67DC61B80C2EAC94005CFE6E /* ViewportOpenGLView.m */, ); name = Classes; sourceTree = "<group>"; @@ -48,6 +61,7 @@ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { isa = PBXGroup; children = ( + 67DC62170C2EC0D9005CFE6E /* OpenGL.framework */, 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, ); name = "Linked Frameworks"; @@ -165,6 +179,8 @@ buildActionMask = 2147483647; files = ( 8D11072D0486CEB800E47090 /* main.m in Sources */, + 678A4AA70C2B18B50011E9F7 /* CustomOpenGLView.m in Sources */, + 67DC61B90C2EAC94005CFE6E /* ViewportOpenGLView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Added: trunk/app/HDRFlow/ViewportOpenGLView.h =================================================================== --- trunk/app/HDRFlow/ViewportOpenGLView.h (rev 0) +++ trunk/app/HDRFlow/ViewportOpenGLView.h 2007-06-24 15:31:51 UTC (rev 158) @@ -0,0 +1,21 @@ + +// HDRFlow - A image processing application + +// Copyright (c) 2007 Goncalo N. M. de Carvalho +// Released under the GPL. +// For more information, see http://www.cryogenicgraphics.com/hdrflow. + +#import "CustomOpenGLView.h" + +@interface ViewportOpenGLView : CustomOpenGLView +{ +} + ++ ( NSOpenGLPixelFormat* ) pixelFormat; + +- ( id ) initWithFrame: ( NSRect ) theFrame; +- ( void ) dealloc; +- ( void ) drawRect: ( NSRect ) theRect; +- ( void ) update; + +@end Added: trunk/app/HDRFlow/ViewportOpenGLView.m =================================================================== --- trunk/app/HDRFlow/ViewportOpenGLView.m (rev 0) +++ trunk/app/HDRFlow/ViewportOpenGLView.m 2007-06-24 15:31:51 UTC (rev 158) @@ -0,0 +1,78 @@ + +// HDRFlow - A image processing application + +// Copyright (c) 2007 Goncalo N. M. de Carvalho +// Released under the GPL. +// For more information, see http://www.cryogenicgraphics.com/hdrflow. + +#import <OpenGL/OpenGL.h> +#import <OpenGL/gl.h> + +#import "ViewportOpenGLView.h" + +@implementation ViewportOpenGLView + ++ ( NSOpenGLPixelFormat* ) pixelFormat +{ + NSOpenGLPixelFormatAttribute attribs[ ] = + { + NSOpenGLPFAWindow, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFADepthSize, 24, + NSOpenGLPFAStencilSize, 8, + 0 + }; + + return [ [ [ NSOpenGLPixelFormat alloc ] initWithAttributes: attribs ] autorelease ]; +} + +- ( id ) initWithFrame: ( NSRect ) theFrame +{ + [ super initWithFrame: theFrame pixelFormat: [ self pixelFormat ] ]; + [ [ super openGLContext ] makeCurrentContext ]; + + return self; +} + +- ( void ) dealloc +{ + [ super dealloc ]; +} + +- ( void ) renewGState +{ + NSWindow* window; + [ super renewGState ]; + window = [ self window ]; + + if( [ window respondsToSelector: @selector( disableScreenUpdatesUntilFlush ) ] ) + [ window disableScreenUpdatesUntilFlush ]; +} + +- ( void ) drawRect: ( NSRect ) theRect +{ + NSRect bounds = [ self bounds ]; + + glViewport( 0, 0, NSWidth( bounds ), NSHeight( bounds ) ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); + + glFlush( ); +} + +- ( void ) prepareOpenGL +{ + glClearColor( 0.0, 0.0, 0.0, 0.0 ); + + // Sync to vertical retrace + long VBL = 1; + [ [ self openGLContext ] setValues: &VBL forParameter: NSOpenGLCPSwapInterval ]; +} + +- ( void ) update +{ + [ super update ]; + if( ![ self inLiveResize ] ) + ; +} + +@end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |