//
// cocos2d::CCRenderTexture::initWithWidthAndHeight from 0x18005fe40 to 0x1800602a8 (1128 bytes)
//
// 6 xrefs:
// > cocos2d::CCRenderTexture::create @ 0x18005fa1e
// > cocos2d::CCRenderTexture::create @ 0x18005fab6
// > cocos2d::CCRenderTexture::create @ 0x18005fb4d
// > cocos2d::CCRenderTexture::initWithWidthAndHeight @ 0x18005fe2c
// > ??> @ 0x1801438a8
// > ??> @ 0x1801b345c
//
// 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
//
// Hidden C++ exception states: #wind=3
__int64 __fastcall cocos2d::CCRenderTexture::initWithWidthAndHeight(
cocos2d::CCRenderTexture *this,
int a2,
int a3,
GLenum a4,
unsigned int a5)
{
cocos2d::CCDirector *v9; // rax
int v10; // ebx
cocos2d::CCDirector *v11; // rax
int v12; // r15d
cocos2d::CCConfiguration *v13; // rax
unsigned int v14; // ebp
unsigned int v15; // r14d
void *v16; // rax
void *v17; // rdi
cocos2d::CCTexture2D *v18; // rax
float v19; // xmm7_4
struct cocos2d::CCConfiguration *v20; // rax
char v21; // bl
void *v22; // rcx
cocos2d::CCTexture2D *v23; // rax
unsigned int v24; // eax
cocos2d::CCRenderTexture_vtbl *v25; // rbx
struct cocos2d::CCSprite *v26; // rax
const struct cocos2d::CCSize *v28; // [rsp+20h] [rbp-A8h]
const struct cocos2d::CCSize *v29; // [rsp+20h] [rbp-A8h]
unsigned __int8 v30; // [rsp+30h] [rbp-98h]
__int64 v31; // [rsp+38h] [rbp-90h] BYREF
GLint params; // [rsp+40h] [rbp-88h] BYREF
void *Block[2]; // [rsp+48h] [rbp-80h] BYREF
__int64 v34; // [rsp+58h] [rbp-70h]
unsigned __int64 v35; // [rsp+60h] [rbp-68h]
v30 = 0;
v9 = cocos2d::CCDirector::sharedDirector();
v10 = (int)(float)(cocos2d::CCDirector::getContentScaleFactor(v9) * (float)a2);
v11 = cocos2d::CCDirector::sharedDirector();
v12 = (int)(float)(cocos2d::CCDirector::getContentScaleFactor(v11) * (float)a3);
glGetIntegerv(0x8CA6u, &this->m_nOldFBO);
v13 = cocos2d::CCConfiguration::sharedConfiguration();
if ( cocos2d::CCConfiguration::supportsNPOT(v13) )
{
v14 = v10;
v15 = v12;
}
else
{
v14 = sub_180095970((unsigned int)v10);
v15 = sub_180095970((unsigned int)v12);
}
v16 = malloc((int)(4 * v14 * v15));
v17 = v16;
if ( v16 )
{
memset(v16, 0, (int)(4 * v14 * v15));
this->m_ePixelFormat = a4;
this->m_nWidth = v10;
this->m_nHeight = v12;
v18 = (cocos2d::CCTexture2D *)operator new(0x68u);
v31 = (__int64)v18;
if ( v18 )
v18 = (cocos2d::CCTexture2D *)cocos2d::CCTexture2D::CCTexture2D(v18);
this->m_pTexture = v18;
if ( !v18 )
goto LABEL_22;
v19 = (float)v10;
kmVec2Fill((float *)&v31, (float)v10, (float)v12);
LODWORD(v28) = v15;
cocos2d::CCTexture2D::initWithData(
this->m_pTexture,
(enum cocos2d::CCTexture2DPixelFormat)v17,
this->m_ePixelFormat,
v14,
v28);
glGetIntegerv(0x8CA7u, ¶ms);
Block[1] = nullptr;
v34 = 7;
v35 = 15;
Block[0] = (void *)0x4D4F43515F4C47LL;
v20 = cocos2d::CCConfiguration::sharedConfiguration();
v21 = cocos2d::CCConfiguration::checkForGLExtension(v20, Block);
if ( v35 > 0xF )
{
v22 = Block[0];
if ( v35 + 1 >= 0x1000 )
{
v22 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v22 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v22);
}
if ( v21 )
{
v23 = (cocos2d::CCTexture2D *)operator new(0x68u);
v31 = (__int64)v23;
if ( v23 )
v23 = (cocos2d::CCTexture2D *)cocos2d::CCTexture2D::CCTexture2D(v23);
this->m_pTextureCopy = v23;
if ( !v23 )
goto LABEL_22;
kmVec2Fill((float *)&v31, v19, (float)v12);
LODWORD(v29) = v15;
cocos2d::CCTexture2D::initWithData(
this->m_pTextureCopy,
(enum cocos2d::CCTexture2DPixelFormat)v17,
this->m_ePixelFormat,
v14,
v29);
}
_glewGenFramebuffers(1);
_glewBindFramebuffer(36160, this->m_uFBO);
v24 = ((__int64 (__fastcall *)(cocos2d::CCTexture2D *))this->m_pTexture->getName)(this->m_pTexture);
_glewFramebufferTexture2D(36160, 36064, 3553, v24, 0);
if ( a5 )
{
_glewGenRenderbuffers(1, &this->m_uDepthRenderBufffer);
_glewBindRenderbuffer(36161, this->m_uDepthRenderBufffer);
_glewRenderbufferStorage(36161, a5, v14, v15);
_glewFramebufferRenderbuffer(36160, 36096, 36161, this->m_uDepthRenderBufffer);
if ( a5 == 35056 )
_glewFramebufferRenderbuffer(36160, 36128, 36161, this->m_uDepthRenderBufffer);
}
_glewCheckFramebufferStatus(36160);
cocos2d::CCTexture2D::setAliasTexParameters(this->m_pTexture);
v25 = this->__vftable;
v26 = cocos2d::CCSprite::createWithTexture(this->m_pTexture);
((void (__fastcall *)(cocos2d::CCRenderTexture *, struct cocos2d::CCSprite *))v25->setSprite)(this, v26);
cocos2d::CCObject::release(this->m_pTexture);
((void (__fastcall *)(cocos2d::CCSprite *))this->m_pSprite->setScaleY)(this->m_pSprite);
v31 = 0x30300000001LL;
((void (__fastcall *)(cocos2d::CCTextureProtocol *, __int64))this->m_pSprite->setBlendFunc)(
&this->m_pSprite->cocos2d::CCTextureProtocol,
0x30300000001LL);
_glewBindRenderbuffer(36161, (unsigned int)params);
_glewBindFramebuffer(36160, (unsigned int)this->m_nOldFBO);
this->m_bAutoDraw = 0;
((void (__fastcall *)(cocos2d::CCRenderTexture *, cocos2d::CCSprite *))this->addChild_1)(this, this->m_pSprite);
v30 = 1;
LABEL_22:
free(v17);
}
return v30;
}