aboutsummaryrefslogtreecommitdiff
path: root/macosx/plugins/DFXVideo/macsrc
diff options
context:
space:
mode:
authorPCSX* teams2010-11-16 14:15:22 +0200
committerGrazvydas Ignotas2010-11-16 14:15:22 +0200
commitef79bbde537d6b9c745a7d86cb9df1d04c35590d (patch)
treeef8d2520dbb9e1e345b41b12c9959f300ca8fd10 /macosx/plugins/DFXVideo/macsrc
downloadpcsx_rearmed-ef79bbde537d6b9c745a7d86cb9df1d04c35590d.tar.gz
pcsx_rearmed-ef79bbde537d6b9c745a7d86cb9df1d04c35590d.tar.bz2
pcsx_rearmed-ef79bbde537d6b9c745a7d86cb9df1d04c35590d.zip
pcsxr-1.9.92
Diffstat (limited to 'macosx/plugins/DFXVideo/macsrc')
-rw-r--r--macosx/plugins/DFXVideo/macsrc/ExtendedKeys.h23
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginConfigController.h26
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginConfigController.m216
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginGLView.h63
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginGLView.m692
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginWindow.h24
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginWindow.m46
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginWindowController.h41
-rw-r--r--macosx/plugins/DFXVideo/macsrc/PluginWindowController.m227
-rw-r--r--macosx/plugins/DFXVideo/macsrc/drawgl.m181
10 files changed, 1539 insertions, 0 deletions
diff --git a/macosx/plugins/DFXVideo/macsrc/ExtendedKeys.h b/macosx/plugins/DFXVideo/macsrc/ExtendedKeys.h
new file mode 100644
index 0000000..1b6475b
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/ExtendedKeys.h
@@ -0,0 +1,23 @@
+
+#ifndef __EXTENDED_KEYS_H__
+#define __EXTENDED_KEYS_H__
+
+enum {
+ PSX_FREEZE_KEY = 0xFFBE/*XK_F1*/,
+ PSX_NEXT_FREEZE_SLOT_KEY = 0xFFBF/*XK_F2*/,
+ PSX_DEFROST_KEY = 0xFFC0/*XK_F3*/,
+ PSX_SHOW_FREEZE_PIC_KEY = 0xFFC1/*XK_F4*/,
+ PSX_SIO_ALWAYS_ON_KEY = 0xFFC2/*XK_F5*/,
+ PSX_BW_MDEC_KEY = 0xFFC3/*XK_F6*/,
+ PSX_XA_AUDIO_ON_KEY = 0xFFC4/*XK_F7*/,
+ PSX_SNAPSHOT_KEY = 0xFFC5/*XK_F8*/,
+ PSX_OPEN_SHELL_KEY = 0xFFC6/*XK_F9*/,
+ PSX_CLOSE_SHELL_KEY = 0xFFC7/*XK_F10*/,
+
+ PSX_STOP_KEY = 0xFF1B/*XK_Escape*/,
+
+ GPU_FULLSCREEN_KEY = 0x0100,
+ GPU_FPS_DISPLAY_KEY = 0xFFFF/*XK_Delete*/
+};
+
+#endif //__EXTENDED_KEYS_H__
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginConfigController.h b/macosx/plugins/DFXVideo/macsrc/PluginConfigController.h
new file mode 100644
index 0000000..0e73441
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginConfigController.h
@@ -0,0 +1,26 @@
+/* NetSfPeopsSoftGPUPluginConfigController */
+
+#define PluginConfigController NetSfPeopsSoftGPUPluginConfigController
+
+#import <Cocoa/Cocoa.h>
+
+@interface PluginConfigController : NSWindowController
+{
+ IBOutlet NSControl *autoFullScreen;
+ IBOutlet NSPopUpButton *ditherMode;
+ IBOutlet NSControl *fpsCounter;
+ IBOutlet NSControl *frameSkipping;
+ IBOutlet NSControl *hackEnable;
+ IBOutlet NSView *hacksView;
+ IBOutlet NSControl *vSync;
+
+ NSMutableDictionary *keyValues;
+}
+- (IBAction)cancel:(id)sender;
+- (IBAction)ok:(id)sender;
+- (IBAction)reset:(id)sender;
+- (IBAction)hackToggle:(id)sender;
+
+- (void)loadValues;
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginConfigController.m b/macosx/plugins/DFXVideo/macsrc/PluginConfigController.m
new file mode 100644
index 0000000..2d3e667
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginConfigController.m
@@ -0,0 +1,216 @@
+#import "PluginConfigController.h"
+#include "gpu.h"
+#include "cfg.h"
+#include "menu.h"
+#include "externals.h"
+
+#define APP_ID @"net.sf.peops.SoftGpuGLPlugin"
+#define PrefsKey APP_ID @" Settings"
+
+static PluginConfigController *windowController;
+char * pConfigFile=NULL;
+
+void AboutDlgProc()
+{
+ // Get parent application instance
+ NSApplication *app = [NSApplication sharedApplication];
+ NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID];
+
+ // Get Credits.rtf
+ NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"];
+ NSAttributedString *credits;
+ if (path) {
+ credits = [[[NSAttributedString alloc] initWithPath: path
+ documentAttributes:NULL] autorelease];
+ } else {
+ credits = [[[NSAttributedString alloc] initWithString:@""] autorelease];
+ }
+
+ // Get Application Icon
+ NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]];
+ NSSize size = NSMakeSize(64, 64);
+ [icon setSize:size];
+
+ [app orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObjectsAndKeys:
+ [bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName",
+ icon, @"ApplicationIcon",
+ [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion",
+ [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version",
+ [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright",
+ credits, @"Credits",
+ nil]];
+}
+
+
+void SoftDlgProc()
+{
+ NSWindow *window;
+
+ if (windowController == nil) {
+ windowController = [[PluginConfigController alloc] initWithWindowNibName:@"NetSfPeopsSoftGPUConfig"];
+ }
+ window = [windowController window];
+
+ /* load values */
+ [windowController loadValues];
+
+ [window center];
+ [window makeKeyAndOrderFront:nil];
+}
+
+void ReadConfig(void)
+{
+ NSDictionary *keyValues;
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
+ [[NSMutableDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithBool:NO], @"FPS Counter",
+ [NSNumber numberWithBool:NO], @"Auto Full Screen",
+ [NSNumber numberWithBool:NO], @"Frame Skipping",
+ [NSNumber numberWithBool:YES], @"Frame Limit",
+ [NSNumber numberWithBool:NO], @"VSync",
+ [NSNumber numberWithBool:NO], @"Enable Hacks",
+ [NSNumber numberWithInt:1], @"Dither Mode",
+ [NSNumber numberWithLong:0], @"Hacks",
+ nil], PrefsKey,
+ nil]];
+
+ keyValues = [defaults dictionaryForKey:PrefsKey];
+
+ iShowFPS = [[keyValues objectForKey:@"FPS Counter"] boolValue];
+ iWindowMode = [[keyValues objectForKey:@"Auto Full Screen"] boolValue] ? 0 : 1;
+ UseFrameSkip = [[keyValues objectForKey:@"Frame Skipping"] boolValue];
+ UseFrameLimit = [[keyValues objectForKey:@"Frame Limit"] boolValue];
+ //??? = [[keyValues objectForKey:@"VSync"] boolValue];
+ iUseFixes = [[keyValues objectForKey:@"Enable Hacks"] boolValue];
+
+ iUseDither = [[keyValues objectForKey:@"Dither Mode"] intValue];
+ dwCfgFixes = [[keyValues objectForKey:@"Hacks"] longValue];
+
+ iResX = 640;
+ iResY = 480;
+ iUseNoStretchBlt = 1;
+
+ fFrameRate = 60;
+ iFrameLimit = 2;
+
+ if (iShowFPS)
+ ulKeybits|=KEY_SHOWFPS;
+ else
+ ulKeybits&=~KEY_SHOWFPS;
+
+ // additional checks
+ if(!iColDepth) iColDepth=32;
+ if(iUseFixes) dwActFixes=dwCfgFixes;
+ else dwActFixes=0;
+ SetFixes();
+
+ if(iFrameLimit==2) SetAutoFrameCap();
+ bSkipNextFrame = FALSE;
+
+ szDispBuf[0]=0;
+ BuildDispMenu(0);
+}
+
+@implementation PluginConfigController
+
+- (IBAction)cancel:(id)sender
+{
+ [self close];
+}
+
+- (IBAction)ok:(id)sender
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:keyValues];
+ [writeDic setObject:[NSNumber numberWithInt:[fpsCounter intValue]] forKey:@"FPS Counter"];
+ [writeDic setObject:[NSNumber numberWithInt:[autoFullScreen intValue]] forKey:@"Auto Full Screen"];
+ [writeDic setObject:[NSNumber numberWithInt:[frameSkipping intValue]] forKey:@"Frame Skipping"];
+ //[writeDic setObject:[NSNumber numberWithInt:[frameLimit intValue]] forKey:@"Frame Limit"];
+ [writeDic setObject:[NSNumber numberWithInt:[vSync intValue]] forKey:@"VSync"];
+ [writeDic setObject:[NSNumber numberWithInt:[hackEnable intValue]] forKey:@"Enable Hacks"];
+
+ [writeDic setObject:[NSNumber numberWithInt:[ditherMode indexOfSelectedItem]] forKey:@"Dither Mode"];
+
+ unsigned long hackValues = 0;
+ int i;
+ NSArray *views = [hacksView subviews];
+ for (i=0; i<[views count]; i++) {
+ NSView *control = [views objectAtIndex:i];
+ if ([control isKindOfClass:[NSButton class]]) {
+ hackValues |= [(NSControl *)control intValue] << ([control tag] - 1);
+ }
+ }
+
+ [writeDic setObject:[NSNumber numberWithLong:hackValues] forKey:@"Hacks"];
+
+ // write to defaults
+ [defaults setObject:writeDic forKey:PrefsKey];
+ [defaults synchronize];
+
+ // and set global values accordingly
+ ReadConfig();
+
+ [self close];
+}
+
+- (IBAction)reset:(id)sender
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ [defaults removeObjectForKey:PrefsKey];
+ [self loadValues];
+}
+
+- (IBAction)hackToggle:(id)sender
+{
+ BOOL enable = [sender intValue] ? YES : NO;
+ int i;
+ NSArray *views = [hacksView subviews];
+
+ for (i=0; i<[views count]; i++) {
+ NSView *control = [views objectAtIndex:i];
+ if ([control isKindOfClass:[NSButton class]]) {
+ [(NSControl *)control setEnabled:enable];
+ }
+ }
+}
+
+- (void)loadValues
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ ReadConfig();
+
+ /* load from preferences */
+ [keyValues release];
+ keyValues = [[defaults dictionaryForKey:PrefsKey] retain];
+
+ [fpsCounter setIntValue:[[keyValues objectForKey:@"FPS Counter"] intValue]];
+ [autoFullScreen setIntValue:[[keyValues objectForKey:@"Auto Full Screen"] intValue]];
+ [frameSkipping setIntValue:[[keyValues objectForKey:@"Frame Skipping"] intValue]];
+ [vSync setIntValue:[[keyValues objectForKey:@"VSync"] intValue]];
+ [hackEnable setIntValue:[[keyValues objectForKey:@"Enable Hacks"] intValue]];
+
+ [ditherMode selectItemAtIndex:[[keyValues objectForKey:@"Dither Mode"] intValue]];
+
+ unsigned long hackValues = [[keyValues objectForKey:@"Hacks"] longValue];
+
+ int i;
+ NSArray *views = [hacksView subviews];
+ for (i=0; i<[views count]; i++) {
+ NSView *control = [views objectAtIndex:i];
+ if ([control isKindOfClass:[NSButton class]]) {
+ [(NSControl *)control setIntValue:(hackValues >> ([control tag] - 1)) & 1];
+ }
+ }
+
+ [self hackToggle:hackEnable];
+}
+
+- (void)awakeFromNib
+{
+ hacksView = [[hacksView subviews] objectAtIndex:0];
+}
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginGLView.h b/macosx/plugins/DFXVideo/macsrc/PluginGLView.h
new file mode 100644
index 0000000..fea3b89
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginGLView.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+ PluginGLView.h
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Sun April 18 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#define PluginGLView NetSfPeopsSoftGPUPluginGLView
+
+#import <Cocoa/Cocoa.h>
+#import <OpenGL/gl.h>
+#include <sys/time.h>
+
+#define IMAGE_COUNT 2
+
+@interface PluginGLView : NSOpenGLView
+{
+ GLubyte *image_base;
+ GLubyte *image[IMAGE_COUNT];
+
+ GLint buffers;
+ //GLint frame_rate;
+
+ GLenum texture_hint;
+ GLboolean rect_texture;
+ GLboolean client_storage;
+ GLboolean texture_range;
+
+ struct timeval cycle_time;
+
+ NSLock *glLock;
+ BOOL noDisplay;
+ BOOL drawBG;
+
+ int image_width;
+ int image_height;
+ int image_width2;
+ int image_height2;
+ int image_depth;
+ int image_type;
+ float image_tx;
+ float image_ty;
+ int whichImage;
+ int isFullscreen;
+}
+
+- (void)renderScreen;
+- (void)swapBuffer;
+- (void)clearBuffer:(BOOL)display;
+- (void)loadTextures: (GLboolean)first;
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginGLView.m b/macosx/plugins/DFXVideo/macsrc/PluginGLView.m
new file mode 100644
index 0000000..96b05ff
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginGLView.m
@@ -0,0 +1,692 @@
+/***************************************************************************
+ PluginGLView.m
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Sun April 18 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#import <OpenGL/gl.h>
+#import <OpenGL/glext.h>
+#import <OpenGL/glu.h>
+#import <GLUT/glut.h>
+#import <Carbon/Carbon.h>
+#import "PluginGLView.h"
+#include "externals.h"
+#undef BOOL
+#include "gpu.h"
+#include "swap.h"
+
+#include <time.h>
+extern time_t tStart;
+
+static int mylog2(int val)
+{
+ int i;
+ for (i=1; i<31; i++)
+ if (val <= (1 << i))
+ return (1 << i);
+
+ return -1;
+}
+
+#if 0
+void BlitScreen16NS(unsigned char * surf,long x,long y)
+{
+ unsigned long lu;
+ unsigned short row,column;
+ unsigned short dx=PreviousPSXDisplay.Range.x1>>1;
+ unsigned short dy=PreviousPSXDisplay.DisplayMode.y;
+ unsigned short LineOffset,SurfOffset;
+ long lPitch=image_width<<1;
+
+ if(PreviousPSXDisplay.Range.y0) // centering needed?
+ {
+ surf+=PreviousPSXDisplay.Range.y0*lPitch;
+ dy-=PreviousPSXDisplay.Range.y0;
+ }
+
+ {
+ unsigned long * SRCPtr = (unsigned long *)(psxVuw + (y<<10) + x);
+ unsigned long * DSTPtr = ((unsigned long *)surf)+(PreviousPSXDisplay.Range.x0>>1);
+
+ LineOffset = 512 - dx;
+ SurfOffset = (lPitch>>2) - dx;
+
+ for(column=0;column<dy;column++)
+ {
+ for(row=0;row<dx;row++)
+ {
+ lu=GETLE16D(SRCPtr++);
+
+ *DSTPtr++= lu;//((lu<<11)&0xf800f800)|((lu<<1)&0x7c007c0)|((lu>>10)&0x1f001f);
+ }
+ SRCPtr += LineOffset;
+ DSTPtr += SurfOffset;
+ }
+ }
+}
+#endif
+
+@implementation PluginGLView
+
+//- (id)initWithFrame:(NSRect)frameRect
+- (id) initWithCoder: (NSCoder *) coder
+{
+ const GLubyte * strExt;
+
+ if ((self = [super initWithCoder:coder]) == nil)
+ return nil;
+
+ glLock = [[NSLock alloc] init];
+ if (nil == glLock) {
+ [self release];
+ return nil;
+ }
+
+ // Init pixel format attribs
+ NSOpenGLPixelFormatAttribute attrs[] =
+ {
+ NSOpenGLPFAAccelerated,
+ NSOpenGLPFANoRecovery,
+ NSOpenGLPFADoubleBuffer,
+ 0
+ };
+
+ // Get pixel format from OpenGL
+ NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+ if (!pixFmt)
+ {
+ NSLog(@"No Accelerated OpenGL pixel format found\n");
+
+ NSOpenGLPixelFormatAttribute attrs2[] =
+ {
+ NSOpenGLPFANoRecovery,
+ 0
+ };
+
+ // Get pixel format from OpenGL
+ pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs2];
+ if (!pixFmt) {
+ NSLog(@"No OpenGL pixel format found!\n");
+
+ [self release];
+ return nil;
+ }
+ }
+
+ [self setPixelFormat:[pixFmt autorelease]];
+
+ /*
+ long swapInterval = 1 ;
+ [[self openGLContext]
+ setValues:&swapInterval
+ forParameter:NSOpenGLCPSwapInterval];
+ */
+ [glLock lock];
+ [[self openGLContext] makeCurrentContext];
+
+ // Init object members
+ strExt = glGetString (GL_EXTENSIONS);
+ texture_range = gluCheckExtension ((const unsigned char *)"GL_APPLE_texture_range", strExt) ? GL_TRUE : GL_FALSE;
+ texture_hint = GL_STORAGE_SHARED_APPLE ;
+ client_storage = gluCheckExtension ((const unsigned char *)"GL_APPLE_client_storage", strExt) ? GL_TRUE : GL_FALSE;
+ rect_texture = gluCheckExtension((const unsigned char *)"GL_EXT_texture_rectangle", strExt) ? GL_TRUE : GL_FALSE;
+
+ // Setup some basic OpenGL stuff
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ [NSOpenGLContext clearCurrentContext];
+ [glLock unlock];
+
+ image_width = 1024;
+ image_height = 512;
+ image_depth = 16;
+
+ image_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ image_base = (GLubyte *) calloc(((IMAGE_COUNT * image_width * image_height) / 3) * 4, image_depth >> 3);
+ if (image_base == nil) {
+ [self release];
+ return nil;
+ }
+
+ // Create and load textures for the first time
+ [self loadTextures:GL_TRUE];
+
+ // Init fps timer
+ //gettimeofday(&cycle_time, NULL);
+
+ drawBG = YES;
+
+ // Call for a redisplay
+ noDisplay = YES;
+ PSXDisplay.Disabled = 1;
+ [self setNeedsDisplay:true];
+
+ return self;
+}
+
+- (void)dealloc
+{
+ int i;
+
+ [glLock lock];
+
+ [[self openGLContext] makeCurrentContext];
+ for(i = 0; i < IMAGE_COUNT; i++)
+ {
+ GLuint dt = i+1;
+ glDeleteTextures(1, &dt);
+ }
+ if(texture_range) glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT, IMAGE_COUNT * image_width * image_height * (image_depth >> 3), image_base);
+
+ [NSOpenGLContext clearCurrentContext];
+ [glLock unlock];
+ [glLock release];
+
+ if (image_base)
+ free(image_base);
+
+ [super dealloc];
+}
+
+- (BOOL)isOpaque
+{
+ return YES;
+}
+
+- (BOOL)acceptsFirstResponder
+{
+ return NO;
+}
+
+- (void)drawRect:(NSRect)aRect
+{
+ // Check if an update has occured to the buffer
+ if ([self lockFocusIfCanDraw]) {
+
+ // Make this context current
+ if (drawBG) {
+ [[NSColor blackColor] setFill];
+ [NSBezierPath fillRect:[self visibleRect]];
+ }
+
+ //glFinish() ;
+ // Swap buffer to screen
+ //[[self openGLContext] flushBuffer];
+
+ [self unlockFocus];
+ }
+}
+
+#if 0
+- (void)update // moved or resized
+{
+ NSRect rect;
+
+ [super update];
+
+ [[self openGLContext] makeCurrentContext];
+ [[self openGLContext] update];
+
+ rect = [self bounds];
+
+ glViewport(0, 0, (int) rect.size.width, (int) rect.size.height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ //[self setNeedsDisplay:true];
+}
+#endif
+
+- (void)reshape // scrolled, moved or resized
+{
+ [glLock lock];
+
+ NSOpenGLContext *oglContext = [self openGLContext];
+ NSRect rect;
+
+ [super reshape];
+
+ [oglContext makeCurrentContext];
+ [oglContext update];
+
+ rect = [[oglContext view] bounds];
+
+ glViewport(0, 0, (int) rect.size.width, (int) rect.size.height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ drawBG = YES;
+
+ [NSOpenGLContext clearCurrentContext];
+
+// [self setNeedsDisplay:true];
+
+ [self renderScreen];
+ [glLock unlock];
+}
+
+- (void)renderScreen
+{
+ int bufferIndex = whichImage;
+
+ if (1/*[glLock tryLock]*/) {
+ // Make this context current
+ [[self openGLContext] makeCurrentContext];
+ if (PSXDisplay.Disabled) {
+ glClear(GL_COLOR_BUFFER_BIT);
+ } else {
+ // Bind, update and draw new image
+ if(rect_texture)
+ {
+ glBindTexture(GL_TEXTURE_RECTANGLE_EXT, bufferIndex+1);
+
+ glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, image_width, image_height, GL_BGRA, image_type, image[bufferIndex]);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex2f(-1.0f, 1.0f);
+
+ glTexCoord2f(0.0f, image_height);
+ glVertex2f(-1.0f, -1.0f);
+
+ glTexCoord2f(image_width, image_height);
+ glVertex2f(1.0f, -1.0f);
+
+ glTexCoord2f(image_width, 0.0f);
+ glVertex2f(1.0f, 1.0f);
+ glEnd();
+ }
+ else
+ {
+ glBindTexture(GL_TEXTURE_2D, whichImage+1);
+
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_width2, image_height2, GL_BGRA, image_type, image[bufferIndex]);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex2f(-1.0f, 1.0f);
+
+ glTexCoord2f(0.0f, image_ty);
+ glVertex2f(-1.0f, -1.0f);
+
+ glTexCoord2f(image_tx, image_ty);
+ glVertex2f(1.0f, -1.0f);
+
+ glTexCoord2f(image_tx, 0.0f);
+ glVertex2f(1.0f, 1.0f);
+ glEnd();
+ }
+ }
+
+ // FPS Display
+ if(ulKeybits&KEY_SHOWFPS)
+ {
+ int len, i;
+ if(szDebugText[0] && ((time(NULL) - tStart) < 2))
+ {
+ strncpy(szDispBuf, szDebugText, 63);
+ }
+ else
+ {
+ szDebugText[0]=0;
+ if (szMenuBuf) {
+ strncat(szDispBuf, szMenuBuf, 63 - strlen(szDispBuf));
+ }
+ }
+
+ NSRect rect = [[[self openGLContext] view] bounds];
+ len = (int) strlen(szDispBuf);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+
+ gluOrtho2D(0.0, rect.size.width, 0.0, rect.size.height);
+ glDisable(rect_texture ? GL_TEXTURE_RECTANGLE_EXT : GL_TEXTURE_2D);
+
+ glColor4f(0.0, 0.0, 0.0, 0.5);
+ glRasterPos2f(3.0, rect.size.height - 14.0);
+ for (i = 0; i < len; i++) {
+ glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, szDispBuf[i]);
+ }
+
+ glColor3f(1.0, 1.0, 1.0);
+ glRasterPos2f(2.0, rect.size.height - 13.0);
+ for (i = 0; i < len; i++) {
+ glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, szDispBuf[i]);
+ }
+
+
+ glEnable(rect_texture ? GL_TEXTURE_RECTANGLE_EXT : GL_TEXTURE_2D);
+ glPopMatrix();
+ }
+
+ [[self openGLContext] flushBuffer];
+ [NSOpenGLContext clearCurrentContext];
+ //[glLock unlock];
+ }
+}
+
+- (void)loadTextures:(GLboolean)first
+{
+ GLint i;
+
+ //[glLock lock];
+ [[self openGLContext] makeCurrentContext];
+
+ /*
+ printf("Range.x0=%i\n"
+ "Range.x1=%i\n"
+ "Range.y0=%i\n"
+ "Range.y1=%i\n",
+ PreviousPSXDisplay.Range.x0,
+ PreviousPSXDisplay.Range.x1,
+ PreviousPSXDisplay.Range.y0,
+ PreviousPSXDisplay.Range.y1);
+
+ printf("DisplayMode.x=%d\n"
+ "DisplayMode.y=%d\n",
+ PreviousPSXDisplay.DisplayMode.x,
+ PreviousPSXDisplay.DisplayMode.y);
+
+ printf("DisplayPosition.x=%i\n"
+ "DisplayPosition.y=%i\n",
+ PreviousPSXDisplay.DisplayPosition.x,
+ PreviousPSXDisplay.DisplayPosition.y);
+
+ printf("DisplayEnd.x=%i\n"
+ "DisplayEnd.y=%i\n",
+ PreviousPSXDisplay.DisplayEnd.x,
+ PreviousPSXDisplay.DisplayEnd.y);
+
+ printf("Double=%i\n"
+ "Height=%i\n",
+ PreviousPSXDisplay.Double,
+ PreviousPSXDisplay.Height);
+
+ printf("Disabled=%i\n", PreviousPSXDisplay.Disabled);
+ */
+
+ image_width = PreviousPSXDisplay.Range.x1;
+ image_height = PreviousPSXDisplay.DisplayMode.y;
+ if (PSXDisplay.RGB24) {
+ image_depth = 32;
+ image_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+ } else {
+ image_depth = 16;
+ image_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ //image_width >>= 1;
+ }
+
+ if (image_width * image_height * (image_depth >> 3) > ((1024*512*2)/3)*4)
+ printf("Fatal error: desired dimension are too large! (%ix%i %ibpp)\n",
+ image_width, image_height, image_depth);
+
+ for(i = 0; i < IMAGE_COUNT; i++)
+ image[i] = image_base + i * image_width * image_height * (image_depth >> 3);
+
+ if(rect_texture)
+ {
+ image_width2 = image_width;
+ image_height2 = image_height;
+ image_tx = (float)image_width;
+ image_ty = (float)image_height;
+
+ if(texture_range) glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT, IMAGE_COUNT * image_width * image_height * (image_depth >> 3), image_base);
+ else glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT, 0, NULL);
+
+ for(i = 0; i < IMAGE_COUNT; i++)
+ {
+ if(!first)
+ {
+ GLuint dt = i+1;
+ glDeleteTextures(1, &dt);
+ }
+
+ glDisable(GL_TEXTURE_2D);
+ glEnable(GL_TEXTURE_RECTANGLE_EXT);
+ glBindTexture(GL_TEXTURE_RECTANGLE_EXT, i+1);
+
+ glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , texture_hint);
+ glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, client_storage);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+
+ glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, image_width,
+ image_height, 0, GL_BGRA, image_type, image[i]);
+ }
+ }
+ else
+ {
+ image_width2 = mylog2(image_width);
+ image_height2 = mylog2(image_height);
+ image_tx = (float)image_width/(float)image_width2;
+ image_ty = (float)image_height/(float)image_height2;
+
+ glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT, 0, NULL);
+ if(texture_range) glTextureRangeAPPLE(GL_TEXTURE_2D, IMAGE_COUNT * image_width2 * image_height2 * (image_depth >> 3), image_base);
+ else glTextureRangeAPPLE(GL_TEXTURE_2D, 0, NULL);
+
+ for(i = 0; i < IMAGE_COUNT; i++)
+ {
+ if(!first)
+ {
+ GLuint dt = i+1;
+ glDeleteTextures(1, &dt);
+ }
+
+ glDisable(GL_TEXTURE_RECTANGLE_EXT);
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, i+1);
+
+ //if(texture_range) glTextureRangeAPPLE(GL_TEXTURE_2D, IMAGE_COUNT * image_width2 * image_height2 * (image_depth >> 3), image_base);
+ //else glTextureRangeAPPLE(GL_TEXTURE_2D, 0, NULL);
+
+ glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , texture_hint);
+ glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, client_storage);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width2,
+ image_height2, 0, GL_BGRA, image_type, image[i]);
+ }
+ }
+
+ [NSOpenGLContext clearCurrentContext];
+ //[glLock unlock];
+}
+
+- (void)swapBuffer
+{
+ unsigned char * surf;
+ long x = PSXDisplay.DisplayPosition.x;
+ long y = PSXDisplay.DisplayPosition.y;
+ unsigned long lu;
+ unsigned short row,column;
+ unsigned short dx=(unsigned short)PSXDisplay.DisplayEnd.x;//PreviousPSXDisplay.Range.x1;
+ unsigned short dy=(unsigned short)PSXDisplay.DisplayEnd.y;//PreviousPSXDisplay.DisplayMode.y;
+ long lPitch;
+
+ //printf("y=%i",PSXDisplay.DisplayPosition.y);
+
+ if ([glLock tryLock]) {
+ // make sure the texture area is ready to be written to
+ glFinishObjectAPPLE(GL_TEXTURE, 2-whichImage);
+
+ if ((image_width != PreviousPSXDisplay.Range.x1) ||
+ (image_height != PreviousPSXDisplay.DisplayMode.y) ||
+ ((PSXDisplay.RGB24 ? 32 : 16) != image_depth)) {
+ [self loadTextures:NO];
+ }
+
+ surf = image[1-whichImage];
+ lPitch=image_width2<<(image_depth >> 4);
+
+ if(PreviousPSXDisplay.Range.y0) // centering needed?
+ {
+ surf+=PreviousPSXDisplay.Range.y0*lPitch;
+ dy-=PreviousPSXDisplay.Range.y0;
+ }
+
+ if(PSXDisplay.RGB24)
+ {
+ unsigned char * pD;unsigned int startxy;
+
+ surf+=PreviousPSXDisplay.Range.x0<<2;
+
+ for(column=0;column<dy;column++)
+ {
+ startxy = (1024 * (column + y)) + x;
+ pD = (unsigned char *)&psxVuw[startxy];
+
+ row = 0;
+ // make sure the reads are aligned
+ while ((int)pD & 0x3) {
+ *((unsigned long *)((surf)+(column*lPitch)+(row<<2))) =
+ (*(pD+0)<<16)|(*(pD+1)<<8)|*(pD+2);
+
+ pD+=3;
+ row++;
+ }
+
+ for(;row<dx;row+=4)
+ {
+ unsigned long lu1 = *((unsigned long *)pD);
+ unsigned long lu2 = *((unsigned long *)pD+1);
+ unsigned long lu3 = *((unsigned long *)pD+2);
+ unsigned long *dst = ((unsigned long *)((surf)+(column*lPitch)+(row<<2)));
+#ifdef __POWERPC__
+ *(dst)=
+ (((lu1>>24)&0xff)<<16)|(((lu1>>16)&0xff)<<8)|(((lu1>>8)&0xff));
+ *(dst+1)=
+ (((lu1>>0)&0xff)<<16)|(((lu2>>24)&0xff)<<8)|(((lu2>>16)&0xff));
+ *(dst+2)=
+ (((lu2>>8)&0xff)<<16)|(((lu2>>0)&0xff)<<8)|(((lu3>>24)&0xff));
+ *(dst+3)=
+ (((lu3>>16)&0xff)<<16)|(((lu3>>8)&0xff)<<8)|(((lu3>>0)&0xff));
+#else
+ *(dst)=
+ (((lu1>>0)&0xff)<<16)|(((lu1>>8)&0xff)<<8)|(((lu1>>16)&0xff));
+ *(dst+1)=
+ (((lu1>>24)&0xff)<<16)|(((lu2>>0)&0xff)<<8)|(((lu2>>8)&0xff));
+ *(dst+2)=
+ (((lu2>>16)&0xff)<<16)|(((lu2>>24)&0xff)<<8)|(((lu3>>0)&0xff));
+ *(dst+3)=
+ (((lu3>>8)&0xff)<<16)|(((lu3>>16)&0xff)<<8)|(((lu3>>24)&0xff));
+#endif
+ pD+=12;
+ }
+
+ //for(;row<dx;row+=4)
+ /*while (pD&0x3) {
+ *((unsigned long *)((surf)+(column*lPitch)+(row<<2)))=
+ (*(pD+0)<<16)|(*(pD+1)<<8)|(*(pD+2)&0xff));
+ pD+=3;
+ row++;
+ }*/
+ }
+ }
+ else
+ {
+ int LineOffset,SurfOffset;
+ unsigned long * SRCPtr = (unsigned long *)(psxVuw + (y << 10) + x);
+ unsigned long * DSTPtr =
+ ((unsigned long *)surf) + (PreviousPSXDisplay.Range.x0 >> 1);
+
+ dx >>= 1;
+
+ LineOffset = 512 - dx;
+ SurfOffset = (lPitch >> 2) - dx;
+
+ for(column=0;column<dy;column++)
+ {
+ for(row=0;row<dx;row++)
+ {
+#ifdef __POWERPC__
+ lu=GETLE16D(SRCPtr++);
+#else
+ lu=*SRCPtr++;
+#endif
+ *DSTPtr++=
+ ((lu << 10) & 0x7c007c00)|
+ ((lu) & 0x3e003e0)|
+ ((lu >> 10) & 0x1f001f);
+ }
+ SRCPtr += LineOffset;
+ DSTPtr += SurfOffset;
+ }
+ }
+
+ // Swap image buffer
+ whichImage = 1 - whichImage;
+
+ [self renderScreen];
+ [glLock unlock];
+ }
+}
+
+- (void)clearBuffer:(BOOL)display
+{
+ if (display == NO) {
+ //[[self openGLContext] makeCurrentContext];
+ //glClear(GL_COLOR_BUFFER_BIT);
+ //[self loadTextures:NO];
+ } else {
+ noDisplay = YES;
+// [self setNeedsDisplay:true];
+ }
+}
+/*
+- (void)mouseDown:(NSEvent *)theEvent
+{
+ PluginWindowController *controller = [[self window] windowController];
+
+ static unsigned long lastTime = 0;
+ unsigned long time;
+
+ time = TickCount();
+
+ if (lastTime != 0) {
+ if (time - lastTime > GetDblTime()) {
+ if (isFullscreen) {
+ [[self openGLContext] clearDrawable];
+ } else {
+ [[self openGLContext] setFullScreen];
+ }
+ isFullscreen = 1-isFullscreen;
+ lastTime = 0;
+ return;
+ }
+ }
+
+ lastTime = time;
+}*/
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginWindow.h b/macosx/plugins/DFXVideo/macsrc/PluginWindow.h
new file mode 100644
index 0000000..38a8dfa
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginWindow.h
@@ -0,0 +1,24 @@
+/***************************************************************************
+ PluginWindow.h
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Wed April 21 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+@interface NetSfPeopsSoftGPUPluginWindow : NSWindow
+{
+}
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginWindow.m b/macosx/plugins/DFXVideo/macsrc/PluginWindow.m
new file mode 100644
index 0000000..ef4737f
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginWindow.m
@@ -0,0 +1,46 @@
+/***************************************************************************
+ PluginWindow.m
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Wed April 21 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#import "PluginWindow.h"
+
+@implementation NetSfPeopsSoftGPUPluginWindow
+/*
+- (BOOL)windowShouldClose:(id)sender
+{
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowDidClose" object:self];
+
+ return YES;
+}*/
+
+- (void)sendEvent:(NSEvent *)theEvent
+{
+ int type = [theEvent type];
+ if (type == NSKeyDown || type == NSKeyUp) {
+ if (type == NSKeyDown && [theEvent keyCode] == 53 /* escape */) {
+ // reroute to menu event
+ [[NSApp mainMenu] performKeyEquivalent:theEvent];
+ }
+
+ // ignore all key Events
+ return;
+ }
+
+ [super sendEvent:theEvent];
+}
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginWindowController.h b/macosx/plugins/DFXVideo/macsrc/PluginWindowController.h
new file mode 100644
index 0000000..ff9af25
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginWindowController.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+ PluginWindowController.h
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Mon April 11 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#define PluginWindowController NetSfPeopsSoftGPUPluginWindowController
+
+#import <Cocoa/Cocoa.h>
+#import "PluginGLView.h"
+
+@class PluginWindowController;
+
+extern NSWindow *gameWindow;
+extern PluginWindowController *gameController;
+
+@interface PluginWindowController : NSWindowController
+{
+ IBOutlet NSOpenGLView *glView;
+
+ NSWindow *fullWindow;
+}
+
++ (id)openGameView;
+- (PluginGLView *)getOpenGLView;
+- (BOOL)fullscreen;
+- (void)setFullscreen:(BOOL)flag;
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/PluginWindowController.m b/macosx/plugins/DFXVideo/macsrc/PluginWindowController.m
new file mode 100644
index 0000000..48262e5
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/PluginWindowController.m
@@ -0,0 +1,227 @@
+/***************************************************************************
+ PluginWindowController.m
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Tue April 12 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#import "PluginWindowController.h"
+#import "PluginWindow.h"
+#import "Carbon/Carbon.h"
+#include "externals.h"
+#undef BOOL
+
+NSWindow *gameWindow;
+PluginWindowController *gameController;
+NSRect windowFrame;
+
+@implementation PluginWindowController
+
++ (id)openGameView
+{
+ if (gameWindow == nil) {
+ if (gameController == nil) {
+ gameController = [[PluginWindowController alloc] initWithWindowNibName:@"NetSfPeopsSoftGPUInterface"];
+ }
+ gameWindow = [gameController window];
+ }
+
+ if (windowFrame.size.width != 0) {
+ [gameWindow setFrame:windowFrame display:NO];
+ } else {
+ [gameWindow center];
+ }
+
+ [gameWindow makeKeyAndOrderFront:nil];
+ [gameController showWindow:nil];
+
+ CGDirectDisplayID display = (CGDirectDisplayID)[[[[gameWindow screen] deviceDescription] objectForKey:@"NSScreenNumber"] longValue];
+ if (CGDisplayIsCaptured(display)) {
+ [gameController setFullscreen:YES];
+ }
+
+ return gameController;
+}
+
+- (PluginGLView *)getOpenGLView
+{
+ return (PluginGLView *)glView;
+}
+
+- (void)dealloc
+{
+ if (fullWindow) {
+ [fullWindow orderOut:self];
+ [fullWindow autorelease];
+ fullWindow = nil;
+ }
+
+ windowFrame = [[self window] frame];
+
+ [super dealloc];
+}
+
+// forget keyDownEvents
+- (void)keyDown:(NSEvent *)theEvent
+{
+ // Not required any more
+}
+
+- (void)mouseDown:(NSEvent *)theEvent
+{
+ if ([self fullscreen]) {
+ [self setFullscreen:NO];
+ }
+}
+
+- (BOOL)fullscreen
+{
+ return (fullWindow!=nil);
+}
+
+- (void)setFullscreen:(BOOL)flag
+{
+ NSWindow *window = [self window];
+ NSScreen *screen = [window screen];
+ CGDirectDisplayID display = (CGDirectDisplayID)[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] longValue];
+
+ NSDisableScreenUpdates();
+
+ if (flag) {
+ if (!CGDisplayIsCaptured(display)) {
+ CGDisplayCapture(display);
+
+ CGDisplayCount count = 10;
+ CGDirectDisplayID displays[10];
+ CGGetActiveDisplayList(10, displays, &count);
+ if (count == 1) {
+ CGDisplayHideCursor(display);
+ CGAssociateMouseAndMouseCursorPosition(NO);
+ }
+
+ //[window orderOut:self];
+ }
+
+ int width = CGDisplayPixelsWide(display);
+ int height = CGDisplayPixelsHigh(display);
+
+ // assume square pixel ratio on the monitor
+ if ((width*3)/4 < height) {
+ height = (width*3)/4;
+ } else {
+ width = (height*4)/3;
+ }
+
+ fullWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect((CGDisplayPixelsWide(display)-width)/2,
+ (CGDisplayPixelsHigh(display)-height)/2,
+ width, height)
+ styleMask:NSBorderlessWindowMask
+ backing:NSBackingStoreRetained
+ defer:NO
+ screen:screen];
+
+ //[[glView openGLContext] setFullScreen];
+ [[glView openGLContext] setView:[fullWindow contentView]];
+ [glView reshape];
+ //[[glView openGLContext] update];
+ //[fullWindow setContentView:glView];
+
+ [fullWindow setBackgroundColor:[NSColor blackColor]];
+ [fullWindow setHasShadow:NO];
+ [fullWindow setDelegate:self];
+
+ [fullWindow setLevel:CGShieldingWindowLevel()];
+ [fullWindow makeKeyAndOrderFront:self];
+
+ [[self window] makeKeyAndOrderFront:self];
+ } else {
+ CGDisplayRelease(display);
+ //CGReleaseAllDisplays();
+
+ CGAssociateMouseAndMouseCursorPosition(YES);
+ CGDisplayShowCursor(display);
+
+ if (fullWindow) {
+ [fullWindow orderOut:self];
+ [fullWindow autorelease];
+ fullWindow = nil;
+
+ [[glView openGLContext] setView:glView];
+ [glView reshape];
+ //[window setContentView:glView];
+ }
+
+ [[self window] makeKeyAndOrderFront:self];
+ }
+
+ NSEnableScreenUpdates();
+}
+
+- (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
+{
+ [self setFullscreen:YES];
+
+ return NO;
+}
+
+- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
+{
+ if (!(([sender resizeFlags] & NSShiftKeyMask) == NSShiftKeyMask)) {
+ NSRect oldSize = [sender frame];
+ NSRect viewSize = [glView frame];
+
+ float xDiff = NSWidth(oldSize) - NSWidth(viewSize);
+ float yDiff = NSHeight(oldSize) - NSHeight(viewSize);
+
+ //if ((proposedFrameSize.height / proposedFrameSize.width) < (3.0/4.0))
+ // proposedFrameSize.height = ((proposedFrameSize.width - xDiff) * 3.0) / 4.0 + yDiff;
+ //else
+ proposedFrameSize.width = ((proposedFrameSize.height - yDiff) * 4.0) / 3.0 + xDiff;
+ }
+
+ return proposedFrameSize;
+}
+
+- (void)windowWillMiniaturize:(NSNotification *)aNotification
+{
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowWantPause" object:self];
+}
+
+- (void)windowDidDeminiaturize:(NSNotification *)aNotification
+{
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowWantResume" object:self];
+}
+
+//- (void)windowDidBecomeMain:(NSNotification *)aNotification
+/*- (void)windowDidBecomeKey:(NSNotification *)aNotification
+{
+ if (iWindowMode==0) {
+ [self setFullscreen:YES];
+ }
+}*/
+
+- (BOOL)windowShouldClose:(id)sender
+{
+ if (fullWindow) {
+ return NO;
+ }
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowDidClose" object:self];
+ [gameController autorelease];
+ gameController = nil;
+ gameWindow = nil;
+
+ return YES;
+}
+
+@end
diff --git a/macosx/plugins/DFXVideo/macsrc/drawgl.m b/macosx/plugins/DFXVideo/macsrc/drawgl.m
new file mode 100644
index 0000000..17e7647
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/drawgl.m
@@ -0,0 +1,181 @@
+/***************************************************************************
+ drawgl.m
+ PeopsSoftGPU
+
+ Created by Gil Pedersen on Sun April 18 2004.
+ Copyright (c) 2004 Gil Pedersen.
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#import "PluginWindowController.h"
+#import "PluginGLView.h"
+#include "ExtendedKeys.h"
+#include "externals.h"
+#include "draw.h"
+#include "gpu.h"
+#include "menu.h"
+
+////////////////////////////////////////////////////////////////////////////////////
+// misc globals
+////////////////////////////////////////////////////////////////////////////////////
+
+int iResX;
+int iResY;
+long lLowerpart;
+BOOL bIsFirstFrame = TRUE;
+BOOL bCheckMask=FALSE;
+unsigned short sSetMask=0;
+unsigned long lSetMask=0;
+int iDesktopCol=16;
+int iShowFPS=0;
+int iWinSize;
+int iUseScanLines=0;
+int iUseNoStretchBlt=0;
+int iFastFwd=0;
+int iDebugMode=0;
+int iFVDisplay=0;
+PSXPoint_t ptCursorPoint[8];
+unsigned short usCursorActive=0;
+char * Xpixels;
+char * pCaptionText;
+
+//static PluginWindowController *windowController;
+static PluginGLView *glView;
+
+////////////////////////////////////////////////////////////////////////
+
+void DoBufferSwap(void) // SWAP BUFFERS
+{
+#if 1
+ [glView swapBuffer];
+#else
+ static long long lastTickCount = -1;
+ static int skipCount = 0;
+ long long microTickCount;
+ long deltaTime;
+
+ Microseconds((struct UnsignedWide *)&microTickCount);
+ deltaTime = (long)(microTickCount - lastTickCount);
+ if (deltaTime <= (PSXDisplay.PAL ? 1000000/50 : 100000000 / 5994) ||
+ skipCount >= 3) {
+ skipCount = 0;
+ [glView swapBuffer];
+ } else {
+ skipCount++;
+ }
+ NSLog(@"count: %i", deltaTime);
+ lastTickCount = microTickCount;
+#endif
+}
+
+
+////////////////////////////////////////////////////////////////////////
+
+void DoClearScreenBuffer(void) // CLEAR DX BUFFER
+{
+ // clear the screen, and DON'T flush it
+ [glView clearBuffer:NO];
+}
+
+
+////////////////////////////////////////////////////////////////////////
+
+void DoClearFrontBuffer(void) // CLEAR DX BUFFER
+{
+ // clear the screen, and flush it
+ [glView clearBuffer:YES];
+}
+
+////////////////////////////////////////////////////////////////////////
+
+unsigned long ulInitDisplay(void) // OPEN GAME WINDOW
+{
+ bUsingTWin=FALSE;
+
+ InitMenu();
+
+ bIsFirstFrame = FALSE;
+
+ if(iShowFPS)
+ {
+ //iShowFPS=0;
+ ulKeybits|=KEY_SHOWFPS;
+ szDispBuf[0]=0;
+ BuildDispMenu(0);
+ }
+
+ PluginWindowController *windowController = [PluginWindowController openGameView];
+ glView = [windowController getOpenGLView];
+
+ [[windowController window] setTitle:[NSString stringWithCString:pCaptionText]];
+
+ return (unsigned long)[windowController window];
+}
+
+
+////////////////////////////////////////////////////////////////////////
+
+void CloseDisplay(void)
+{
+ if (gameController) {
+ [gameController close];
+ [gameController release];
+ gameController = nil;
+ gameWindow = nil;
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////
+
+void CreatePic(unsigned char * pMem)
+{
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+void DestroyPic(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+void DisplayPic(void)
+{
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+void ShowGpuPic(void)
+{
+ // this is the default implementation...
+}
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+void ShowTextGpuPic(void)
+{
+ // this is the default implementation...
+}
+
+
+void HandleKey(int keycode)
+{
+ switch (keycode) {
+ case GPU_FULLSCREEN_KEY:
+ [gameController setFullscreen:![gameController fullscreen]];
+ break;
+ }
+}