Skip to content

Commit

Permalink
IPHONE: Add a mouse texture buffer surface to VideoContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Feb 23, 2012
1 parent 4637d55 commit 5863f6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion backends/platform/iphone/iphone_common.h
Expand Up @@ -78,6 +78,7 @@ struct VideoContext {
int mouseHotspotX, mouseHotspotY;
uint mouseWidth, mouseHeight;
bool mouseIsVisible;
Graphics::Surface mouseTexture;

// Misc state
GraphicsModes graphicsMode;
Expand All @@ -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);

Expand Down
17 changes: 4 additions & 13 deletions backends/platform/iphone/iphone_video.mm
Expand Up @@ -39,8 +39,6 @@
static UITouch *_firstTouch = NULL;
static UITouch *_secondTouch = NULL;

static unsigned short *_mouseCursor = NULL;

static GLint _renderBufferWidth;
static GLint _renderBufferHeight;

Expand All @@ -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;
}
Expand Down Expand Up @@ -245,6 +238,7 @@ - (void)dealloc {

_videoContext.screenTexture.free();
_videoContext.overlayTexture.free();
_videoContext.mouseTexture.free();
}

- (void)drawRect:(CGRect)frame {
Expand Down Expand Up @@ -318,10 +312,7 @@ - (void)updateMouseCursor {
}

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 {
Expand Down Expand Up @@ -398,8 +389,8 @@ - (void)updateMouseSurface {

//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
Expand Down
14 changes: 8 additions & 6 deletions backends/platform/iphone/osys_video.mm
Expand Up @@ -392,18 +392,20 @@
}

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)
palette = _mouseCursorPalette;
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];
Expand All @@ -414,5 +416,5 @@
}
}

iPhone_setMouseCursor(mouseBuf);
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES];
}

0 comments on commit 5863f6a

Please sign in to comment.