ios2 attempt 2 #5

Open
kornerr wants to merge 12 commits from ios2 into master
pull from: ios2
4 changed files with 6 additions and 42 deletions
Showing only changes of commit 56d4b2dd88 - Show all commits

No files matched your search

+2 -29
View File
@@ -12,7 +12,6 @@
#include "../raybri.h"
#include <math.h>
#include <stdio.h>
#include <libEGL/libEGL.h>
@@ -41,25 +40,6 @@ static void sr_log(const char *text)
fflush(stderr);
}
static void sr_hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
{
float i = floorf(h * 6.0f);
float f = h * 6.0f - i;
float p = v * (1.0f - s);
float q = v * (1.0f - f * s);
float t = v * (1.0f - (1.0f - f) * s);
switch (((int)i) % 6)
{
case 0: *r = v; *g = t; *b = p; break;
case 1: *r = q; *g = v; *b = p; break;
case 2: *r = p; *g = v; *b = t; break;
case 3: *r = p; *g = q; *b = v; break;
case 4: *r = t; *g = p; *b = v; break;
default: *r = v; *g = p; *b = q; break;
}
}
// (Re)create the EGL window surface on the layer handed to us by UIKit.
static int sr_create_surface(void)
{
@@ -181,20 +161,13 @@ void raybri_resize(int width, int height)
sr_log("surface recreated");
}
void raybri_render(double time)
void raybri_render(void)
{
if (!sr_ready) return;
if (eglMakeCurrent(sr_display, sr_surface, sr_surface, sr_context) == EGL_FALSE) return;
// Background colour cycles through the hue wheel over time.
float hue = fmodf((float)time * 0.15f, 1.0f);
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
sr_hsv_to_rgb(hue, 0.65f, 0.85f, &r, &g, &b);
rlClearColor((unsigned char)(r * 255.0f), (unsigned char)(g * 255.0f), (unsigned char)(b * 255.0f), 255);
rlClearColor(0, 0, 255, 255);
rlClearScreenBuffers();
eglSwapBuffers(sr_display, sr_surface);
+3 -7
View File
@@ -26,6 +26,9 @@ typedef struct raybri_config {
// on iOS it recreates the EGL window surface when it changes.
void raybri_resize(int width, int height);
// Render one frame.
void raybri_render(void);
// Release the GL/EGL resources owned by the bridge.
void raybri_shutdown(void);
@@ -35,10 +38,6 @@ void raybri_shutdown(void);
// Returns 1 on success, 0 on failure.
int raybri_init(void *layer, int width, int height);
// Render one frame: clear the drawable to a time-based background colour and
// present it. `time` is monotonically increasing seconds.
void raybri_render(double time);
#else
// Initialise the OpenGL-backed raylib scene (no raylib window is created).
@@ -57,9 +56,6 @@ void raybri_load_model(const char *gltf_path);
// Cube rotation, driven by the application (Euler angles, degrees).
void raybri_set_rotation(float x_deg, float y_deg, float z_deg);
// Render one frame.
void raybri_render(void);
#endif
#ifdef __cplusplus
+1 -3
View File
@@ -1,12 +1,10 @@
import QuartzCore
import UIKit
// Render a single frame. The timer calls this directly: an EGL/ANGLE surface
// presents into the view's layer, so there is no draw(_:) / needsDisplay pass
// like in the NSOpenGLView on macOS.
func renderDraw(_ vm: RenderVM) {
let t = CACurrentMediaTime() - vm.startTime
raybri_render(t)
raybri_render()
}
// Backing-pixel size of the view, which is what EGL/ANGLE renders into.
-3
View File
@@ -1,5 +1,4 @@
import Foundation
import QuartzCore
import UIKit
// Bring up EGL/ANGLE on the view's layer. Returns false when the surface could
@@ -17,8 +16,6 @@ func renderInit(_ vm: RenderVM) -> Bool {
// Same shape as the macOS timer: a repeating timer on the main run loop, but
// here it calls the renderer directly instead of flagging the view for redraw.
func renderStartTimer(_ vm: RenderVM) {
vm.startTime = CACurrentMediaTime()
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
guard let vm else { return }
renderDraw(vm)