diff --git a/examples/common/entry/entry_ios.mm b/examples/common/entry/entry_ios.mm index 62d52b0ae..9a318e9f6 100644 --- a/examples/common/entry/entry_ios.mm +++ b/examples/common/entry/entry_ios.mm @@ -28,13 +28,13 @@ namespace entry struct Context { - Context() + Context(uint32_t _width, uint32_t _height) { const char* argv[1] = { "ios" }; m_mte.m_argc = 1; m_mte.m_argv = const_cast(argv); - m_eventQueue.postSizeEvent(768, 1024); + m_eventQueue.postSizeEvent(_width, _height); // Prevent render thread creation. bgfx::renderFrame(); @@ -57,6 +57,13 @@ namespace entry int32_t MainThreadEntry::threadFunc(void* _userData) { + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); + char path[PATH_MAX]; + if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) + chdir(path); + CFRelease(resourcesURL); + MainThreadEntry* self = (MainThreadEntry*)_userData; int32_t result = main(self->m_argc, self->m_argv); return result; @@ -145,6 +152,36 @@ using namespace entry; bgfx::renderFrame(); } +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch *touch = [[event allTouches] anyObject]; + CGPoint touchLocation = [touch locationInView:self]; + + s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y); + s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, MouseButton::Left, true); +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch *touch = [[event allTouches] anyObject]; + CGPoint touchLocation = [touch locationInView:self]; + s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, MouseButton::Left, false); +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch *touch = [[event allTouches] anyObject]; + CGPoint touchLocation = [touch locationInView:self]; + s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y); +} + +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch *touch = [[event allTouches] anyObject]; + CGPoint touchLocation = [touch locationInView:self]; + s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, MouseButton::Left, false); +} + @end @interface AppDelegate : UIResponder @@ -173,8 +210,12 @@ using namespace entry; [m_window addSubview: m_view]; [m_window makeKeyAndVisible]; + + //float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but ui is too small on ipad retina + float scaleFactor = 1.0f; + [m_view setContentScaleFactor: scaleFactor ]; - s_ctx = new Context; + s_ctx = new Context((uint32_t)(scaleFactor*rect.size.width), (uint32_t)(scaleFactor*rect.size.height)); return YES; } diff --git a/src/glcontext_eagl.h b/src/glcontext_eagl.h index 26eedf308..17b60145f 100644 --- a/src/glcontext_eagl.h +++ b/src/glcontext_eagl.h @@ -33,7 +33,7 @@ namespace bgfx GLuint m_fbo; GLuint m_colorRbo; - GLuint m_depthRbo; + GLuint m_depthStencilRbo; }; } // namespace bgfx diff --git a/src/glcontext_eagl.mm b/src/glcontext_eagl.mm index e21ea5b23..3d6feddeb 100644 --- a/src/glcontext_eagl.mm +++ b/src/glcontext_eagl.mm @@ -49,11 +49,12 @@ namespace bgfx GL_CHECK(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height) ); BX_TRACE("Screen size: %d x %d", width, height); - GL_CHECK(glGenRenderbuffers(1, &m_depthRbo) ); - GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthRbo) ); - GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height) ); - GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRbo) ); - + GL_CHECK(glGenRenderbuffers(1, &m_depthStencilRbo) ); + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilRbo) ); + GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height) ); // from OES_packed_depth_stencil + GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); + GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); + BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) , "glCheckFramebufferStatus failed 0x%08x" , glCheckFramebufferStatus(GL_FRAMEBUFFER) @@ -74,10 +75,10 @@ namespace bgfx m_colorRbo = 0; } - if (0 != m_depthRbo) + if (0 != m_depthStencilRbo) { - GL_CHECK(glDeleteRenderbuffers(1, &m_depthRbo) ); - m_depthRbo = 0; + GL_CHECK(glDeleteRenderbuffers(1, &m_depthStencilRbo) ); + m_depthStencilRbo = 0; } EAGLContext* context = (EAGLContext*)m_context; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index e3337ea19..4efaf5091 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1359,7 +1359,8 @@ namespace bgfx s_textureFormat[TextureFormat::BGRA8].m_fmt = GL_BGRA; - // Mixing GLES and GL extensions here. OpenGL EXT_bgra wants + // Mixing GLES and GL extensions here. OpenGL EXT_bgra and + // APPLE_texture_format_BGRA8888 wants // format to be BGRA but internal format to stay RGBA, but // EXT_texture_format_BGRA8888 wants both format and internal // format to be BGRA. @@ -1367,7 +1368,8 @@ namespace bgfx // Reference: // https://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_format_BGRA8888.txt // https://www.opengl.org/registry/specs/EXT/bgra.txt - if (!s_extension[Extension::EXT_bgra].m_supported) + // https://www.khronos.org/registry/gles/extensions/APPLE/APPLE_texture_format_BGRA8888.txt + if (!s_extension[Extension::EXT_bgra].m_supported && !s_extension[Extension::APPLE_texture_format_BGRA8888].m_supported) { s_textureFormat[TextureFormat::BGRA8].m_internalFmt = GL_BGRA; }