mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-02-17 20:31:57 -05:00
commit
6bccda7e3d
4 changed files with 58 additions and 14 deletions
|
@ -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<char**>(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<UIApplicationDelegate>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace bgfx
|
|||
|
||||
GLuint m_fbo;
|
||||
GLuint m_colorRbo;
|
||||
GLuint m_depthRbo;
|
||||
GLuint m_depthStencilRbo;
|
||||
};
|
||||
} // namespace bgfx
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue