AMD fix
This commit is contained in:
+164
-14
@@ -6,6 +6,12 @@
|
||||
#include "render_texture.hpp"
|
||||
#include "gl_state.hpp"
|
||||
|
||||
static uint32_t& render_texture_counter = *(uint32_t*)0x00000001411AD648;
|
||||
|
||||
static int32_t render_texture_init_framebuffer(RenderTexture* rt, int32_t max_level);
|
||||
static int32_t render_texture_set_framebuffer_texture(RenderTexture* rrt,
|
||||
GLuint color_texture, int32_t level, GLuint depth_texture, bool stencil);
|
||||
|
||||
int32_t RenderTexture::Bind(int32_t index) {
|
||||
if (index < 0 || index > max_level)
|
||||
return -1;
|
||||
@@ -19,25 +25,169 @@ int32_t RenderTexture::Bind(int32_t index) {
|
||||
}
|
||||
|
||||
void RenderTexture::Free() {
|
||||
static void (FASTCALL * RenderTexture__Free)(RenderTexture * rt)
|
||||
= (void (FASTCALL*)(RenderTexture * rt))0x00000001405035C0;
|
||||
RenderTexture__Free(this);
|
||||
if (depth_texture) {
|
||||
texture_free(depth_texture);
|
||||
depth_texture = 0;
|
||||
}
|
||||
|
||||
if (color_texture) {
|
||||
texture_free(color_texture);
|
||||
color_texture = 0;
|
||||
}
|
||||
|
||||
if (rbo) {
|
||||
glDeleteRenderbuffers(1, &rbo);
|
||||
rbo = 0;
|
||||
}
|
||||
|
||||
if (field_2C) {
|
||||
glDeleteRenderbuffers(1, &field_2C);
|
||||
field_2C = 0;
|
||||
}
|
||||
|
||||
if (fbos) {
|
||||
glDeleteFramebuffers(max_level + 1, fbos);
|
||||
free(fbos);
|
||||
fbos = 0;
|
||||
}
|
||||
max_level = 0;
|
||||
}
|
||||
|
||||
int32_t RenderTexture::Init(int32_t width, int32_t height,
|
||||
int32_t max_level, GLenum color_format, GLenum depth_format) {
|
||||
static int32_t(FASTCALL * RenderTexture__Init)(RenderTexture * rt, int32_t width, int32_t height,
|
||||
int32_t max_level, GLenum color_format, GLenum depth_format)
|
||||
= (int32_t(FASTCALL*)(RenderTexture * rt, int32_t width, int32_t height,
|
||||
int32_t max_level, GLenum color_format, GLenum depth_format))0x0000000140503420;
|
||||
return RenderTexture__Init(this, width, height, max_level, color_format, depth_format);
|
||||
if (max_level < 0)
|
||||
return -1;
|
||||
|
||||
max_level = min_def(max_level, 15);
|
||||
if (max_level < 0)
|
||||
return 0;
|
||||
Free();
|
||||
|
||||
GLuint color_texture;
|
||||
if (color_format) {
|
||||
this->color_texture = texture_load_tex_2d(texture_id(0x23, render_texture_counter),
|
||||
color_format, width, height, max_level, 0, 0);
|
||||
if (!this->color_texture)
|
||||
return -1;
|
||||
|
||||
render_texture_counter++;
|
||||
color_texture = GetColorTex();
|
||||
gl_state_bind_texture_2d(GetColorTex());
|
||||
if (color_format == GL_RGBA32F) {
|
||||
glTexParameteriDLL(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteriDLL(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
glTexParameteriDLL(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteriDLL(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
gl_state_bind_texture_2d(0);
|
||||
}
|
||||
else {
|
||||
this->color_texture = 0;
|
||||
color_texture = 0;
|
||||
}
|
||||
|
||||
GLuint depth_texture;
|
||||
bool stencil;
|
||||
if (depth_format) {
|
||||
this->depth_texture = texture_load_tex_2d(texture_id(0x23, render_texture_counter),
|
||||
depth_format, width, height, 0, 0, 0);
|
||||
if (!this->depth_texture)
|
||||
return -1;
|
||||
|
||||
render_texture_counter++;
|
||||
depth_texture = this->GetDepthTex();
|
||||
stencil = depth_format == GL_DEPTH24_STENCIL8;
|
||||
}
|
||||
else {
|
||||
this->depth_texture = 0;
|
||||
depth_texture = 0;
|
||||
stencil = false;
|
||||
}
|
||||
this->max_level = max_level;
|
||||
|
||||
if (render_texture_init_framebuffer(this, max_level) >= 0)
|
||||
for (int32_t i = 0; i <= max_level; i++)
|
||||
if (render_texture_set_framebuffer_texture(this, color_texture, i, depth_texture, stencil) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RenderTexture::SetColorDepthTextures(GLuint color_texture,
|
||||
int32_t max_level, GLuint depth_texture) {
|
||||
int32_t(FASTCALL * RenderTexture__SetColorDepthTextures)(RenderTexture * rt,
|
||||
GLuint color_texture, int32_t level, GLuint depth_texture)
|
||||
= (int32_t(FASTCALL*)(RenderTexture * rt,
|
||||
GLuint color_texture, int32_t level, GLuint depth_texture))0x0000000140503130;
|
||||
return RenderTexture__SetColorDepthTextures(this, color_texture, max_level, depth_texture);
|
||||
int32_t max_level, GLuint depth_texture, bool stencil) {
|
||||
int32_t error = 0;
|
||||
this->max_level = max_level;
|
||||
if (!fbos)
|
||||
error = render_texture_init_framebuffer(this, max_level);
|
||||
render_texture_set_framebuffer_texture(this, color_texture, max_level, depth_texture, stencil);
|
||||
return error;
|
||||
}
|
||||
|
||||
void render_texture_counter_reset() {
|
||||
render_texture_counter = 0;
|
||||
}
|
||||
|
||||
static int32_t render_texture_init_framebuffer(RenderTexture* rt, int32_t max_level) {
|
||||
rt->fbos = force_malloc<GLuint>(max_level + 1LL);
|
||||
glGenFramebuffers(max_level + 1, rt->fbos);
|
||||
return -(gl_state_get_error() != GL_ZERO);
|
||||
}
|
||||
|
||||
static int32_t render_texture_set_framebuffer_texture(RenderTexture* rt,
|
||||
GLuint color_texture, int32_t level, GLuint depth_texture, bool stencil) {
|
||||
if (level < 0 || level > rt->max_level)
|
||||
return -1;
|
||||
|
||||
gl_state_bind_framebuffer(rt->fbos[level]);
|
||||
gl_state_get_error();
|
||||
|
||||
if (color_texture) {
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, color_texture, level);
|
||||
gl_state_get_error();
|
||||
glDrawBufferDLL(GL_COLOR_ATTACHMENT0);
|
||||
glReadBufferDLL(GL_COLOR_ATTACHMENT0);
|
||||
}
|
||||
else {
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, 0);
|
||||
gl_state_get_error();
|
||||
glDrawBufferDLL(GL_ZERO);
|
||||
glReadBufferDLL(GL_ZERO);
|
||||
}
|
||||
gl_state_get_error();
|
||||
|
||||
if (!level) {
|
||||
if (stencil) {
|
||||
if (depth_texture)
|
||||
glFramebufferTexture(GL_FRAMEBUFFER,
|
||||
GL_DEPTH_STENCIL_ATTACHMENT, depth_texture, 0);
|
||||
else if (rt->rbo) {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rt->rbo);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
|
||||
GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rt->rbo);
|
||||
}
|
||||
else
|
||||
glFramebufferTexture(GL_FRAMEBUFFER,
|
||||
GL_DEPTH_STENCIL_ATTACHMENT, 0, 0);
|
||||
}
|
||||
else {
|
||||
if (depth_texture)
|
||||
glFramebufferTexture(GL_FRAMEBUFFER,
|
||||
GL_DEPTH_ATTACHMENT, depth_texture, 0);
|
||||
else if (rt->rbo) {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rt->rbo);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
|
||||
GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->rbo);
|
||||
}
|
||||
else
|
||||
glFramebufferTexture(GL_FRAMEBUFFER,
|
||||
GL_DEPTH_ATTACHMENT, 0, 0);
|
||||
}
|
||||
gl_state_get_error();
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
ret = -1;
|
||||
gl_state_bind_framebuffer(0);
|
||||
gl_state_get_error();
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user