IPHONE: Add a mouse texture buffer surface to VideoContext.

This commit is contained in:
Johannes Schickel 2012-02-24 00:55:52 +01:00
parent 4637d55337
commit 5863f6a556
3 changed files with 13 additions and 20 deletions

View File

@ -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);

View File

@ -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

View File

@ -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];
}