mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 04:34:58 -04:00
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:
parent
74799d9ea4
commit
aa809491cc
@ -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)
|
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
|
## Memory management
|
||||||
Some general guidelines to keep in mind when it comes to `cc_string` strings:
|
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
|
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`)
|
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
|
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
|
4. Use `buffer` as a C string now
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
@ -277,7 +277,7 @@ void Thread_Sleep(cc_uint32 milliseconds) { usleep(milliseconds * 1000); }
|
|||||||
|
|
||||||
#ifdef CC_BUILD_ANDROID
|
#ifdef CC_BUILD_ANDROID
|
||||||
/* All threads using JNI must detach BEFORE they exit */
|
/* 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) {
|
static void* ExecThread(void* param) {
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
JavaGetCurrentEnv(env);
|
JavaGetCurrentEnv(env);
|
||||||
|
@ -25,18 +25,13 @@ static UIWindow* winHandle;
|
|||||||
static void DoDrawFramebuffer(CGRect dirty);
|
static void DoDrawFramebuffer(CGRect dirty);
|
||||||
@implementation CCWindow
|
@implementation CCWindow
|
||||||
|
|
||||||
- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); }
|
//- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); }
|
||||||
|
|
||||||
- (BOOL)isOpaque { return YES; }
|
- (BOOL)isOpaque { return YES; }
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CCViewController
|
@implementation CCViewController
|
||||||
|
|
||||||
- (void)viewDidLoad {
|
|
||||||
[super viewDidLoad];
|
|
||||||
// Do any additional setup after loading the view, typically from a nib.
|
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CCAppDelegate
|
@implementation CCAppDelegate
|
||||||
@ -123,7 +118,7 @@ void Window_Init(void) {
|
|||||||
DisplayInfo.ScaleY = 1; // TODO dpi scale
|
DisplayInfo.ScaleY = 1; // TODO dpi scale
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoCreateWindow(void) {
|
static CGRect DoCreateWindow(void) {
|
||||||
CGRect bounds = UIScreen.mainScreen.bounds;
|
CGRect bounds = UIScreen.mainScreen.bounds;
|
||||||
controller = [CCViewController alloc];
|
controller = [CCViewController alloc];
|
||||||
winHandle = [[CCWindow alloc] initWithFrame:bounds];
|
winHandle = [[CCWindow alloc] initWithFrame:bounds];
|
||||||
@ -133,9 +128,9 @@ static void DoCreateWindow(void) {
|
|||||||
WindowInfo.Exists = true;
|
WindowInfo.Exists = true;
|
||||||
WindowInfo.Width = bounds.size.width;
|
WindowInfo.Width = bounds.size.width;
|
||||||
WindowInfo.Height = bounds.size.height;
|
WindowInfo.Height = bounds.size.height;
|
||||||
|
return bounds;
|
||||||
}
|
}
|
||||||
void Window_Create2D(int width, int height) { DoCreateWindow(); }
|
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_SetSize(int width, int height) { }
|
||||||
|
|
||||||
void Window_Close(void) { }
|
void Window_Close(void) { }
|
||||||
@ -228,6 +223,32 @@ void Window_LockLandscapeOrientation(cc_bool lock) {
|
|||||||
// TODO implement
|
// 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--------------------------------------------------------*
|
*--------------------------------------------------------GLContext--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
@ -236,12 +257,13 @@ static GLuint framebuffer;
|
|||||||
static GLuint color_renderbuffer, depth_renderbuffer;
|
static GLuint color_renderbuffer, depth_renderbuffer;
|
||||||
|
|
||||||
static void CreateFramebuffer(void) {
|
static void CreateFramebuffer(void) {
|
||||||
|
CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer;
|
||||||
glGenFramebuffers(1, &framebuffer);
|
glGenFramebuffers(1, &framebuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||||
|
|
||||||
glGenRenderbuffers(1, &color_renderbuffer);
|
glGenRenderbuffers(1, &color_renderbuffer);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 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);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_renderbuffer);
|
||||||
|
|
||||||
glGenRenderbuffers(1, &depth_renderbuffer);
|
glGenRenderbuffers(1, &depth_renderbuffer);
|
||||||
@ -273,7 +295,9 @@ void* GLContext_GetAddress(const char* function) { return NULL; }
|
|||||||
|
|
||||||
cc_bool GLContext_SwapBuffers(void) {
|
cc_bool GLContext_SwapBuffers(void) {
|
||||||
static GLenum discards[] = { GL_DEPTH_ATTACHMENT };
|
static GLenum discards[] = { GL_DEPTH_ATTACHMENT };
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||||
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards);
|
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer);
|
||||||
[ctx_handle presentRenderbuffer:GL_RENDERBUFFER];
|
[ctx_handle presentRenderbuffer:GL_RENDERBUFFER];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user