Cocoa Port:

- Add support for the new OpenGL 3.2 renderer. (Requires OS X v10.7 or later, Xcode 4 builds only.)
This commit is contained in:
rogerman 2013-02-05 07:12:50 +00:00
parent 14d6e53f54
commit 2dc9077511
9 changed files with 154 additions and 74 deletions

View File

@ -1236,7 +1236,6 @@
AB06CD02135B8ACE00E977B3 /* ROMReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ROMReader.h; path = ../ROMReader.h; sourceTree = SOURCE_ROOT; };
AB06CD03135B8ACE00E977B3 /* rtc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = rtc.h; path = ../rtc.h; sourceTree = SOURCE_ROOT; };
AB06CD04135B8ACE00E977B3 /* saves.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = saves.h; path = ../saves.h; sourceTree = SOURCE_ROOT; };
AB06CD05135B8ACE00E977B3 /* shaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = shaders.h; path = ../shaders.h; sourceTree = SOURCE_ROOT; };
AB06CD06135B8ACE00E977B3 /* slot1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = slot1.h; path = ../slot1.h; sourceTree = SOURCE_ROOT; };
AB06CD07135B8ACE00E977B3 /* sndsdl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sndsdl.h; path = ../sndsdl.h; sourceTree = SOURCE_ROOT; };
AB06CD08135B8ACE00E977B3 /* SPU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPU.h; path = ../SPU.h; sourceTree = SOURCE_ROOT; };
@ -1804,7 +1803,6 @@
AB06CD02135B8ACE00E977B3 /* ROMReader.h */,
AB06CD03135B8ACE00E977B3 /* rtc.h */,
AB06CD04135B8ACE00E977B3 /* saves.h */,
AB06CD05135B8ACE00E977B3 /* shaders.h */,
AB06CD06135B8ACE00E977B3 /* slot1.h */,
AB06CD07135B8ACE00E977B3 /* sndsdl.h */,
AB06CD08135B8ACE00E977B3 /* SPU.h */,

View File

@ -1114,7 +1114,6 @@
ABD1FE951345AC8400AF11D1 /* ROMReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ROMReader.h; path = ../ROMReader.h; sourceTree = SOURCE_ROOT; };
ABD1FE961345AC8400AF11D1 /* rtc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = rtc.h; path = ../rtc.h; sourceTree = SOURCE_ROOT; };
ABD1FE971345AC8400AF11D1 /* saves.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = saves.h; path = ../saves.h; sourceTree = SOURCE_ROOT; };
ABD1FE981345AC8400AF11D1 /* shaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = shaders.h; path = ../shaders.h; sourceTree = SOURCE_ROOT; };
ABD1FE991345AC8400AF11D1 /* slot1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = slot1.h; path = ../slot1.h; sourceTree = SOURCE_ROOT; };
ABD1FE9A1345AC8400AF11D1 /* sndsdl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sndsdl.h; path = ../sndsdl.h; sourceTree = SOURCE_ROOT; };
ABD1FE9B1345AC8400AF11D1 /* SPU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPU.h; path = ../SPU.h; sourceTree = SOURCE_ROOT; };
@ -1735,7 +1734,6 @@
ABD1FE951345AC8400AF11D1 /* ROMReader.h */,
ABD1FE961345AC8400AF11D1 /* rtc.h */,
ABD1FE971345AC8400AF11D1 /* saves.h */,
ABD1FE981345AC8400AF11D1 /* shaders.h */,
ABD1FE991345AC8400AF11D1 /* slot1.h */,
ABD1FE9A1345AC8400AF11D1 /* sndsdl.h */,
ABD1FE9B1345AC8400AF11D1 /* SPU.h */,

View File

@ -64,6 +64,7 @@
AB1B9E661501A78000464647 /* ringbuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB1B9E601501A78000464647 /* ringbuffer.cpp */; };
AB1F468413A0ADE400B80DE6 /* SndOut.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ABD1FF7A1345ACFA00AF11D1 /* SndOut.cpp */; };
AB1F469813A0AE2F00B80DE6 /* Timestretcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ABD1FF9B1345ACFA00AF11D1 /* Timestretcher.cpp */; };
AB26D87C16B5253D00A2305C /* OGLRender_3_2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB68A0DA16B139BC00DE0546 /* OGLRender_3_2.cpp */; };
AB350B6A1478A5B3007165AC /* cocoa_hid.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB350B691478A5B3007165AC /* cocoa_hid.mm */; };
AB350BA51478AC96007165AC /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB350BA41478AC96007165AC /* IOKit.framework */; };
AB350D3B147A1D93007165AC /* HID_usage_strings.plist in Resources */ = {isa = PBXBuildFile; fileRef = AB350D3A147A1D93007165AC /* HID_usage_strings.plist */; };
@ -172,6 +173,7 @@
AB4FCEBF1692AB82000F498F /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB4FCEBC1692AB82000F498F /* Accelerate.framework */; };
AB58F32D1364F44B0074C376 /* cocoa_file.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB58F32C1364F44B0074C376 /* cocoa_file.mm */; };
AB64987C13ECC73800EE7DD2 /* FileTypeInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = AB64987B13ECC73800EE7DD2 /* FileTypeInfo.plist */; };
AB68A0DD16B139BC00DE0546 /* OGLRender_3_2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB68A0DA16B139BC00DE0546 /* OGLRender_3_2.cpp */; };
AB6FBEF6139B6258007BB045 /* slot1_retail_nand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB6FBEF5139B6258007BB045 /* slot1_retail_nand.cpp */; };
AB75226E14C7BB51009B97B3 /* AppIcon_FirmwareConfig.icns in Resources */ = {isa = PBXBuildFile; fileRef = AB75226D14C7BB51009B97B3 /* AppIcon_FirmwareConfig.icns */; };
AB796C9C15CDCB0F00C59155 /* arm_jit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB796C9B15CDCB0F00C59155 /* arm_jit.cpp */; };
@ -765,6 +767,7 @@
AB58F32B1364F44B0074C376 /* cocoa_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_file.h; sourceTree = "<group>"; };
AB58F32C1364F44B0074C376 /* cocoa_file.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoa_file.mm; sourceTree = "<group>"; };
AB64987B13ECC73800EE7DD2 /* FileTypeInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = FileTypeInfo.plist; sourceTree = "<group>"; };
AB68A0DA16B139BC00DE0546 /* OGLRender_3_2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OGLRender_3_2.cpp; path = ../OGLRender_3_2.cpp; sourceTree = "<group>"; };
AB6FBEF5139B6258007BB045 /* slot1_retail_nand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = slot1_retail_nand.cpp; sourceTree = "<group>"; };
AB75226D14C7BB51009B97B3 /* AppIcon_FirmwareConfig.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon_FirmwareConfig.icns; sourceTree = "<group>"; };
AB796C9B15CDCB0F00C59155 /* arm_jit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = arm_jit.cpp; path = ../arm_jit.cpp; sourceTree = "<group>"; };
@ -817,6 +820,7 @@
ABB97873144E89CC00793FA3 /* Icon_ActionReplay_32x32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_ActionReplay_32x32.png; path = Images/Icon_ActionReplay_32x32.png; sourceTree = "<group>"; };
ABB97874144E89CC00793FA3 /* Icon_CodeBreaker_32x32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_CodeBreaker_32x32.png; path = Images/Icon_CodeBreaker_32x32.png; sourceTree = "<group>"; };
ABB97875144E89CC00793FA3 /* Icon_DeSmuME_32x32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_DeSmuME_32x32.png; path = Images/Icon_DeSmuME_32x32.png; sourceTree = "<group>"; };
ABBB421516B4A5F30012E5AB /* OGLRender_3_2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OGLRender_3_2.h; path = ../OGLRender_3_2.h; sourceTree = "<group>"; };
ABBC0F8C1394B1AA0028B6BD /* DefaultUserPrefs.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = DefaultUserPrefs.plist; sourceTree = "<group>"; };
ABBF04A414B515F300E505A0 /* AppIcon_ROMCheats.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon_ROMCheats.icns; sourceTree = "<group>"; };
ABC3AF2B14B7F06900D5B13D /* Icon_VolumeFull_16x16.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_VolumeFull_16x16.png; path = images/Icon_VolumeFull_16x16.png; sourceTree = "<group>"; };
@ -881,7 +885,6 @@
ABD1FE951345AC8400AF11D1 /* ROMReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ROMReader.h; path = ../ROMReader.h; sourceTree = SOURCE_ROOT; };
ABD1FE961345AC8400AF11D1 /* rtc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = rtc.h; path = ../rtc.h; sourceTree = SOURCE_ROOT; };
ABD1FE971345AC8400AF11D1 /* saves.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = saves.h; path = ../saves.h; sourceTree = SOURCE_ROOT; };
ABD1FE981345AC8400AF11D1 /* shaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = shaders.h; path = ../shaders.h; sourceTree = SOURCE_ROOT; };
ABD1FE991345AC8400AF11D1 /* slot1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = slot1.h; path = ../slot1.h; sourceTree = SOURCE_ROOT; };
ABD1FE9A1345AC8400AF11D1 /* sndsdl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sndsdl.h; path = ../sndsdl.h; sourceTree = SOURCE_ROOT; };
ABD1FE9B1345AC8400AF11D1 /* SPU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPU.h; path = ../SPU.h; sourceTree = SOURCE_ROOT; };
@ -1453,6 +1456,7 @@
ABD1FEBF1345AC8400AF11D1 /* movie.cpp */,
ABD1FEC01345AC8400AF11D1 /* NDSSystem.cpp */,
ABD1FEC11345AC8400AF11D1 /* OGLRender.cpp */,
AB68A0DA16B139BC00DE0546 /* OGLRender_3_2.cpp */,
ABD1FEC21345AC8400AF11D1 /* path.cpp */,
ABD1FEC31345AC8400AF11D1 /* rasterize.cpp */,
ABD1FEC41345AC8400AF11D1 /* readwrite.cpp */,
@ -1504,6 +1508,7 @@
ABD1FE8B1345AC8400AF11D1 /* movie.h */,
ABD1FE8C1345AC8400AF11D1 /* NDSSystem.h */,
ABD1FE8D1345AC8400AF11D1 /* OGLRender.h */,
ABBB421516B4A5F30012E5AB /* OGLRender_3_2.h */,
ABD1FE8F1345AC8400AF11D1 /* PACKED.h */,
ABD1FE8E1345AC8400AF11D1 /* PACKED_END.h */,
ABD1FE901345AC8400AF11D1 /* path.h */,
@ -1514,7 +1519,6 @@
ABD1FE951345AC8400AF11D1 /* ROMReader.h */,
ABD1FE961345AC8400AF11D1 /* rtc.h */,
ABD1FE971345AC8400AF11D1 /* saves.h */,
ABD1FE981345AC8400AF11D1 /* shaders.h */,
ABD1FE991345AC8400AF11D1 /* slot1.h */,
ABD1FE9A1345AC8400AF11D1 /* sndsdl.h */,
ABD1FE9B1345AC8400AF11D1 /* SPU.h */,
@ -2370,6 +2374,7 @@
AB40568D169F5DCC0016AC3E /* x86func.cpp in Sources */,
AB405690169F5DCC0016AC3E /* x86operand.cpp in Sources */,
AB405693169F5DCC0016AC3E /* x86util.cpp in Sources */,
AB26D87C16B5253D00A2305C /* OGLRender_3_2.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2513,6 +2518,7 @@
AB40568F169F5DCC0016AC3E /* x86func.cpp in Sources */,
AB405692169F5DCC0016AC3E /* x86operand.cpp in Sources */,
AB405695169F5DCC0016AC3E /* x86util.cpp in Sources */,
AB68A0DD16B139BC00DE0546 /* OGLRender_3_2.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2569,6 +2575,7 @@
AB796D6F15CDCBA200C59155 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
LLVM_LTO = YES;
};
name = Release;
};

View File

@ -250,6 +250,7 @@ bool GetGPULayerState(int gpuType, unsigned int i);
void SetGPUDisplayState(int gpuType, bool state);
bool GetGPUDisplayState(int gpuType);
void RequestOpenGLRenderer_3_2(bool request_3_2);
void SetOpenGLRendererFunctions(bool (*initFunction)(),
bool (*beginOGLFunction)(),
void (*endOGLFunction)());

View File

@ -22,15 +22,18 @@
#import "cocoa_util.h"
#include "sndOSX.h"
#include <OpenGL/OpenGL.h>
#include "../NDSSystem.h"
#include "../GPU.h"
#include "../OGLRender.h"
#include "../rasterize.h"
#include "../SPU.h"
#include "../metaspu/metaspu.h"
#ifdef MAC_OS_X_VERSION_10_7
#include "../OGLRender_3_2.h"
#else
#include "../OGLRender.h"
#endif
#undef BOOL
GPU3DInterface *core3DList[] = {
@ -1851,6 +1854,25 @@ bool GetGPUDisplayState(int gpuType)
return result;
}
void RequestOpenGLRenderer_3_2(bool request_3_2)
{
#ifdef OGLRENDER_3_2_H
if (request_3_2)
{
OGLLoadEntryPoints_3_2_Func = &OGLLoadEntryPoints_3_2;
OGLCreateRenderer_3_2_Func = &OGLCreateRenderer_3_2;
}
else
{
OGLLoadEntryPoints_3_2_Func = NULL;
OGLCreateRenderer_3_2_Func = NULL;
}
#else
OGLLoadEntryPoints_3_2_Func = NULL;
OGLCreateRenderer_3_2_Func = NULL;
#endif
}
void SetOpenGLRendererFunctions(bool (*initFunction)(),
bool (*beginOGLFunction)(),
void (*endOGLFunction)())

View File

@ -48,6 +48,7 @@
+ (NSString *) operatingSystemString;
+ (NSString *) modelIdentifierString;
+ (BOOL) OSVersionCheckMajor:(NSUInteger)checkMajor minor:(NSUInteger)checkMinor revision:(NSUInteger)checkRevision;
@end

View File

@ -181,6 +181,29 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain];
return modelIdentifierStr;
}
+ (BOOL) OSVersionCheckMajor:(NSUInteger)checkMajor minor:(NSUInteger)checkMinor revision:(NSUInteger)checkRevision
{
BOOL result = NO;
NSDictionary *systemDict = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSString *versionString = (NSString *)[systemDict objectForKey:@"ProductVersion"];
const char *versionCString = [versionString cStringUsingEncoding:NSUTF8StringEncoding];
unsigned int OSMajor = 0;
unsigned int OSMinor = 0;
unsigned int OSRevision = 0;
sscanf(versionCString, "%u.%u.%u", &OSMajor, &OSMinor, &OSRevision);
if ((OSMajor > checkMajor) ||
(OSMajor >= checkMajor && OSMinor > checkMinor) ||
(OSMajor >= checkMajor && OSMinor >= checkMinor && OSRevision >= checkRevision) )
{
result = YES;
}
return result;
}
@end
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4

View File

@ -124,6 +124,7 @@
CGLContextObj cglDisplayContext;
NSOpenGLContext *oglRendererContext;
BOOL useContext_3_2;
BOOL isVBOSupported;
BOOL isShadersSupported;
BOOL isVAOSupported;
@ -158,6 +159,8 @@
unsigned int vtxBufferOffset;
}
- (void) setupOpenGL_Legacy;
- (void) setupOpenGL_3_2;
- (void) drawVideoFrame;
- (void) uploadDisplayTextures:(const GLvoid *)textureData width:(const GLsizei)texWidth height:(const GLsizei)texHeight;
- (void) renderDisplayUsingDisplayMode:(const NSInteger)displayModeID;
@ -170,7 +173,7 @@ extern "C"
{
#endif
static GLint SetupShaders(GLuint *vShaderID, GLuint *fShaderID, GLuint *programID);
GLint SetupShaders(GLuint *programID, GLuint *vertShaderID, const char *vertShaderProgram, GLuint *fragShaderID, const char *fragShaderProgram);
bool OSXOpenGLRendererInit();
bool OSXOpenGLRendererBegin();
void OSXOpenGLRendererEnd();

View File

@ -39,13 +39,13 @@
#undef BOOL
// VERTEX SHADER FOR DISPLAY OUTPUT
const char *vShader = {"\
const char *vShader_100 = {"\
attribute vec2 inPosition; \n\
attribute vec2 inTexCoord0; \n\
\n\
uniform vec2 viewSize;\n\
uniform float scalar;\n\
uniform float angleDegrees;\n\
uniform vec2 viewSize; \n\
uniform float scalar; \n\
uniform float angleDegrees; \n\
\n\
varying vec2 vtxTexCoord; \n\
\n\
@ -53,8 +53,8 @@ const char *vShader = {"\
{ \n\
float angleRadians = radians(angleDegrees); \n\
\n\
mat2 projection = mat2( vec2(2.0/viewSize.x, 0.0), \n\
vec2(0.0, 2.0/viewSize.y));\n\
mat2 projection = mat2( vec2(2.0/viewSize.x, 0.0), \n\
vec2( 0.0, 2.0/viewSize.y)); \n\
\n\
mat2 rotation = mat2( vec2(cos(angleRadians), -sin(angleRadians)), \n\
vec2(sin(angleRadians), cos(angleRadians))); \n\
@ -63,20 +63,18 @@ const char *vShader = {"\
vec2( 0.0, scalar)); \n\
\n\
vtxTexCoord = inTexCoord0; \n\
gl_Position = vec4(projection * rotation * scale * inPosition, 1.0, 1.0);\n\
gl_Position = vec4(projection * rotation * scale * inPosition, 1.0, 1.0); \n\
} \n\
"};
"};
// FRAGMENT SHADER FOR DISPLAY OUTPUT
const char *fShader = {"\
uniform sampler2D tex;\n\
\n\
const char *fShader_100 = {"\
varying vec2 vtxTexCoord; \n\
uniform sampler2D tex; \n\
\n\
void main() \n\
{ \n\
vec4 color = texture2D(tex, vtxTexCoord);\n\
gl_FragColor = color;\n\
gl_FragColor = texture2D(tex, vtxTexCoord); \n\
} \n\
"};
@ -1012,6 +1010,19 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
vtxBufferOffset = 0;
// Create a new context for the OpenGL-based emulated 3D renderer
#ifdef MAC_OS_X_VERSION_10_7
NSOpenGLPixelFormatAttribute attrs[] = {
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFAAccelerated,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
(NSOpenGLPixelFormatAttribute)0
};
useContext_3_2 = [CocoaDSUtil OSVersionCheckMajor:10 minor:7 revision:0] ? YES : NO;
#else
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
@ -1019,9 +1030,20 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFAAccelerated,
(NSOpenGLPixelFormatAttribute)0, (NSOpenGLPixelFormatAttribute)0,
(NSOpenGLPixelFormatAttribute)0
};
useContext_3_2 = NO;
#endif
// If we're not using a 3.2 Core Profile context, then remove that
// requirement from the pixel format.
if (!useContext_3_2)
{
attrs[9] = (NSOpenGLPixelFormatAttribute)0;
attrs[10] = (NSOpenGLPixelFormatAttribute)0;
}
NSOpenGLPixelFormat *tempPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
if (tempPixelFormat == nil)
{
@ -1031,22 +1053,26 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
tempPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
}
NSOpenGLPixelBuffer *tempPixelBuffer = [[NSOpenGLPixelBuffer alloc]
initWithTextureTarget:GL_TEXTURE_2D
textureInternalFormat:GL_BGRA
textureMaxMipMapLevel:0
pixelsWide:GPU_DISPLAY_WIDTH
pixelsHigh:GPU_DISPLAY_HEIGHT*2];
NSOpenGLContext *newOGLRendererContext = [[NSOpenGLContext alloc] initWithFormat:tempPixelFormat shareContext:nil];
[newOGLRendererContext setPixelBuffer:tempPixelBuffer cubeMapFace:0 mipMapLevel:0 currentVirtualScreen:[[self openGLContext] currentVirtualScreen]];
[tempPixelFormat release];
[tempPixelBuffer release];
if (!useContext_3_2)
{
NSOpenGLPixelBuffer *tempPixelBuffer = [[NSOpenGLPixelBuffer alloc]
initWithTextureTarget:GL_TEXTURE_2D
textureInternalFormat:GL_BGRA
textureMaxMipMapLevel:0
pixelsWide:GPU_DISPLAY_WIDTH
pixelsHigh:GPU_DISPLAY_HEIGHT*2];
[newOGLRendererContext setPixelBuffer:tempPixelBuffer cubeMapFace:0 mipMapLevel:0 currentVirtualScreen:[[self openGLContext] currentVirtualScreen]];
[tempPixelBuffer release];
}
oglRendererContext = newOGLRendererContext;
OSXOpenGLRendererContext = (CGLContextObj)[oglRendererContext CGLContextObj];
RequestOpenGLRenderer_3_2(useContext_3_2);
SetOpenGLRendererFunctions(&OSXOpenGLRendererInit,
&OSXOpenGLRendererBegin,
&OSXOpenGLRendererEnd);
@ -1149,22 +1175,23 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
vtxIndexBuffer[6] = 4; vtxIndexBuffer[7] = 5; vtxIndexBuffer[8] = 6;
vtxIndexBuffer[9] = 6; vtxIndexBuffer[10] = 7; vtxIndexBuffer[11] = 4;
[self setupOpenGL_Legacy];
}
- (void) setupOpenGL_Legacy
{
// Check the OpenGL capabilities for this renderer
const GLubyte *glExtString = glGetString(GL_EXTENSIONS);
BOOL isPBOSupported = gluCheckExtension((const GLubyte *)"GL_ARB_pixel_buffer_object", glExtString);
// Enable OS X's multithreaded OpenGL engine if both VBOs and PBOs are supported.
//
// If these aren't supported, then multithreading may result in a substantial
// performance penalty.
if (isVBOSupported && isPBOSupported)
{
CGLEnable(cglDisplayContext, kCGLCEMPEngine);
CGLEnable(OSXOpenGLRendererContext, kCGLCEMPEngine);
}
// Set up textures
glGenTextures(1, &displayTexID);
glBindTexture(GL_TEXTURE_2D, displayTexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
// Set up VBOs
isVBOSupported = gluCheckExtension((const GLubyte *)"GL_ARB_vertex_buffer_object", glExtString);
@ -1186,13 +1213,13 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
}
// Set up shaders
isShadersSupported = ( gluCheckExtension((const GLubyte *)"GL_ARB_shader_objects", glExtString) &&
gluCheckExtension((const GLubyte *)"GL_ARB_vertex_shader", glExtString) &&
gluCheckExtension((const GLubyte *)"GL_ARB_fragment_shader", glExtString) &&
gluCheckExtension((const GLubyte *)"GL_ARB_vertex_program", glExtString) );
isShadersSupported = (gluCheckExtension((const GLubyte *)"GL_ARB_shader_objects", glExtString) &&
gluCheckExtension((const GLubyte *)"GL_ARB_vertex_shader", glExtString) &&
gluCheckExtension((const GLubyte *)"GL_ARB_fragment_shader", glExtString) &&
gluCheckExtension((const GLubyte *)"GL_ARB_vertex_program", glExtString) );
if (isShadersSupported)
{
GLint shaderStatus = SetupShaders(&vertexShaderID, &fragmentShaderID, &shaderProgram);
GLint shaderStatus = SetupShaders(&shaderProgram, &vertexShaderID, vShader_100, &fragmentShaderID, fShader_100);
if (shaderStatus == GL_TRUE)
{
glUseProgram(shaderProgram);
@ -1212,10 +1239,10 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
}
// Set up VAO
isVAOSupported = isVBOSupported &&
isShadersSupported &&
(gluCheckExtension((const GLubyte *)"GL_ARB_vertex_array_object", glExtString) ||
gluCheckExtension((const GLubyte *)"GL_APPLE_vertex_array_object", glExtString) );
isVAOSupported = ( isVBOSupported &&
isShadersSupported &&
(gluCheckExtension((const GLubyte *)"GL_ARB_vertex_array_object", glExtString) ||
gluCheckExtension((const GLubyte *)"GL_APPLE_vertex_array_object", glExtString) ) );
if (isVAOSupported)
{
glGenVertexArrays(1, &vaoMainStatesID);
@ -1244,7 +1271,7 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
{
glDisable(GL_ALPHA_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_FOG);
glEnable(GL_TEXTURE_2D);
}
@ -1773,42 +1800,42 @@ CGLContextObj OSXOpenGLRendererContext = NULL;
@end
static GLint SetupShaders(GLuint *vShaderID, GLuint *fShaderID, GLuint *programID)
GLint SetupShaders(GLuint *programID, GLuint *vertShaderID, const char *vertShaderProgram, GLuint *fragShaderID, const char *fragShaderProgram)
{
GLint shaderStatus = GL_TRUE;
*vShaderID = glCreateShader(GL_VERTEX_SHADER);
if (*vShaderID == 0)
*vertShaderID = glCreateShader(GL_VERTEX_SHADER);
if (*vertShaderID == 0)
{
NSLog(@"OpenGL Error - Failed to create vertex shader.");
return shaderStatus;
}
glShaderSource(*vShaderID, 1, (const GLchar **)&vShader, NULL);
glCompileShader(*vShaderID);
glGetShaderiv(*vShaderID, GL_COMPILE_STATUS, &shaderStatus);
glShaderSource(*vertShaderID, 1, (const GLchar **)&vertShaderProgram, NULL);
glCompileShader(*vertShaderID);
glGetShaderiv(*vertShaderID, GL_COMPILE_STATUS, &shaderStatus);
if (shaderStatus == GL_FALSE)
{
glDeleteShader(*vShaderID);
glDeleteShader(*vertShaderID);
NSLog(@"OpenGL Error - Failed to compile vertex shader.");
return shaderStatus;
}
*fShaderID = glCreateShader(GL_FRAGMENT_SHADER);
if (*fShaderID == 0)
*fragShaderID = glCreateShader(GL_FRAGMENT_SHADER);
if (*fragShaderID == 0)
{
glDeleteShader(*vShaderID);
glDeleteShader(*vertShaderID);
NSLog(@"OpenGL Error - Failed to create fragment shader.");
return shaderStatus;
}
glShaderSource(*fShaderID, 1, (const GLchar **)&fShader, NULL);
glCompileShader(*fShaderID);
glGetShaderiv(*fShaderID, GL_COMPILE_STATUS, &shaderStatus);
glShaderSource(*fragShaderID, 1, (const GLchar **)&fragShaderProgram, NULL);
glCompileShader(*fragShaderID);
glGetShaderiv(*fragShaderID, GL_COMPILE_STATUS, &shaderStatus);
if (shaderStatus == GL_FALSE)
{
glDeleteShader(*vShaderID);
glDeleteShader(*fShaderID);
glDeleteShader(*vertShaderID);
glDeleteShader(*fragShaderID);
NSLog(@"OpenGL Error - Failed to compile fragment shader.");
return shaderStatus;
}
@ -1816,14 +1843,14 @@ static GLint SetupShaders(GLuint *vShaderID, GLuint *fShaderID, GLuint *programI
*programID = glCreateProgram();
if (*programID == 0)
{
glDeleteShader(*vShaderID);
glDeleteShader(*fShaderID);
glDeleteShader(*vertShaderID);
glDeleteShader(*fragShaderID);
NSLog(@"OpenGL Error - Failed to create shader program.");
return shaderStatus;
}
glAttachShader(*programID, *vShaderID);
glAttachShader(*programID, *fShaderID);
glAttachShader(*programID, *vertShaderID);
glAttachShader(*programID, *fragShaderID);
glBindAttribLocation(*programID, OGLVertexAttributeID_Position, "inPosition");
glBindAttribLocation(*programID, OGLVertexAttributeID_TexCoord0, "inTexCoord0");
@ -1833,8 +1860,8 @@ static GLint SetupShaders(GLuint *vShaderID, GLuint *fShaderID, GLuint *programI
if (shaderStatus == GL_FALSE)
{
glDeleteProgram(*programID);
glDeleteShader(*vShaderID);
glDeleteShader(*fShaderID);
glDeleteShader(*vertShaderID);
glDeleteShader(*fragShaderID);
NSLog(@"OpenGL Error - Failed to link shader program.");
return shaderStatus;
}