iOS: add scaling support

master
Maksim 2020-04-19 13:27:02 +02:00
parent 9574090ad9
commit 7fdb63d3cc
2 changed files with 67 additions and 55 deletions

View File

@ -24,7 +24,7 @@ namespace irr
{
namespace video
{
struct SEAGLManagerDataStorage
{
SEAGLManagerDataStorage() : Layer(0), Context(0)
@ -40,7 +40,7 @@ CEAGLManager::CEAGLManager() : IContextManager(), Configured(false), DataStorage
#ifdef _DEBUG
setDebugName("CEAGLManager");
#endif
DataStorage = new SEAGLManagerDataStorage();
}
@ -49,7 +49,7 @@ CEAGLManager::~CEAGLManager()
destroyContext();
destroySurface();
terminate();
delete static_cast<SEAGLManagerDataStorage*>(DataStorage);
}
@ -62,7 +62,7 @@ bool CEAGLManager::initialize(const SIrrlichtCreationParameters& params, const S
Params = params;
Data = data;
UIView* view = (__bridge UIView*)data.OpenGLiOS.View;
if (view == nil || ![[view layer] isKindOfClass:[CAEAGLLayer class]])
@ -70,8 +70,9 @@ bool CEAGLManager::initialize(const SIrrlichtCreationParameters& params, const S
os::Printer::log("Could not get EAGL display.");
return false;
}
dataStorage->Layer = (CAEAGLLayer*)[view layer];
dataStorage->Layer.contentsScale = view.contentScaleFactor;
return true;
}
@ -79,11 +80,11 @@ bool CEAGLManager::initialize(const SIrrlichtCreationParameters& params, const S
void CEAGLManager::terminate()
{
SEAGLManagerDataStorage* dataStorage = static_cast<SEAGLManagerDataStorage*>(DataStorage);
[EAGLContext setCurrentContext:0];
destroySurface();
if (dataStorage->Layer != nil)
dataStorage->Layer = 0;
}
@ -92,13 +93,13 @@ bool CEAGLManager::generateSurface()
{
SEAGLManagerDataStorage* dataStorage = static_cast<SEAGLManagerDataStorage*>(DataStorage);
CAEAGLLayer* layer = dataStorage->Layer;
if (layer == nil)
return false;
if (Configured)
return true;
NSDictionary* attribs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO],
kEAGLDrawablePropertyRetainedBacking,
@ -108,7 +109,7 @@ bool CEAGLManager::generateSurface()
[layer setOpaque:(Params.WithAlphaChannel) ? YES : NO];
[layer setDrawableProperties:attribs];
Configured = true;
return true;
@ -118,13 +119,13 @@ void CEAGLManager::destroySurface()
{
SEAGLManagerDataStorage* dataStorage = static_cast<SEAGLManagerDataStorage*>(DataStorage);
CAEAGLLayer* layer = dataStorage->Layer;
if (layer == nil)
return;
[layer setOpaque:NO];
[layer setDrawableProperties:nil];
Configured = false;
}
@ -156,7 +157,7 @@ bool CEAGLManager::generateContext()
os::Printer::log("Could not create EAGL context.", ELL_ERROR);
return false;
}
Data.OpenGLiOS.Context = (__bridge void*)dataStorage->Context;
os::Printer::log("EAGL context created with OpenGLESVersion: ", core::stringc(static_cast<int>(OpenGLESVersion)), ELL_DEBUG);
@ -167,7 +168,7 @@ bool CEAGLManager::generateContext()
void CEAGLManager::destroyContext()
{
SEAGLManagerDataStorage* dataStorage = static_cast<SEAGLManagerDataStorage*>(DataStorage);
[dataStorage->Context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:nil];
if (FrameBuffer.BufferID != 0)
@ -175,13 +176,13 @@ void CEAGLManager::destroyContext()
glDeleteFramebuffersOES(1, &FrameBuffer.BufferID);
FrameBuffer.BufferID = 0;
}
if (FrameBuffer.ColorBuffer != 0)
{
glDeleteRenderbuffersOES(1, &FrameBuffer.ColorBuffer);
FrameBuffer.ColorBuffer = 0;
}
if (FrameBuffer.DepthBuffer != 0)
{
glDeleteRenderbuffersOES(1, &FrameBuffer.DepthBuffer);
@ -189,10 +190,10 @@ void CEAGLManager::destroyContext()
}
[EAGLContext setCurrentContext:0];
if (dataStorage->Context != nil)
dataStorage->Context = 0;
Data.OpenGLiOS.Context = 0;
}
@ -200,14 +201,14 @@ bool CEAGLManager::activateContext(const SExposedVideoData& videoData, bool rest
{
SEAGLManagerDataStorage* dataStorage = static_cast<SEAGLManagerDataStorage*>(DataStorage);
EAGLContext* context = dataStorage->Context;
bool status = false;
if (context != nil)
{
status = ([EAGLContext currentContext] == context || [EAGLContext setCurrentContext:context]);
}
if (status)
{
if (FrameBuffer.ColorBuffer == 0)
@ -216,7 +217,7 @@ bool CEAGLManager::activateContext(const SExposedVideoData& videoData, bool rest
glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:dataStorage->Layer];
}
if (FrameBuffer.DepthBuffer == 0)
{
GLenum depth = (Params.ZBufferBits >= 24) ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16_OES;
@ -225,7 +226,7 @@ bool CEAGLManager::activateContext(const SExposedVideoData& videoData, bool rest
glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.DepthBuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depth, Params.WindowSize.Width, Params.WindowSize.Height);
}
if (FrameBuffer.BufferID == 0)
{
glGenFramebuffersOES(1, &FrameBuffer.BufferID);
@ -233,7 +234,7 @@ bool CEAGLManager::activateContext(const SExposedVideoData& videoData, bool rest
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, FrameBuffer.DepthBuffer);
}
glBindFramebufferOES(GL_FRAMEBUFFER_OES, FrameBuffer.BufferID);
}
else
@ -253,17 +254,17 @@ bool CEAGLManager::swapBuffers()
{
SEAGLManagerDataStorage* dataStorage = static_cast<SEAGLManagerDataStorage*>(DataStorage);
EAGLContext* context = dataStorage->Context;
bool status = false;
if (context != nil && context == [EAGLContext currentContext])
{
glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
status = true;
}
return status;
}

View File

@ -28,17 +28,17 @@ namespace irr
{
class CIrrDeviceiOS;
}
/* IrrUIViewController */
@interface IrrUIViewController : UIViewController
@end
@implementation IrrUIViewController
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
return UIRectEdgeAll;
}
@end
/* IrrUIViewController */
@interface IrrUIViewController : UIViewController
@end
@implementation IrrUIViewController
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
return UIRectEdgeAll;
}
@end
/* CIrrDelegateiOS */
@ -181,23 +181,22 @@ namespace irr
@interface CIrrViewiOS : UIView
- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device;
@property (nonatomic) float Scale;
@end
@implementation CIrrViewiOS
{
irr::CIrrDeviceiOS* Device;
float Scale;
}
- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device;
{
self = [super initWithFrame:frame];
self.Scale = 1.0f;
if (self)
{
Device = device;
Scale = 1.f;
}
return self;
@ -221,8 +220,8 @@ namespace irr
CGPoint touchPoint = [touch locationInView:self];
ev.TouchInput.X = touchPoint.x*Scale;
ev.TouchInput.Y = touchPoint.y*Scale;
ev.TouchInput.X = touchPoint.x * self.Scale;
ev.TouchInput.Y = touchPoint.y * self.Scale;
Device->postEventFromUser(ev);
}
@ -241,8 +240,8 @@ namespace irr
CGPoint touchPoint = [touch locationInView:self];
ev.TouchInput.X = touchPoint.x*Scale;
ev.TouchInput.Y = touchPoint.y*Scale;
ev.TouchInput.X = touchPoint.x * self.Scale;
ev.TouchInput.Y = touchPoint.y * self.Scale;
Device->postEventFromUser(ev);
}
@ -261,8 +260,8 @@ namespace irr
CGPoint touchPoint = [touch locationInView:self];
ev.TouchInput.X = touchPoint.x*Scale;
ev.TouchInput.Y = touchPoint.y*Scale;
ev.TouchInput.X = touchPoint.x * self.Scale;
ev.TouchInput.Y = touchPoint.y * self.Scale;
Device->postEventFromUser(ev);
}
@ -281,8 +280,8 @@ namespace irr
CGPoint touchPoint = [touch locationInView:self];
ev.TouchInput.X = touchPoint.x*Scale;
ev.TouchInput.Y = touchPoint.y*Scale;
ev.TouchInput.X = touchPoint.x * self.Scale;
ev.TouchInput.Y = touchPoint.y * self.Scale;
Device->postEventFromUser(ev);
}
@ -769,7 +768,13 @@ namespace irr
#ifdef _IRR_COMPILE_WITH_OGLES1_
{
CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this];
CreationParams.WindowSize = core::dimension2d<u32>(view.frame.size.width, view.frame.size.height);
view.contentScaleFactor = dataStorage->Window.screen.nativeScale;
view.Scale = view.contentScaleFactor;
CreationParams.WindowSize =
{
view.frame.size.width * view.contentScaleFactor,
view.frame.size.height * view.contentScaleFactor
};
dataStorage->View = view;
data.OpenGLiOS.View = (__bridge void*)view;
@ -791,7 +796,13 @@ namespace irr
#ifdef _IRR_COMPILE_WITH_OGLES2_
{
CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this];
CreationParams.WindowSize = core::dimension2d<u32>(view.frame.size.width, view.frame.size.height);
view.contentScaleFactor = dataStorage->Window.screen.nativeScale;
view.Scale = view.contentScaleFactor;
CreationParams.WindowSize =
{
view.frame.size.width * view.contentScaleFactor,
view.frame.size.height * view.contentScaleFactor
};
dataStorage->View = view;
data.OpenGLiOS.View = (__bridge void*)view;