diff --git a/src/DivaGL/hook.cpp b/src/DivaGL/hook.cpp index a3618d5..c835ec0 100644 --- a/src/DivaGL/hook.cpp +++ b/src/DivaGL/hook.cpp @@ -17,6 +17,8 @@ #include "object.hpp" #include "print.hpp" #include "resource.h" +#include "render_manager.hpp" +#include "render_texture.hpp" #include "shader_ft.hpp" #include "sprite.hpp" #include "stage.hpp" @@ -62,9 +64,10 @@ HOOK(int32_t, FASTCALL, data_init, 0x0000000140192FF0) { effect_patch(); light_param_patch(); object_patch(); - render_manager_patch(); - rob_patch(); pv_game_patch(); + render_manager_patch(); + render_texture_patch(); + rob_patch(); shadow_patch(); sprite_patch(); stage_patch(); diff --git a/src/DivaGL/render_texture.cpp b/src/DivaGL/render_texture.cpp index 8f4e1f1..3552dc8 100644 --- a/src/DivaGL/render_texture.cpp +++ b/src/DivaGL/render_texture.cpp @@ -5,6 +5,7 @@ #include "render_texture.hpp" #include "gl_state.hpp" +#include static uint32_t& render_texture_counter = *(uint32_t*)0x00000001411AD648; @@ -12,6 +13,15 @@ static int32_t render_texture_init_framebuffer(RenderTexture* rt, int32_t max_le static int32_t render_texture_set_framebuffer_texture(RenderTexture* rrt, GLuint color_texture, int32_t level, GLuint depth_texture, bool stencil); +RenderTexture::RenderTexture() : color_texture(), depth_texture(), +binding(), max_level(), fbos()/*, depth_rbo(), stencil_rbo()*/ { + +} + +RenderTexture::~RenderTexture() { + Free(); +} + int32_t RenderTexture::Bind(int32_t index) { if (index < 0 || index > max_level) return -1; @@ -35,15 +45,15 @@ void RenderTexture::Free() { color_texture = 0; } - if (rbo) { - glDeleteRenderbuffers(1, &rbo); - rbo = 0; + /*if (depth_rbo) { + glDeleteRenderbuffers(1, &depth_rbo); + depth_rbo = 0; } - if (field_2C) { - glDeleteRenderbuffers(1, &field_2C); - field_2C = 0; - } + if (stencil_rbo) { + glDeleteRenderbuffers(1, &stencil_rbo); + stencil_rbo = 0; + }*/ if (fbos) { glDeleteFramebuffers(max_level + 1, fbos); @@ -110,6 +120,26 @@ int32_t RenderTexture::Init(int32_t width, int32_t height, return 0; } +/*int32_t RenderTexture::InitDepthRenderbuffer(GLenum internal_format, int32_t width, int32_t height) { + gl_state_bind_framebuffer(fbos[0]); + glGenRenderbuffers(1, &depth_rbo); + glBindRenderbuffer(GL_RENDERBUFFER, depth_rbo); + glRenderbufferStorage(GL_RENDERBUFFER, internal_format, width, height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rbo); + gl_state_bind_framebuffer(0); + return -(glGetError() != GL_ZERO); +} + +int32_t RenderTexture::InitStencilRenderbuffer(GLenum internal_format, int32_t width, int32_t height) { + gl_state_bind_framebuffer(fbos[0]); + glGenRenderbuffers(1, &stencil_rbo); + glBindRenderbuffer(GL_RENDERBUFFER, stencil_rbo); + glRenderbufferStorage(GL_RENDERBUFFER, internal_format, width, height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil_rbo); + gl_state_bind_framebuffer(0); + return -(glGetError() != GL_ZERO); +}*/ + int32_t RenderTexture::SetColorDepthTextures(GLuint color_texture, int32_t max_level, GLuint depth_texture, bool stencil) { int32_t error = 0; @@ -124,6 +154,21 @@ void render_texture_counter_reset() { render_texture_counter = 0; } +HOOK(void, FASTCALL, RenderTexture__RenderTexture, 0x00000001405030C0, RenderTexture* This) { + RenderTexture temp; + *(void***)This = *(void***)&temp; + *This = temp; +} + +HOOK(void, FASTCALL, RenderTexture___RenderTexture, 0x00000001405030F0, RenderTexture* This) { + This->~RenderTexture(); +} + +void render_texture_patch() { + INSTALL_HOOK(RenderTexture__RenderTexture); + INSTALL_HOOK(RenderTexture___RenderTexture); +} + static int32_t render_texture_init_framebuffer(RenderTexture* rt, int32_t max_level) { rt->fbos = force_malloc(max_level + 1LL); glGenFramebuffers(max_level + 1, rt->fbos); @@ -157,10 +202,10 @@ static int32_t render_texture_set_framebuffer_texture(RenderTexture* rt, if (depth_texture) glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depth_texture, 0); - else if (rt->rbo) { - glBindRenderbuffer(GL_RENDERBUFFER, rt->rbo); + else if (rt->depth_rbo) { + glBindRenderbuffer(GL_RENDERBUFFER, rt->depth_rbo); glFramebufferRenderbuffer(GL_FRAMEBUFFER, - GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rt->rbo); + GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rt->depth_rbo); } else glFramebufferTexture(GL_FRAMEBUFFER, @@ -170,10 +215,10 @@ static int32_t render_texture_set_framebuffer_texture(RenderTexture* rt, if (depth_texture) glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_texture, 0); - else if (rt->rbo) { - glBindRenderbuffer(GL_RENDERBUFFER, rt->rbo); + else if (rt->depth_rbo) { + glBindRenderbuffer(GL_RENDERBUFFER, rt->depth_rbo); glFramebufferRenderbuffer(GL_FRAMEBUFFER, - GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->rbo); + GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth_rbo); } else glFramebufferTexture(GL_FRAMEBUFFER, diff --git a/src/DivaGL/render_texture.hpp b/src/DivaGL/render_texture.hpp index ecc3794..ff15297 100644 --- a/src/DivaGL/render_texture.hpp +++ b/src/DivaGL/render_texture.hpp @@ -9,19 +9,23 @@ #include "texture.hpp" struct RenderTexture { - void* __vftable; texture* color_texture; texture* depth_texture; int32_t binding; int32_t max_level; GLuint* fbos; - GLuint rbo; - GLuint field_2C; + GLuint depth_rbo; + GLuint stencil_rbo; + + RenderTexture(); + virtual ~RenderTexture(); int32_t Bind(int32_t index = 0); void Free(); int32_t Init(int32_t width, int32_t height, int32_t max_level, GLenum color_format, GLenum depth_format); + /*int32_t InitDepthRenderbuffer(GLenum internal_format, int32_t width, int32_t height); + int32_t InitStencilRenderbuffer(GLenum internal_format, int32_t width, int32_t height);*/ int32_t SetColorDepthTextures(GLuint color_texture, int32_t max_level = 0, GLuint depth_texture = 0, bool stencil = false); @@ -49,3 +53,5 @@ struct RenderTexture { static_assert(sizeof(RenderTexture) == 0x30, "\"RenderTexture\" struct should have a size of 0x30"); extern void render_texture_counter_reset(); + +extern void render_texture_patch();