114114 GL_FLOAT_VEC2 = 0x8b50 , GL_FLOAT_VEC3 , GL_FLOAT_VEC4 , GL_INT_VEC2 , GL_INT_VEC3 , GL_INT_VEC4 , GL_BOOL , GL_FLOAT_MAT2 = 0x8b5a , GL_FLOAT_MAT3 , GL_FLOAT_MAT4 , GL_SAMPLER_2D = 0x8b5e ,
115115 GL_SAMPLER_3D , GL_SAMPLER_CUBE , GL_SAMPLER_2D_SHADOW = 0x8b62 , GL_TEXTURE_2D_ARRAY = 0x8c1a , GL_TEXTURE_BINDING_2D_ARRAY = 0x8c1d ,
116116 GL_READ_FRAMEBUFFER = 0x8ca8 , GL_DRAW_FRAMEBUFFER , GL_READ_FRAMEBUFFER_BINDING , GL_RENDERBUFFER_SAMPLES , GL_FRAMEBUFFER_COMPLETE = 0x8cd5 , GL_MAX_COLOR_ATTACHMENTS = 0x8cdf ,
117+ GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8cd0 , GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME ,
118+ GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL , GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE , GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER ,
119+ GL_FRAMEBUFFER_DEFAULT = 0x8218 , GL_TEXTURE = 0x1702 ,
120+ GL_RENDERBUFFER_DEPTH_SIZE = 0x8d54 , GL_RENDERBUFFER_STENCIL_SIZE ,
117121 GL_RENDERBUFFER_WIDTH = 0x8d42 , GL_RENDERBUFFER_HEIGHT , GL_RENDERBUFFER_INTERNAL_FORMAT , GL_FRAMEBUFFER_SRGB = 0x8db9 , GL_SAMPLER_2D_ARRAY = 0x8dc1 ,
118122 GL_UNSIGNED_INT_VEC2 = 0x8dc6 , GL_UNSIGNED_INT_VEC3 , GL_UNSIGNED_INT_VEC4 , GL_TEXTURE_SWIZZLE_R = 0x8e42 , GL_TEXTURE_SWIZZLE_A = 0x8e45 ,
119123 GL_ALREADY_SIGNALED = 0x911a , GL_TIMEOUT_EXPIRED , GL_CONDITION_SATISFIED , GL_CONTEXT_PROFILE_MASK = 0x9126 ,
@@ -314,7 +318,7 @@ static uint32_t name_new(void ***tab, uint32_t *n, uint32_t *cap, size_t sz) {
314318NAMES (tex_t , g_texs, g_ntexs, g_captexs)
315319static tex_t *tex_of (GLuint n) { return n && n < g_ntexs ? g_texs[n] : NULL ; }
316320
317- typedef struct { int fmt; uint32_t w, h; __strong id <MTLTexture > tex; uint64_t gen; } rb_t ;
321+ typedef struct { int fmt; uint32_t w, h; __strong id <MTLTexture > tex; uint64_t gen; GLenum internal_fmt; } rb_t ;
318322NAMES (rb_t , g_rbs, g_nrbs, g_caprbs)
319323static rb_t *rb_of (GLuint n) { return n && n < g_nrbs ? g_rbs[n] : NULL ; }
320324
@@ -1695,6 +1699,16 @@ static void mip_impl(GLenum target) {
16951699 case GL_RENDERBUFFER_SAMPLES : *v = 0 ; return ;
16961700 case GL_RENDERBUFFER_WIDTH : *v = r ? (GLint)r->w : 0 ; return ;
16971701 case GL_RENDERBUFFER_HEIGHT : *v = r ? (GLint)r->h : 0 ; return ;
1702+ case GL_RENDERBUFFER_INTERNAL_FORMAT : *v = r ? (GLint)r->internal_fmt : 0 ; return ;
1703+ case GL_RENDERBUFFER_DEPTH_SIZE :
1704+ switch (r ? r->internal_fmt : 0 ) {
1705+ case GL_DEPTH_COMPONENT16 : *v = 16 ; return ;
1706+ case GL_DEPTH_COMPONENT24 : case GL_DEPTH24_STENCIL8 : *v = 24 ; return ;
1707+ case GL_DEPTH_COMPONENT32 : case GL_DEPTH_COMPONENT32F : case GL_DEPTH32F_STENCIL8 : *v = 32 ; return ;
1708+ default : *v = 0 ; return ;
1709+ }
1710+ case GL_RENDERBUFFER_STENCIL_SIZE :
1711+ *v = r && (r->internal_fmt == GL_STENCIL_INDEX8 || r->internal_fmt == GL_DEPTH24_STENCIL8 || r->internal_fmt == GL_DEPTH32F_STENCIL8 ) ? 8 : 0 ; return ;
16981712 }
16991713 RED1 (" glGetRenderbufferParameteriv(%#x ) not implemented" , p); *v = 0 ;
17001714}
@@ -1705,7 +1719,7 @@ static void mip_impl(GLenum target) {
17051719 @autoreleasepool {
17061720 MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: g_fmt[f].pf width: w height: h mipmapped: NO ];
17071721 td.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead ; td.storageMode = MTLStorageModePrivate ;
1708- r->tex = [g_dev newTextureWithDescriptor: td]; r->fmt = f; r->w = w; r->h = h; r->gen ++;
1722+ r->tex = [g_dev newTextureWithDescriptor: td]; r->fmt = f; r->w = w; r->h = h; r->gen ++; r-> internal_fmt = ifmt;
17091723 }
17101724 OLOG (" renderbuffer %u : %d x%d %s " , S.rb , w, h, g_fmt[f].name );
17111725}
@@ -1730,6 +1744,47 @@ static void fb_attach(GLenum target, GLenum attachment, int kind, GLuint name, i
17301744GL (glFramebufferTextureLayer, void , GLenum target, GLenum att, GLuint t, GLint level, GLint layer) { fb_attach (target, att, 1 , t, level, layer); }
17311745GL (glFramebufferTexture3D, void , GLenum target, GLenum att, GLenum textarget, GLuint t, GLint level, GLint z) { (void )textarget; fb_attach (target, att, 1 , t, level, z); }
17321746GL (glFramebufferRenderbuffer, void , GLenum target, GLenum att, GLenum rbt, GLuint r) { (void )rbt; fb_attach (target, att, 2 , r, 0 , 0 ); }
1747+ // Report the attachment actually bound; Naruto checks stencil and depth before a battle.
1748+ GL (glGetFramebufferAttachmentParameteriv, void , GLenum target, GLenum attachment, GLenum p, GLint *v) {
1749+ GLenum error = 0x500 ; // GL_INVALID_ENUM
1750+ if (!v || (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER && target != GL_READ_FRAMEBUFFER )) goto fail;
1751+ GLuint name = target == GL_READ_FRAMEBUFFER ? S.read_fb : S.fb ;
1752+ fb_t *f = fb_of (name);
1753+ const att_t *a;
1754+ if (!name) {
1755+ if (attachment != GL_BACK && attachment != GL_DEPTH && attachment != GL_STENCIL ) goto fail;
1756+ if (p == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE ) { *v = GL_FRAMEBUFFER_DEFAULT ; return ; }
1757+ error = 0x502 ; goto fail; // GL_INVALID_OPERATION
1758+ }
1759+ if (!f) { error = 0x502 ; goto fail; }
1760+ if (attachment == GL_COLOR_ATTACHMENT0 ) a = &f->col ;
1761+ else if (attachment == GL_DEPTH_ATTACHMENT ) a = &f->depth ;
1762+ else if (attachment == GL_STENCIL_ATTACHMENT ) a = &f->stencil ;
1763+ else if (attachment == GL_DEPTH_STENCIL_ATTACHMENT ) {
1764+ if (f->depth .kind != f->stencil .kind || f->depth .name != f->stencil .name ||
1765+ f->depth .level != f->stencil .level || f->depth .face != f->stencil .face ) { error = 0x502 ; goto fail; }
1766+ a = &f->depth ;
1767+ } else goto fail;
1768+ if (p == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE ) {
1769+ *v = a->kind == 1 ? GL_TEXTURE : a->kind == 2 ? GL_RENDERBUFFER : 0 ; return ;
1770+ }
1771+ if (p == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME ) { *v = (GLint)a->name ; return ; }
1772+ if (a->kind == 1 ) {
1773+ tex_t *t = tex_of (a->name );
1774+ switch (p) {
1775+ case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL : *v = a->level ; return ;
1776+ case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE :
1777+ *v = t && t->target == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + a->face : 0 ; return ;
1778+ case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER :
1779+ *v = t && (t->target == GL_TEXTURE_2D_ARRAY || t->target == GL_TEXTURE_3D ) ? a->face : 0 ; return ;
1780+ }
1781+ } else error = 0x502 ;
1782+ fail:
1783+ if (!g_gl_error) g_gl_error = error;
1784+ }
1785+ GL (glGetFramebufferAttachmentParameterivEXT, void , GLenum target, GLenum attachment, GLenum p, GLint *v) {
1786+ h_glGetFramebufferAttachmentParameteriv (target, attachment, p, v);
1787+ }
17331788// A framebuffer's colour image: the texture, its level and its slice (a cube face or an array layer) or 3D slice
17341789static id <MTLTexture > fb_color (GLuint fb, int *level, int *slice) {
17351790 *level = *slice = 0 ;
0 commit comments