ios: actually show the rendered game onscreen

no textures and always uses 100% CPU though, so not all that great
This commit is contained in:
UnknownShadow200 2021-09-17 19:39:47 +10:00
parent 74799d9ea4
commit aa809491cc
3 changed files with 36 additions and 12 deletions

View File

@ -9,7 +9,7 @@ ClassiCube strings (`cc_string`) are a struct with the following fields:
Note: This means **STRINGS MAY NOT BE NULL TERMINATED** (and are not in most cases)
You should also read the **Strings** section in the [style guide](doc/style.md)
You should also read the **Strings** section in the [style guide](/doc/style.md)
## Memory management
Some general guidelines to keep in mind when it comes to `cc_string` strings:
@ -57,7 +57,7 @@ The `buffer` field **should not** be treated as a C string, because `cc_string`
The general way to achieve this is to
1. Initialise `capacity` with 1 less than actual buffer size (e.g. use `String_InitArray_NT` instead of `String_InitArray`)
2. Perform various operations on the `cc_string` string
3. Add null terminator to end (i.e. `buffer[length] = '\0';
3. Add null terminator to end (i.e. `buffer[length]` = '\0';
4. Use `buffer` as a C string now
For example:

View File

@ -277,7 +277,7 @@ void Thread_Sleep(cc_uint32 milliseconds) { usleep(milliseconds * 1000); }
#ifdef CC_BUILD_ANDROID
/* All threads using JNI must detach BEFORE they exit */
/* (see https://developer.android.com/training/articles/perf-jni */
/* (see https://developer.android.com/training/articles/perf-jni#threads */
static void* ExecThread(void* param) {
JNIEnv* env;
JavaGetCurrentEnv(env);

View File

@ -25,18 +25,13 @@ static UIWindow* winHandle;
static void DoDrawFramebuffer(CGRect dirty);
@implementation CCWindow
- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); }
//- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); }
- (BOOL)isOpaque { return YES; }
@end
@implementation CCViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
@end
@implementation CCAppDelegate
@ -123,7 +118,7 @@ void Window_Init(void) {
DisplayInfo.ScaleY = 1; // TODO dpi scale
}
static void DoCreateWindow(void) {
static CGRect DoCreateWindow(void) {
CGRect bounds = UIScreen.mainScreen.bounds;
controller = [CCViewController alloc];
winHandle = [[CCWindow alloc] initWithFrame:bounds];
@ -133,9 +128,9 @@ static void DoCreateWindow(void) {
WindowInfo.Exists = true;
WindowInfo.Width = bounds.size.width;
WindowInfo.Height = bounds.size.height;
return bounds;
}
void Window_Create2D(int width, int height) { DoCreateWindow(); }
void Window_Create3D(int width, int height) { DoCreateWindow(); }
void Window_SetSize(int width, int height) { }
void Window_Close(void) { }
@ -228,6 +223,32 @@ void Window_LockLandscapeOrientation(cc_bool lock) {
// TODO implement
}
@interface CCGLView : UIView
@end
@implementation CCGLView
+ (Class)layerClass {
return [CAEAGLLayer class];
}
@end
static CCGLView* view_handle;
void Window_Create3D(int width, int height) {
CGRect bounds = DoCreateWindow();
view_handle = [[CCGLView alloc] initWithFrame:bounds];
controller.view = view_handle;
CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer;
layer.opaque = YES;
layer.drawableProperties =
@{
kEAGLDrawablePropertyRetainedBacking : [NSNumber numberWithBool:NO],
kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8
};
}
/*########################################################################################################################*
*--------------------------------------------------------GLContext--------------------------------------------------------*
*#########################################################################################################################*/
@ -236,12 +257,13 @@ static GLuint framebuffer;
static GLuint color_renderbuffer, depth_renderbuffer;
static void CreateFramebuffer(void) {
CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glGenRenderbuffers(1, &color_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, WindowInfo.Width, WindowInfo.Height);
[ctx_handle renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_renderbuffer);
glGenRenderbuffers(1, &depth_renderbuffer);
@ -273,7 +295,9 @@ void* GLContext_GetAddress(const char* function) { return NULL; }
cc_bool GLContext_SwapBuffers(void) {
static GLenum discards[] = { GL_DEPTH_ATTACHMENT };
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards);
glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer);
[ctx_handle presentRenderbuffer:GL_RENDERBUFFER];
return true;
}