diff --git a/desmume/src/cocoa/cocoa_output.h b/desmume/src/cocoa/cocoa_output.h index cd7bddd01..aaf74374b 100644 --- a/desmume/src/cocoa/cocoa_output.h +++ b/desmume/src/cocoa/cocoa_output.h @@ -16,12 +16,14 @@ along with the this software. If not, see . */ -#import +#import #include #include #import "cocoa_util.h" +@class NSImage; +@class NSBitmapImageRep; typedef struct { diff --git a/desmume/src/cocoa/cocoa_output.mm b/desmume/src/cocoa/cocoa_output.mm index 3ac1c2984..003f1f4a0 100644 --- a/desmume/src/cocoa/cocoa_output.mm +++ b/desmume/src/cocoa/cocoa_output.mm @@ -28,14 +28,15 @@ #include "../SPU.h" #include "../metaspu/metaspu.h" -#include - #ifdef MAC_OS_X_VERSION_10_7 #include "../OGLRender_3_2.h" #else #include "../OGLRender.h" #endif +#import +#include + #undef BOOL GPU3DInterface *core3DList[] = { @@ -1320,7 +1321,7 @@ GPU3DInterface *core3DList[] = { } uint32_t *bitmapData = (uint32_t *)[imageRep bitmapData]; - RGBA5551ToRGBA8888Buffer((const uint16_t *)[self.frameData bytes], bitmapData, (w * h)); + RGB555ToRGBA8888Buffer((const uint16_t *)[self.frameData bytes], bitmapData, (w * h)); #ifdef __BIG_ENDIAN__ uint32_t *bitmapDataEnd = bitmapData + (w * h); @@ -1622,7 +1623,7 @@ GPU3DInterface *core3DList[] = { } else { - RGBA5551ToRGBA8888Buffer((const uint16_t *)[mainData bytes], (uint32_t *)[vf srcBufferPtr], [mainData length] / sizeof(UInt16)); + RGB555ToRGBA8888Buffer((const uint16_t *)[mainData bytes], (uint32_t *)[vf srcBufferPtr], [mainData length] / sizeof(UInt16)); const UInt32 *vfDestBuffer = [vf runFilter]; [videoDelegate doProcessVideoFrame:vfDestBuffer displayMode:displayModeID width:destWidth height:destHeight]; } @@ -1973,6 +1974,7 @@ void DestroyOpenGLRenderer() CGLReleasePBuffer(OSXOpenGLRendererPBuffer); CGLReleaseContext(OSXOpenGLRendererContext); OSXOpenGLRendererContext = NULL; + OSXOpenGLRendererPBuffer = NULL; } void RequestOpenGLRenderer_3_2(bool request_3_2) diff --git a/desmume/src/cocoa/cocoa_rom.mm b/desmume/src/cocoa/cocoa_rom.mm index 1c0eebc4b..94917aeb5 100644 --- a/desmume/src/cocoa/cocoa_rom.mm +++ b/desmume/src/cocoa/cocoa_rom.mm @@ -571,14 +571,14 @@ void RomIconToRGBA8888(uint32_t *bitmapData) iconClutPtr = (uint16_t *)&MMU.CART_ROM[iconOffset + 0x220] + 1; iconPixPtr = (uint32_t *)&MMU.CART_ROM[iconOffset + 0x20]; - // Setup the 4-bit color CLUT. + // Setup the 4-bit CLUT. // - // The actual color values are stored with the ROM icon data in RGBA5551 format. + // The actual color values are stored with the ROM icon data in RGB555 format. // We convert these color values and store them in the CLUT as RGBA8888 values. // // The first entry always represents the alpha, so we can just ignore it. clut[0] = 0x00000000; - RGBA5551ToRGBA8888Buffer(iconClutPtr, &clut[1], 15); + RGB555ToRGBA8888Buffer(iconClutPtr, &clut[1], 15); // Load the image from the icon pixel data. // diff --git a/desmume/src/cocoa/cocoa_util.h b/desmume/src/cocoa/cocoa_util.h index ce5aeb9b7..c1c35665d 100644 --- a/desmume/src/cocoa/cocoa_util.h +++ b/desmume/src/cocoa/cocoa_util.h @@ -16,7 +16,7 @@ along with the this software. If not, see . */ -#import +#import #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 #include "macosx_10_4_compat.h" @@ -93,10 +93,10 @@ extern "C" { #endif -uint32_t RGBA5551ToRGBA8888(const uint16_t color16); -uint32_t RGBA8888ToRGB888(const uint32_t color24); -void RGBA5551ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels); -void RGB888ToRGBA8888Buffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels); +uint32_t RGB555ToRGBA8888(const uint16_t color16); +uint32_t RGBA8888ForceOpaque(const uint32_t color32); +void RGB555ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels); +void RGBA8888ForceOpaqueBuffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels); NSSize GetTransformedBounds(NSSize normalBounds, double scalar, double angleDegrees); double GetMaxScalarInBounds(double normalBoundsWidth, double normalBoundsHeight, double keepInBoundsWidth, double keepInBoundsHeight); NSPoint GetNormalPointFromTransformedPoint(NSPoint transformedPt, NSSize normalBounds, NSSize transformBounds, double scalar, double angleDegrees); diff --git a/desmume/src/cocoa/cocoa_util.mm b/desmume/src/cocoa/cocoa_util.mm index 35bf5f01a..80387efc6 100644 --- a/desmume/src/cocoa/cocoa_util.mm +++ b/desmume/src/cocoa/cocoa_util.mm @@ -19,6 +19,7 @@ #import "cocoa_util.h" #import "cocoa_globals.h" #import "types.h" +#import #include #include @@ -320,12 +321,12 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain]; @end /******************************************************************************************** - RGBA5551ToRGBA8888() - INLINE + RGB555ToRGBA8888() - INLINE - Converts a color from 16-bit RGBA5551 format into 32-bit RGBA8888 format. + Converts a color from 15-bit RGB555 format into 32-bit RGBA8888 format. Takes: - color16 - The pixel in 16-bit RGBA5551 format. + color16 - The pixel in 15-bit RGB555 format. Returns: A 32-bit unsigned integer containing the RGBA8888 formatted color. @@ -333,7 +334,7 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain]; Details: The input and output pixels are expected to have little-endian byte order. ********************************************************************************************/ -FORCEINLINE uint32_t RGBA5551ToRGBA8888(const uint16_t color16) +FORCEINLINE uint32_t RGB555ToRGBA8888(const uint16_t color16) { return ((color16 & 0x001F) << 3) | ((color16 & 0x03E0) << 6) | @@ -342,31 +343,31 @@ FORCEINLINE uint32_t RGBA5551ToRGBA8888(const uint16_t color16) } /******************************************************************************************** - RGB888ToRGBA8888() - INLINE - - Converts a color from 24-bit RGB888 format into 32-bit RGBA8888 format. + RGBA8888ForceOpaque() - INLINE + Forces the alpha channel of a 32-bit RGBA8888 color to a value of 0xFF. + Takes: - color24 - The pixel in 24-bit RGB888 format. - + color32 - The pixel in 32-bit RGBA8888 format. + Returns: A 32-bit unsigned integer containing the RGBA8888 formatted color. - + Details: The input and output pixels are expected to have little-endian byte order. ********************************************************************************************/ -FORCEINLINE uint32_t RGB888ToRGBA8888(const uint32_t color24) +FORCEINLINE uint32_t RGBA8888ForceOpaque(const uint32_t color32) { - return color24 | 0xFF000000; + return color32 | 0xFF000000; } /******************************************************************************************** - RGBA5551ToRGBA8888Buffer() + RGB555ToRGBA8888Buffer() - Copies a 16-bit RGBA5551 pixel buffer into a 32-bit RGBA8888 pixel buffer. + Copies a 15-bit RGB555 pixel buffer into a 32-bit RGBA8888 pixel buffer. Takes: - srcBuffer - Pointer to the source 16-bit RGBA5551 pixel buffer. + srcBuffer - Pointer to the source 15-bit RGB555 pixel buffer. destBuffer - Pointer to the destination 32-bit RGBA8888 pixel buffer. @@ -380,23 +381,24 @@ FORCEINLINE uint32_t RGB888ToRGBA8888(const uint32_t color24) Also, it is the caller's responsibility to ensure that the source and destination buffers are large enough to accomodate the requested number of pixels. ********************************************************************************************/ -void RGBA5551ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels) +void RGB555ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels) { const uint32_t *__restrict__ destBufferEnd = destBuffer + numberPixels; while (destBuffer < destBufferEnd) { - *destBuffer++ = RGBA5551ToRGBA8888(*srcBuffer++); + *destBuffer++ = RGB555ToRGBA8888(*srcBuffer++); } } /******************************************************************************************** - RGB888ToRGBA8888Buffer() + RGBA8888ForceOpaqueBuffer() - Copies a 24-bit RGB888 pixel buffer into a 32-bit RGBA8888 pixel buffer. + Copies a 32-bit RGBA8888 pixel buffer into another 32-bit RGBA8888 pixel buffer. + The pixels in the destination buffer will have an alpha value of 0xFF. Takes: - srcBuffer - Pointer to the source 24-bit RGB888 pixel buffer. + srcBuffer - Pointer to the source 32-bit RGBA8888 pixel buffer. destBuffer - Pointer to the destination 32-bit RGBA8888 pixel buffer. @@ -410,13 +412,13 @@ void RGBA5551ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t * Also, it is the caller's responsibility to ensure that the source and destination buffers are large enough to accomodate the requested number of pixels. ********************************************************************************************/ -void RGB888ToRGBA8888Buffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels) +void RGBA8888ForceOpaqueBuffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels) { const uint32_t *__restrict__ destBufferEnd = destBuffer + numberPixels; while (destBuffer < destBufferEnd) { - *destBuffer++ = RGB888ToRGBA8888(*srcBuffer++); + *destBuffer++ = RGBA8888ForceOpaque(*srcBuffer++); } } diff --git a/desmume/src/cocoa/cocoa_videofilter.mm b/desmume/src/cocoa/cocoa_videofilter.mm index 1e6a306b3..0e2db60a4 100644 --- a/desmume/src/cocoa/cocoa_videofilter.mm +++ b/desmume/src/cocoa/cocoa_videofilter.mm @@ -139,7 +139,7 @@ } uint32_t *bitmapData = (uint32_t *)[imageRep bitmapData]; - RGB888ToRGBA8888Buffer((const uint32_t *)[self runFilter], bitmapData, (w * h)); + RGBA8888ForceOpaqueBuffer((const uint32_t *)[self runFilter], bitmapData, (w * h)); #ifdef __BIG_ENDIAN__ uint32_t *bitmapDataEnd = bitmapData + (w * h); diff --git a/desmume/src/cocoa/userinterface/displayView.h b/desmume/src/cocoa/userinterface/displayView.h index e9b43acce..58f58ec05 100644 --- a/desmume/src/cocoa/userinterface/displayView.h +++ b/desmume/src/cocoa/userinterface/displayView.h @@ -22,6 +22,12 @@ #import "cocoa_output.h" +enum OGLVertexAttributeID +{ + OGLVertexAttributeID_Position = 0, + OGLVertexAttributeID_TexCoord0 = 8 +}; + @class DisplayViewDelegate; @class CocoaDSController; @@ -154,22 +160,16 @@ unsigned int vtxBufferOffset; } -- (void) setupOpenGL_Legacy; +- (void) setupOpenGL; +- (void) shutdownOpenGL; +- (void) setupShaderIO; +- (BOOL) setupShadersWithVertexProgram:(const char *)vertShaderProgram fragmentProgram:(const char *)fragShaderProgram; - (void) drawVideoFrame; +- (void) uploadVertices; +- (void) uploadTexCoords; - (void) uploadDisplayTextures:(const GLvoid *)textureData displayMode:(const NSInteger)displayModeID width:(const GLsizei)texWidth height:(const GLsizei)texHeight; - (void) renderDisplayUsingDisplayMode:(const NSInteger)displayModeID; - (void) updateDisplayVerticesUsingDisplayMode:(const NSInteger)displayModeID orientation:(const NSInteger)displayOrientationID; - (void) updateTexCoordS:(GLfloat)s T:(GLfloat)t; @end - -#ifdef __cplusplus -extern "C" -{ -#endif - -GLint SetupShaders(GLuint *programID, GLuint *vertShaderID, GLuint *fragShaderID, const char *vertShaderProgram, const char *fragShaderProgram); - -#ifdef __cplusplus -} -#endif diff --git a/desmume/src/cocoa/userinterface/displayView.mm b/desmume/src/cocoa/userinterface/displayView.mm index 32709ff85..6329edc33 100644 --- a/desmume/src/cocoa/userinterface/displayView.mm +++ b/desmume/src/cocoa/userinterface/displayView.mm @@ -24,14 +24,14 @@ #import "cocoa_videofilter.h" #import "cocoa_util.h" -#include #include +#include #include #undef BOOL // VERTEX SHADER FOR DISPLAY OUTPUT -const char *vShader_100 = {"\ +const char *vertexProgram_100 = {"\ attribute vec2 inPosition; \n\ attribute vec2 inTexCoord0; \n\ \n\ @@ -60,7 +60,7 @@ const char *vShader_100 = {"\ "}; // FRAGMENT SHADER FOR DISPLAY OUTPUT -const char *fShader_100 = {"\ +const char *fragmentProgram_100 = {"\ varying vec2 vtxTexCoord; \n\ uniform sampler2D tex; \n\ \n\ @@ -70,12 +70,6 @@ const char *fShader_100 = {"\ } \n\ "}; -enum OGLVertexAttributeID -{ - OGLVertexAttributeID_Position = 0, - OGLVertexAttributeID_TexCoord0 = 8, -}; - @implementation DisplayViewDelegate @@ -824,7 +818,7 @@ enum OGLVertexAttributeID } uint32_t *bitmapData = (uint32_t *)[imageRep bitmapData]; - RGBA5551ToRGBA8888Buffer((const uint16_t *)videoFrameData, bitmapData, (imageWidth * imageHeight)); + RGB555ToRGBA8888Buffer((const uint16_t *)videoFrameData, bitmapData, (imageWidth * imageHeight)); #ifdef __BIG_ENDIAN__ uint32_t *bitmapDataEnd = bitmapData + (imageWidth * imageHeight); @@ -1003,24 +997,7 @@ enum OGLVertexAttributeID CGLContextObj prevContext = CGLGetCurrentContext(); CGLSetCurrentContext(cglDisplayContext); - glDeleteTextures(1, &displayTexID); - - glDeleteVertexArraysAPPLE(1, &vaoMainStatesID); - glDeleteBuffersARB(1, &vboVertexID); - glDeleteBuffersARB(1, &vboTexCoordID); - glDeleteBuffersARB(1, &vboElementID); - - if (isShaderSupported) - { - glUseProgram(0); - - glDetachShader(shaderProgram, vertexShaderID); - glDetachShader(shaderProgram, fragmentShaderID); - - glDeleteProgram(shaderProgram); - glDeleteShader(vertexShaderID); - glDeleteShader(fragmentShaderID); - } + [self shutdownOpenGL]; CGLSetCurrentContext(prevContext); @@ -1061,10 +1038,10 @@ enum OGLVertexAttributeID vtxIndexBuffer[6] = 4; vtxIndexBuffer[7] = 5; vtxIndexBuffer[8] = 6; vtxIndexBuffer[9] = 6; vtxIndexBuffer[10] = 7; vtxIndexBuffer[11] = 4; - [self setupOpenGL_Legacy]; + [self setupOpenGL]; } -- (void) setupOpenGL_Legacy +- (void) setupOpenGL { // Check the OpenGL capabilities for this renderer const GLubyte *glExtString = glGetString(GL_EXTENSIONS); @@ -1089,8 +1066,8 @@ enum OGLVertexAttributeID #endif if (isShaderSupported) { - GLint shaderStatus = SetupShaders(&shaderProgram, &vertexShaderID, &fragmentShaderID, vShader_100, fShader_100); - if (shaderStatus == GL_TRUE) + BOOL isShaderSetUp = [self setupShadersWithVertexProgram:vertexProgram_100 fragmentProgram:fragmentProgram_100]; + if (isShaderSetUp) { glUseProgram(shaderProgram); @@ -1172,11 +1149,125 @@ enum OGLVertexAttributeID glClear(GL_COLOR_BUFFER_BIT); } +- (void) shutdownOpenGL +{ + glDeleteTextures(1, &displayTexID); + + glDeleteVertexArraysAPPLE(1, &vaoMainStatesID); + glDeleteBuffersARB(1, &vboVertexID); + glDeleteBuffersARB(1, &vboTexCoordID); + glDeleteBuffersARB(1, &vboElementID); + + if (isShaderSupported) + { + glUseProgram(0); + + glDetachShader(shaderProgram, vertexShaderID); + glDetachShader(shaderProgram, fragmentShaderID); + + glDeleteProgram(shaderProgram); + glDeleteShader(vertexShaderID); + glDeleteShader(fragmentShaderID); + } +} + +- (void) setupShaderIO +{ + glBindAttribLocation(shaderProgram, OGLVertexAttributeID_Position, "inPosition"); + glBindAttribLocation(shaderProgram, OGLVertexAttributeID_TexCoord0, "inTexCoord0"); +} + +- (BOOL) setupShadersWithVertexProgram:(const char *)vertShaderProgram fragmentProgram:(const char *)fragShaderProgram +{ + BOOL result = NO; + GLint shaderStatus = GL_TRUE; + + vertexShaderID = glCreateShader(GL_VERTEX_SHADER); + if (vertexShaderID == 0) + { + NSLog(@"OpenGL Error - Failed to create vertex shader."); + return result; + } + + glShaderSource(vertexShaderID, 1, (const GLchar **)&vertShaderProgram, NULL); + glCompileShader(vertexShaderID); + glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &shaderStatus); + if (shaderStatus == GL_FALSE) + { + glDeleteShader(vertexShaderID); + NSLog(@"OpenGL Error - Failed to compile vertex shader."); + return result; + } + + fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); + if (fragmentShaderID == 0) + { + glDeleteShader(vertexShaderID); + NSLog(@"OpenGL Error - Failed to create fragment shader."); + return result; + } + + glShaderSource(fragmentShaderID, 1, (const GLchar **)&fragShaderProgram, NULL); + glCompileShader(fragmentShaderID); + glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &shaderStatus); + if (shaderStatus == GL_FALSE) + { + glDeleteShader(vertexShaderID); + glDeleteShader(fragmentShaderID); + NSLog(@"OpenGL Error - Failed to compile fragment shader."); + return result; + } + + shaderProgram = glCreateProgram(); + if (shaderProgram == 0) + { + glDeleteShader(vertexShaderID); + glDeleteShader(fragmentShaderID); + NSLog(@"OpenGL Error - Failed to create shader program."); + return result; + } + + glAttachShader(shaderProgram, vertexShaderID); + glAttachShader(shaderProgram, fragmentShaderID); + + [self setupShaderIO]; + + glLinkProgram(shaderProgram); + glGetProgramiv(shaderProgram, GL_LINK_STATUS, &shaderStatus); + if (shaderStatus == GL_FALSE) + { + glDeleteProgram(shaderProgram); + glDeleteShader(vertexShaderID); + glDeleteShader(fragmentShaderID); + NSLog(@"OpenGL Error - Failed to link shader program."); + return result; + } + + glValidateProgram(shaderProgram); + + result = YES; + return result; +} + - (void) drawVideoFrame { CGLFlushDrawable(cglDisplayContext); } +- (void) uploadVertices +{ + glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboVertexID); + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLint) * (2 * 8), vtxBuffer + vtxBufferOffset); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); +} + +- (void) uploadTexCoords +{ + glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboTexCoordID); + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLfloat) * (2 * 8), texCoordBuffer); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); +} + - (void) uploadDisplayTextures:(const GLvoid *)textureData displayMode:(const NSInteger)displayModeID width:(const GLsizei)texWidth height:(const GLsizei)texHeight { if (textureData == NULL) @@ -1201,10 +1292,7 @@ enum OGLVertexAttributeID { lastDisplayMode = displayModeID; [self updateDisplayVerticesUsingDisplayMode:displayModeID orientation:currentDisplayOrientation]; - - glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboVertexID); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLint) * (2 * 8), vtxBuffer + vtxBufferOffset); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + [self uploadVertices]; } const GLsizei vtxElementCount = (displayModeID == DS_DISPLAY_TYPE_COMBO) ? 12 : 6; @@ -1391,8 +1479,8 @@ enum OGLVertexAttributeID - (void)doProcessVideoFrame:(const void *)videoFrameData displayMode:(const NSInteger)displayModeID width:(const NSInteger)frameWidth height:(const NSInteger)frameHeight { CGLLockContext(cglDisplayContext); - CGLSetCurrentContext(cglDisplayContext); + [self uploadDisplayTextures:videoFrameData displayMode:displayModeID width:frameWidth height:frameHeight]; [self renderDisplayUsingDisplayMode:displayModeID]; [self drawVideoFrame]; @@ -1421,7 +1509,7 @@ enum OGLVertexAttributeID CGLUnlockContext(cglDisplayContext); } -- (void) doTransformView:(const DisplayOutputTransformData *)transformData +- (void)doTransformView:(const DisplayOutputTransformData *)transformData { const GLfloat angleDegrees = (GLfloat)transformData->rotation; const GLfloat s = (GLfloat)transformData->scale; @@ -1448,8 +1536,8 @@ enum OGLVertexAttributeID - (void)doRedraw { CGLLockContext(cglDisplayContext); - CGLSetCurrentContext(cglDisplayContext); + [self renderDisplayUsingDisplayMode:lastDisplayMode]; [self drawVideoFrame]; @@ -1464,9 +1552,7 @@ enum OGLVertexAttributeID CGLLockContext(cglDisplayContext); CGLSetCurrentContext(cglDisplayContext); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboVertexID); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLint) * (2 * 8), vtxBuffer + vtxBufferOffset); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + [self uploadVertices]; CGLUnlockContext(cglDisplayContext); } @@ -1476,6 +1562,7 @@ enum OGLVertexAttributeID const GLint textureFilter = useBilinear ? GL_LINEAR : GL_NEAREST; CGLLockContext(cglDisplayContext); + CGLSetCurrentContext(cglDisplayContext); glBindTexture(GL_TEXTURE_2D, displayTexID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, textureFilter); @@ -1493,9 +1580,7 @@ enum OGLVertexAttributeID CGLLockContext(cglDisplayContext); CGLSetCurrentContext(cglDisplayContext); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboVertexID); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLint) * (2 * 8), vtxBuffer + vtxBufferOffset); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + [self uploadVertices]; CGLUnlockContext(cglDisplayContext); } @@ -1514,9 +1599,7 @@ enum OGLVertexAttributeID CGLLockContext(cglDisplayContext); CGLSetCurrentContext(cglDisplayContext); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboVertexID); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLint) * (2 * 8), vtxBuffer + vtxBufferOffset); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + [self uploadVertices]; if (lastDisplayMode == DS_DISPLAY_TYPE_COMBO) { @@ -1530,7 +1613,6 @@ enum OGLVertexAttributeID - (void)doVerticalSyncChanged:(BOOL)useVerticalSync { const GLint swapInt = useVerticalSync ? 1 : 0; - CGLSetParameter(cglDisplayContext, kCGLCPSwapInterval, &swapInt); } @@ -1573,87 +1655,15 @@ enum OGLVertexAttributeID [self updateTexCoordS:s T:t]; CGLLockContext(cglDisplayContext); + CGLSetCurrentContext(cglDisplayContext); glBindTexture(GL_TEXTURE_2D, displayTexID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)potW, (GLsizei)potH, 0, GL_BGRA, glTexPixelFormat, glTexBack); glBindTexture(GL_TEXTURE_2D, 0); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboTexCoordID); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(GLfloat) * (2 * 8), texCoordBuffer); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + [self uploadTexCoords]; CGLUnlockContext(cglDisplayContext); } @end - -GLint SetupShaders(GLuint *programID, GLuint *vertShaderID, GLuint *fragShaderID, const char *vertShaderProgram, const char *fragShaderProgram) -{ - GLint shaderStatus = GL_TRUE; - - *vertShaderID = glCreateShader(GL_VERTEX_SHADER); - if (*vertShaderID == 0) - { - NSLog(@"OpenGL Error - Failed to create vertex shader."); - return shaderStatus; - } - - glShaderSource(*vertShaderID, 1, (const GLchar **)&vertShaderProgram, NULL); - glCompileShader(*vertShaderID); - glGetShaderiv(*vertShaderID, GL_COMPILE_STATUS, &shaderStatus); - if (shaderStatus == GL_FALSE) - { - glDeleteShader(*vertShaderID); - NSLog(@"OpenGL Error - Failed to compile vertex shader."); - return shaderStatus; - } - - *fragShaderID = glCreateShader(GL_FRAGMENT_SHADER); - if (*fragShaderID == 0) - { - glDeleteShader(*vertShaderID); - NSLog(@"OpenGL Error - Failed to create fragment shader."); - return shaderStatus; - } - - glShaderSource(*fragShaderID, 1, (const GLchar **)&fragShaderProgram, NULL); - glCompileShader(*fragShaderID); - glGetShaderiv(*fragShaderID, GL_COMPILE_STATUS, &shaderStatus); - if (shaderStatus == GL_FALSE) - { - glDeleteShader(*vertShaderID); - glDeleteShader(*fragShaderID); - NSLog(@"OpenGL Error - Failed to compile fragment shader."); - return shaderStatus; - } - - *programID = glCreateProgram(); - if (*programID == 0) - { - glDeleteShader(*vertShaderID); - glDeleteShader(*fragShaderID); - NSLog(@"OpenGL Error - Failed to create shader program."); - return shaderStatus; - } - - glAttachShader(*programID, *vertShaderID); - glAttachShader(*programID, *fragShaderID); - - glBindAttribLocation(*programID, OGLVertexAttributeID_Position, "inPosition"); - glBindAttribLocation(*programID, OGLVertexAttributeID_TexCoord0, "inTexCoord0"); - - glLinkProgram(*programID); - glGetProgramiv(*programID, GL_LINK_STATUS, &shaderStatus); - if (shaderStatus == GL_FALSE) - { - glDeleteProgram(*programID); - glDeleteShader(*vertShaderID); - glDeleteShader(*fragShaderID); - NSLog(@"OpenGL Error - Failed to link shader program."); - return shaderStatus; - } - - glValidateProgram(*programID); - - return shaderStatus; -} diff --git a/desmume/src/cocoa/userinterface/preferencesWindowDelegate.mm b/desmume/src/cocoa/userinterface/preferencesWindowDelegate.mm index 7195f93fe..6051684d8 100644 --- a/desmume/src/cocoa/userinterface/preferencesWindowDelegate.mm +++ b/desmume/src/cocoa/userinterface/preferencesWindowDelegate.mm @@ -81,7 +81,7 @@ NSArray *imageRepArray = [videoFilterImage representations]; const NSBitmapImageRep *imageRep = [imageRepArray objectAtIndex:0]; - RGB888ToRGBA8888Buffer((const uint32_t *)[imageRep bitmapData], (uint32_t *)[videoFilter srcBufferPtr], (64 * 64)); + RGBA8888ForceOpaqueBuffer((const uint32_t *)[imageRep bitmapData], (uint32_t *)[videoFilter srcBufferPtr], (64 * 64)); [videoFilterImage release]; BOOL useBilinear = [[NSUserDefaults standardUserDefaults] boolForKey:@"DisplayView_UseBilinearOutput"]; @@ -118,7 +118,7 @@ } } - RGB888ToRGBA8888Buffer((const uint32_t *)[videoFilter runFilter], (uint32_t *)[bilinearVideoFilter srcBufferPtr], (vfWidth * vfHeight)); + RGBA8888ForceOpaqueBuffer((const uint32_t *)[videoFilter runFilter], (uint32_t *)[bilinearVideoFilter srcBufferPtr], (vfWidth * vfHeight)); [bindings setObject:[bilinearVideoFilter image] forKey:@"VideoFilterPreviewImage"]; iconVolumeFull = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Icon_VolumeFull_16x16" ofType:@"png"]]; @@ -501,7 +501,7 @@ } } - RGB888ToRGBA8888Buffer((const uint32_t *)[videoFilter runFilter], (uint32_t *)[bilinearVideoFilter srcBufferPtr], (vfWidth * vfHeight)); + RGBA8888ForceOpaqueBuffer((const uint32_t *)[videoFilter runFilter], (uint32_t *)[bilinearVideoFilter srcBufferPtr], (vfWidth * vfHeight)); NSBitmapImageRep *newPreviewImageRep = [bilinearVideoFilter bitmapImageRep]; NSImage *videoFilterPreviewImage = [bindings objectForKey:@"VideoFilterPreviewImage"];