IPHONE: Add support for unfiltered upscaling.

This commit is contained in:
Johannes Schickel 2012-02-20 02:32:10 +01:00
parent 8102e7e645
commit d77253fbe5
6 changed files with 64 additions and 20 deletions

View file

@ -50,6 +50,11 @@ enum UIViewSwipeDirection {
kUIViewSwipeRight = 8
};
typedef enum {
kGraphicsModeLinear = 0,
kGraphicsModeNone = 1
} GraphicsModes;
#ifdef IPHONE_OFFICIAL
void iphone_main(int argc, char **argv);
#endif
@ -65,6 +70,7 @@ void iphone_main(int argc, char *argv[]);
#endif
// On the ObjC side
void iPhone_setGraphicsMode(int mode);
void iPhone_updateScreen(int mouseX, int mouseY);
void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2);
void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2);

View file

@ -62,6 +62,8 @@
- (void)initSurface;
- (void)setGraphicsMode;
- (void)updateSurface;
- (void)updateMainSurface;
- (void)updateOverlaySurface;

View file

@ -24,6 +24,7 @@
#include "iphone_common.h"
static iPhoneView *sharedInstance = nil;
static GraphicsModes _graphicsMode = kGraphicsModeLinear;
static int _width = 0;
static int _height = 0;
static int _fullWidth;
@ -75,6 +76,12 @@ int printOglError(const char *file, int line) {
return retCode;
}
void iPhone_setGraphicsMode(int mode) {
_graphicsMode = mode;
[sharedInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES];
}
void iPhone_showCursor(int state) {
_mouseCursorEnabled = state;
}
@ -201,6 +208,27 @@ bool getLocalMouseCoords(CGPoint *point) {
return true;
}
static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) {
if (!tex)
return;
glBindTexture(GL_TEXTURE_2D, tex); printOpenGLError();
GLint filter = GL_LINEAR;
switch (mode) {
case kGraphicsModeLinear:
filter = GL_LINEAR;
break;
case kGraphicsModeNone:
filter = GL_NEAREST;
break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); printOpenGLError();
}
@implementation iPhoneView
@ -263,6 +291,12 @@ bool getLocalMouseCoords(CGPoint *point) {
// }
}
- (void)setGraphicsMode {
setFilterModeForTexture(_screenTexture, _graphicsMode);
setFilterModeForTexture(_overlayTexture, _graphicsMode);
setFilterModeForTexture(_mouseCursorTexture, _graphicsMode);
}
- (void)updateSurface {
if (!_needsScreenUpdate) {
return;
@ -287,9 +321,7 @@ bool getLocalMouseCoords(CGPoint *point) {
-(void)updateMouseCursor {
if (_mouseCursorTexture == 0) {
glGenTextures(1, &_mouseCursorTexture); printOpenGLError();
glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); printOpenGLError();
setFilterModeForTexture(_mouseCursorTexture, _graphicsMode);
}
glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError();
@ -487,18 +519,14 @@ bool getLocalMouseCoords(CGPoint *point) {
}
glGenTextures(1, &_screenTexture); printOpenGLError();
glBindTexture(GL_TEXTURE_2D, _screenTexture); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); printOpenGLError();
setFilterModeForTexture(_screenTexture, _graphicsMode);
if (_overlayTexture > 0) {
glDeleteTextures(1, &_overlayTexture); printOpenGLError();
}
glGenTextures(1, &_overlayTexture); printOpenGLError();
glBindTexture(GL_TEXTURE_2D, _overlayTexture); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); printOpenGLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); printOpenGLError();
setFilterModeForTexture(_overlayTexture, _graphicsMode);
if (_textureBuffer) {
free(_textureBuffer);

View file

@ -45,7 +45,9 @@
const OSystem::GraphicsMode OSystem_IPHONE::s_supportedGraphicsModes[] = {
{0, 0, 0}
{ "linear", "Linear filtering", kGraphicsModeLinear },
{ "none", "No filtering", kGraphicsModeNone },
{ 0, 0, 0 }
};
AQCallbackStruct OSystem_IPHONE::s_AudioQueue;
@ -60,7 +62,8 @@ OSystem_IPHONE::OSystem_IPHONE() :
_screenOrientation(kScreenOrientationFlippedLandscape), _mouseClickAndDragEnabled(false),
_gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false),
_mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0),
_overlayHeight(0), _overlayWidth(0), _overlayBuffer(0), _mouseCursorPaletteEnabled(false) {
_overlayHeight(0), _overlayWidth(0), _overlayBuffer(0), _mouseCursorPaletteEnabled(false),
_currentGraphicsMode(kGraphicsModeLinear) {
_queuedInputEvent.type = Common::EVENT_INVALID;
_touchpadModeEnabled = !iPhone_isHighResDevice();
_fsFactory = new POSIXFilesystemFactory();

View file

@ -54,12 +54,13 @@ struct AQCallbackStruct {
class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager {
protected:
static const OSystem::GraphicsMode s_supportedGraphicsModes[];
static AQCallbackStruct s_AudioQueue;
static SoundProc s_soundCallback;
static void *s_soundParam;
int _currentGraphicsMode;
Audio::MixerImpl *_mixer;
Graphics::Surface _framebuffer;
@ -129,7 +130,6 @@ public:
virtual bool getFeatureState(Feature f);
virtual const GraphicsMode *getSupportedGraphicsModes() const;
virtual int getDefaultGraphicsMode() const;
bool setGraphicsMode(const char *name);
virtual bool setGraphicsMode(int mode);
virtual int getGraphicsMode() const;
virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format);

View file

@ -31,19 +31,24 @@ const OSystem::GraphicsMode *OSystem_IPHONE::getSupportedGraphicsModes() const {
int OSystem_IPHONE::getDefaultGraphicsMode() const {
return -1;
}
bool OSystem_IPHONE::setGraphicsMode(const char *mode) {
return true;
return kGraphicsModeLinear;
}
bool OSystem_IPHONE::setGraphicsMode(int mode) {
switch (mode) {
case kGraphicsModeNone:
case kGraphicsModeLinear:
_currentGraphicsMode = mode;
iPhone_setGraphicsMode(mode);
return true;
default:
return false;
}
}
int OSystem_IPHONE::getGraphicsMode() const {
return -1;
return _currentGraphicsMode;
}
void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) {