diff options
-rw-r--r-- | backends/platform/iphone/iphone_common.h | 2 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.mm | 17 | ||||
-rw-r--r-- | backends/platform/iphone/osys_video.mm | 14 |
3 files changed, 13 insertions, 20 deletions
diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index 6e97d9d853..4dd9407064 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -78,6 +78,7 @@ struct VideoContext { int mouseHotspotX, mouseHotspotY; uint mouseWidth, mouseHeight; bool mouseIsVisible; + Graphics::Surface mouseTexture; // Misc state GraphicsModes graphicsMode; @@ -89,7 +90,6 @@ void iPhone_updateScreen(); bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY); const char *iPhone_getDocumentsDir(); bool iPhone_isHighResDevice(); -void iPhone_setMouseCursor(unsigned short *buffer); uint getSizeNextPOT(uint size); diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm index cdd8d68b31..d7511c56d4 100644 --- a/backends/platform/iphone/iphone_video.mm +++ b/backends/platform/iphone/iphone_video.mm @@ -39,8 +39,6 @@ static int _needsScreenUpdate = 0; static UITouch *_firstTouch = NULL; static UITouch *_secondTouch = NULL; -static unsigned short *_mouseCursor = NULL; - static GLint _renderBufferWidth; static GLint _renderBufferHeight; @@ -66,11 +64,6 @@ int printOglError(const char *file, int line) { return retCode; } -void iPhone_setMouseCursor(unsigned short *buffer) { - _mouseCursor = buffer; - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; -} - bool iPhone_isHighResDevice() { return _fullHeight > 480; } @@ -245,6 +238,7 @@ const char *iPhone_getDocumentsDir() { _videoContext.screenTexture.free(); _videoContext.overlayTexture.free(); + _videoContext.mouseTexture.free(); } - (void)drawRect:(CGRect)frame { @@ -318,10 +312,7 @@ const char *iPhone_getDocumentsDir() { } glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getSizeNextPOT(_videoContext.mouseWidth), getSizeNextPOT(_videoContext.mouseHeight), 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _mouseCursor); printOpenGLError(); - - free(_mouseCursor); - _mouseCursor = NULL; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _videoContext.mouseTexture.w, _videoContext.mouseTexture.h, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _videoContext.mouseTexture.pixels); printOpenGLError(); } - (void)updateMainSurface { @@ -398,8 +389,8 @@ const char *iPhone_getDocumentsDir() { //printf("Cursor: width %u height %u\n", _videoContext.mouseWidth, _videoContext.mouseHeight); - float texWidth = _videoContext.mouseWidth / (float)getSizeNextPOT(_videoContext.mouseWidth); - float texHeight = _videoContext.mouseHeight / (float)getSizeNextPOT(_videoContext.mouseHeight); + float texWidth = _videoContext.mouseWidth / (float)_videoContext.mouseTexture.w; + float texHeight = _videoContext.mouseHeight / (float)_videoContext.mouseTexture.h; const GLfloat texCoords[] = { // Top left diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm index 7e2b1eee07..6fa800a004 100644 --- a/backends/platform/iphone/osys_video.mm +++ b/backends/platform/iphone/osys_video.mm @@ -392,11 +392,12 @@ void OSystem_IPHONE::setCursorPalette(const byte *colors, uint start, uint num) } void OSystem_IPHONE::updateMouseTexture() { - int texWidth = getSizeNextPOT(_videoContext->mouseWidth); - int texHeight = getSizeNextPOT(_videoContext->mouseHeight); - int bufferSize = texWidth * texHeight * sizeof(int16); - uint16 *mouseBuf = (uint16 *)malloc(bufferSize); - memset(mouseBuf, 0, bufferSize); + uint texWidth = getSizeNextPOT(_videoContext->mouseWidth); + uint texHeight = getSizeNextPOT(_videoContext->mouseHeight); + + Graphics::Surface &mouseTexture = _videoContext->mouseTexture; + if (mouseTexture.w != texWidth || mouseTexture.h != texHeight) + mouseTexture.create(texWidth, texHeight, Graphics::createPixelFormat<5551>()); const uint16 *palette; if (_mouseCursorPaletteEnabled) @@ -404,6 +405,7 @@ void OSystem_IPHONE::updateMouseTexture() { else palette = _gamePaletteRGBA5551; + uint16 *mouseBuf = (uint16 *)mouseTexture.getBasePtr(0, 0); for (uint x = 0; x < _videoContext->mouseWidth; ++x) { for (uint y = 0; y < _videoContext->mouseHeight; ++y) { const byte color = _mouseBuf[y * _videoContext->mouseWidth + x]; @@ -414,5 +416,5 @@ void OSystem_IPHONE::updateMouseTexture() { } } - iPhone_setMouseCursor(mouseBuf); + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; } |