github.com/Seikaijyu/gio@v0.0.1/app/gl_ios.m (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // +build darwin,ios,nometal
     4  
     5  @import UIKit;
     6  @import OpenGLES;
     7  
     8  #include "_cgo_export.h"
     9  
    10  Class gio_layerClass(void) {
    11  	return [CAEAGLLayer class];
    12  }
    13  
    14  int gio_renderbufferStorage(CFTypeRef ctxRef, CFTypeRef layerRef, GLenum buffer) {
    15  	EAGLContext *ctx = (__bridge EAGLContext *)ctxRef;
    16  	CAEAGLLayer *layer = (__bridge CAEAGLLayer *)layerRef;
    17  	return (int)[ctx renderbufferStorage:buffer fromDrawable:layer];
    18  }
    19  
    20  int gio_presentRenderbuffer(CFTypeRef ctxRef, GLenum buffer) {
    21  	EAGLContext *ctx = (__bridge EAGLContext *)ctxRef;
    22  	return (int)[ctx presentRenderbuffer:buffer];
    23  }
    24  
    25  int gio_makeCurrent(CFTypeRef ctxRef) {
    26  	EAGLContext *ctx = (__bridge EAGLContext *)ctxRef;
    27  	return (int)[EAGLContext setCurrentContext:ctx];
    28  }
    29  
    30  CFTypeRef gio_createContext(void) {
    31  	EAGLContext *ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
    32  	if (ctx == nil) {
    33  		return nil;
    34  	}
    35  	return CFBridgingRetain(ctx);
    36  }
    37  
    38  CFTypeRef gio_createGLLayer(void) {
    39  	CAEAGLLayer *layer = [[CAEAGLLayer layer] init];
    40  	if (layer == nil) {
    41  		return nil;
    42  	}
    43  	layer.drawableProperties = @{kEAGLDrawablePropertyColorFormat: kEAGLColorFormatSRGBA8};
    44  	layer.opaque = YES;
    45  	layer.anchorPoint = CGPointMake(0, 0);
    46  	return CFBridgingRetain(layer);
    47  }