//
// cocos2d::CCRenderTexture::initWithWidthAndHeight from 0x1005f53f0 to 0x1005f575d (877 bytes)
//
// 4 xrefs:
// > cocos2d::CCRenderTexture::create_1 @ 0x1005f52c9
// > cocos2d::CCRenderTexture::initWithWidthAndHeight_1 @ 0x1005f5318
// > cocos2d::CCRenderTexture::create @ 0x1005f539f
// > cocos2d::CCRenderTexture::create_2 @ 0x1005f5804
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
bool __fastcall cocos2d::CCRenderTexture::initWithWidthAndHeight(
cocos2d::CCRenderTexture *a1,
int a2,
int a3,
cocos2d::CCTexture2DPixelFormat a4,
unsigned int a5)
{
cocos2d::CCDirector *v6; // rax
int v7; // r12d
cocos2d::CCDirector *v8; // rax
int v9; // r13d
cocos2d::CCConfiguration *v10; // rax
bool v11; // al
__int64 v12; // r14
__int64 v13; // rcx
size_t v14; // r14
void *v15; // rax
void *v16; // r15
cocos2d::CCTexture2D *v17; // r14
float v18; // xmm0_4
GLenum m_ePixelFormat; // r12d
cocos2d::CCConfiguration *v20; // rax
bool v21; // r14
GLenum v22; // r12d
cocos2d::CCTexture2D *v23; // r14
GLenum v24; // r12d
GLuint v25; // eax
cocos2d::CCSprite *v26; // rax
cocos2d::CCSize v28[3]; // [rsp+0h] [rbp-60h] BYREF
GLint params; // [rsp+18h] [rbp-48h] BYREF
float v30; // [rsp+1Ch] [rbp-44h]
GLsizei height[2]; // [rsp+20h] [rbp-40h]
GLenum internalformat; // [rsp+28h] [rbp-38h]
float v33; // [rsp+2Ch] [rbp-34h]
GLsizei width[12]; // [rsp+30h] [rbp-30h]
internalformat = a5;
v33 = *(float *)&a4;
v6 = cocos2d::CCDirector::sharedDirector();
v7 = (int)(float)(sub_1004849C0((__int64)v6) * (float)a2);
v8 = cocos2d::CCDirector::sharedDirector();
v9 = (int)(float)(sub_1004849C0((__int64)v8) * (float)a3);
glGetIntegerv(0x8CA6u, &a1->m_nOldFBO);
v10 = cocos2d::CCConfiguration::sharedConfiguration();
v11 = cocos2d::CCConfiguration::supportsNPOT(v10);
v12 = (unsigned int)v7;
v13 = (unsigned int)v9;
if ( !v11 )
{
v12 = sub_1005772B0(v7);
v13 = sub_1005772B0(v9);
}
*(_QWORD *)width = v12;
*(_QWORD *)height = v13;
v14 = 4 * (int)v13 * (int)v12;
v15 = malloc(v14);
v16 = v15;
if ( v15 )
{
__bzero(v15, v14);
*(float *)&a1->m_ePixelFormat = v33;
a1->m_nWidth = v7;
a1->m_nHeight = v9;
v17 = (cocos2d::CCTexture2D *)operator new(0x68u);
sub_100477FC0((__int64)v17);
a1->m_pTexture = v17;
v18 = (float)v7;
m_ePixelFormat = a1->m_ePixelFormat;
v33 = v18;
v30 = (float)v9;
sub_10028CBF0((float *)v28, v18, (float)v9);
cocos2d::CCTexture2D::initWithData(
v17,
v16,
(cocos2d::CCTexture2DPixelFormat)m_ePixelFormat,
width[0],
height[0],
v28);
glGetIntegerv(0x8CA7u, ¶ms);
v20 = cocos2d::CCConfiguration::sharedConfiguration();
LOBYTE(v28[0].width) = 14;
strcpy((char *)v28 + 1, "GL_QCOM");
v21 = cocos2d::CCConfiguration::checkForGLExtension((__int64)v20, (__int64)v28);
v22 = internalformat;
if ( (LOBYTE(v28[0].width) & 1) != 0 )
operator delete(*(void **)&v28[2]);
if ( v21 )
{
v23 = (cocos2d::CCTexture2D *)operator new(0x68u);
sub_100477FC0((__int64)v23);
a1->m_pTextureCopy = v23;
v24 = a1->m_ePixelFormat;
sub_10028CBF0((float *)v28, v33, v30);
cocos2d::CCTexture2D::initWithData(v23, v16, (cocos2d::CCTexture2DPixelFormat)v24, width[0], height[0], v28);
v22 = internalformat;
}
glGenFramebuffers(1, &a1->m_uFBO);
glBindFramebuffer(0x8D40u, a1->m_uFBO);
v25 = ((__int64 (__fastcall *)(cocos2d::CCTexture2D *))a1->m_pTexture->getName)(a1->m_pTexture);
glFramebufferTexture2D(0x8D40u, 0x8CE0u, 0xDE1u, v25, 0);
if ( v22 )
{
glGenRenderbuffers(1, &a1->m_uDepthRenderBufffer);
glBindRenderbuffer(0x8D41u, a1->m_uDepthRenderBufffer);
glRenderbufferStorage(0x8D41u, v22, width[0], height[0]);
glFramebufferRenderbuffer(0x8D40u, 0x8D00u, 0x8D41u, a1->m_uDepthRenderBufffer);
if ( v22 == 35056 )
glFramebufferRenderbuffer(0x8D40u, 0x8D20u, 0x8D41u, a1->m_uDepthRenderBufffer);
}
glCheckFramebufferStatus(0x8D40u);
cocos2d::CCTexture2D::setAliasTexParameters(a1->m_pTexture);
v26 = cocos2d::CCSprite::createWithTexture_1(a1->m_pTexture);
((void (__fastcall *)(cocos2d::CCRenderTexture *, cocos2d::CCSprite *))a1->setSprite)(a1, v26);
cocos2d::CCObject::release(a1->m_pTexture);
((void (__fastcall *)(cocos2d::CCSprite *, float))a1->m_pSprite->setScaleY)(a1->m_pSprite, -1.0);
((void (__fastcall *)(cocos2d::CCSprite *, __int64))a1->m_pSprite->setBlendFunc)(a1->m_pSprite, 0x30300000001LL);
glBindRenderbuffer(0x8D41u, params);
glBindFramebuffer(0x8D40u, a1->m_nOldFBO);
a1->m_bAutoDraw = 0;
((void (__fastcall *)(cocos2d::CCRenderTexture *, cocos2d::CCSprite *))a1->addChild)(a1, a1->m_pSprite);
free(v16);
}
return v16 != nullptr;
}