mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
refactor(texture): encapsulate textures with unique_ptr and bind methods
Replace raw GLuint framebuffer textures with std::unique_ptr<Texture>. Update TextureManager to return const Texture* instead of GLuint. Use Texture::bind() for active texture binding. Add RGBA16F and RGB formats. Add texture parameter methods. Update destructors accordingly.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "Cubed/constants.hpp"
|
#include "Cubed/constants.hpp"
|
||||||
#include "Cubed/primitive_data.hpp"
|
#include "Cubed/primitive_data.hpp"
|
||||||
#include "Cubed/render/player_renderer.hpp"
|
#include "Cubed/render/player_renderer.hpp"
|
||||||
|
#include "Cubed/render/texture.hpp"
|
||||||
#include "Cubed/render/vertex_array.hpp"
|
#include "Cubed/render/vertex_array.hpp"
|
||||||
#include "Cubed/render/vertex_buffer.hpp"
|
#include "Cubed/render/vertex_buffer.hpp"
|
||||||
#include "Cubed/shader.hpp"
|
#include "Cubed/shader.hpp"
|
||||||
@@ -137,16 +138,16 @@ private:
|
|||||||
std::unique_ptr<VertexBuffer> m_quad_vbo = 0;
|
std::unique_ptr<VertexBuffer> m_quad_vbo = 0;
|
||||||
|
|
||||||
GLuint m_fbo = 0;
|
GLuint m_fbo = 0;
|
||||||
GLuint m_screen_texture = 0;
|
std::unique_ptr<Texture> m_screen_texture;
|
||||||
GLuint m_screen_depth_texture = 0;
|
std::unique_ptr<Texture> m_screen_depth_texture;
|
||||||
|
|
||||||
GLuint m_oit_fbo = 0;
|
GLuint m_oit_fbo = 0;
|
||||||
GLuint m_accum_texture = 0;
|
std::unique_ptr<Texture> m_accum_texture;
|
||||||
GLuint m_reveal_texture = 0;
|
std::unique_ptr<Texture> m_reveal_texture;
|
||||||
GLuint m_oit_depth_texture = 0;
|
std::unique_ptr<Texture> m_oit_depth_texture;
|
||||||
|
|
||||||
GLuint m_depth_map_fbo = 0;
|
GLuint m_depth_map_fbo = 0;
|
||||||
GLuint m_depth_map_texture = 0;
|
std::unique_ptr<Texture> m_depth_map_texture;
|
||||||
|
|
||||||
glm::mat4 m_ui_proj;
|
glm::mat4 m_ui_proj;
|
||||||
glm::mat4 m_ui_m_matrix;
|
glm::mat4 m_ui_m_matrix;
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ enum TextureFormat : GLenum {
|
|||||||
DEPTH_COMPONENT32F = GL_DEPTH_COMPONENT32F,
|
DEPTH_COMPONENT32F = GL_DEPTH_COMPONENT32F,
|
||||||
DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
|
DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
|
||||||
R16F = GL_R16F,
|
R16F = GL_R16F,
|
||||||
|
RGBA16F = GL_RGBA16F,
|
||||||
RED = GL_RED,
|
RED = GL_RED,
|
||||||
RGBA = GL_RGBA,
|
RGBA = GL_RGBA,
|
||||||
|
RGB = GL_RGB,
|
||||||
RGBA8 = GL_RGBA8,
|
RGBA8 = GL_RGBA8,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ public:
|
|||||||
~TextureManager();
|
~TextureManager();
|
||||||
|
|
||||||
void delet_texture();
|
void delet_texture();
|
||||||
GLuint get_block_status_array() const;
|
const Texture* get_block_status_array() const;
|
||||||
GLuint get_texture_array() const;
|
const Texture* get_texture_array() const;
|
||||||
GLuint get_cross_plane_array() const;
|
const Texture* get_cross_plane_array() const;
|
||||||
GLuint get_ui_array() const;
|
const Texture* get_ui_array() const;
|
||||||
GLuint get_pbr_texture() const;
|
const Texture* get_pbr_texture() const;
|
||||||
const std::vector<std::unique_ptr<Texture>>& item_textures() const;
|
const std::vector<std::unique_ptr<Texture>>& item_textures() const;
|
||||||
GLuint get_skin() const;
|
const Texture* get_skin() const;
|
||||||
// Must call after MapTable::init_map() and glfwMakeContextCurrent(window);
|
// Must call after MapTable::init_map() and glfwMakeContextCurrent(window);
|
||||||
void init_texture();
|
void init_texture();
|
||||||
|
|
||||||
|
|||||||
@@ -223,8 +223,7 @@ void PlayerRenderer::render(const Shader& shader) {
|
|||||||
glm::vec3(0, 1, 0));
|
glm::vec3(0, 1, 0));
|
||||||
model = glm::translate(model, glm::vec3(-0.5f, 0.0f, -0.5f));
|
model = glm::translate(model, glm::vec3(-0.5f, 0.0f, -0.5f));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
m_renderer.texture_mamger().get_skin()->bind(1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_renderer.texture_mamger().get_skin());
|
|
||||||
|
|
||||||
auto make_rotated = [&](glm::vec3 pivot, float angle) {
|
auto make_rotated = [&](glm::vec3 pivot, float angle) {
|
||||||
glm::mat4 mat = model;
|
glm::mat4 mat = model;
|
||||||
|
|||||||
@@ -39,16 +39,16 @@ Renderer::~Renderer() {
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
m_vao.clear();
|
m_vao.clear();
|
||||||
glDeleteFramebuffers(1, &m_fbo);
|
glDeleteFramebuffers(1, &m_fbo);
|
||||||
glDeleteTextures(1, &m_screen_texture);
|
m_screen_texture.reset();
|
||||||
glDeleteTextures(1, &m_screen_depth_texture);
|
m_screen_depth_texture.reset();
|
||||||
|
|
||||||
glDeleteFramebuffers(1, &m_oit_fbo);
|
glDeleteFramebuffers(1, &m_oit_fbo);
|
||||||
glDeleteTextures(1, &m_accum_texture);
|
m_accum_texture.reset();
|
||||||
glDeleteTextures(1, &m_reveal_texture);
|
m_oit_depth_texture.reset();
|
||||||
glDeleteTextures(1, &m_oit_depth_texture);
|
m_reveal_texture.reset();
|
||||||
|
|
||||||
glDeleteFramebuffers(1, &m_depth_map_fbo);
|
glDeleteFramebuffers(1, &m_depth_map_fbo);
|
||||||
glDeleteTextures(1, &m_depth_map_texture);
|
m_depth_map_texture.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,9 +428,7 @@ void Renderer::render_ui() {
|
|||||||
shader.set_loc("proj_matrix", m_ui_proj);
|
shader.set_loc("proj_matrix", m_ui_proj);
|
||||||
|
|
||||||
m_vao[3].bind();
|
m_vao[3].bind();
|
||||||
|
m_texture_manager.get_ui_array()->bind(0);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_texture_manager.get_ui_array());
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
Tools::check_opengl_error();
|
Tools::check_opengl_error();
|
||||||
@@ -455,12 +453,11 @@ void Renderer::render_underwater() {
|
|||||||
shader.set_loc("InverseViewProjection", glm::inverse(m_p_mat * m_v_mat));
|
shader.set_loc("InverseViewProjection", glm::inverse(m_p_mat * m_v_mat));
|
||||||
shader.set_loc("sunColor", m_parallel_light.sun_color);
|
shader.set_loc("sunColor", m_parallel_light.sun_color);
|
||||||
shader.set_loc("u_lightSpaceMatrix", m_parallel_light.light_space_matrix);
|
shader.set_loc("u_lightSpaceMatrix", m_parallel_light.light_space_matrix);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_screen_texture);
|
m_screen_texture->bind(0);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
m_screen_depth_texture->bind(1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_screen_depth_texture);
|
m_depth_map_texture->bind(2);
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_depth_map_texture);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
@@ -494,28 +491,22 @@ void Renderer::updata_framebuffer(int width, int height) {
|
|||||||
glGenFramebuffers(1, &m_oit_fbo);
|
glGenFramebuffers(1, &m_oit_fbo);
|
||||||
}
|
}
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
||||||
|
m_screen_texture = std::make_unique<Texture>(TextureType::TEXTURE_2D);
|
||||||
|
m_screen_texture->tex_image_2d(TextureFormat::RGB, TextureFormat::RGB,
|
||||||
|
GL_UNSIGNED_BYTE, nullptr, width, height);
|
||||||
|
|
||||||
glDeleteTextures(1, &m_screen_texture);
|
m_screen_texture->set_linear();
|
||||||
glDeleteTextures(1, &m_screen_depth_texture);
|
|
||||||
|
|
||||||
glGenTextures(1, &m_screen_texture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_screen_texture);
|
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
|
|
||||||
GL_UNSIGNED_BYTE, NULL);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||||
m_screen_texture, 0);
|
m_screen_texture->id(), 0);
|
||||||
|
|
||||||
glGenTextures(1, &m_screen_depth_texture);
|
m_screen_depth_texture = std::make_unique<Texture>(TextureType::TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_screen_depth_texture);
|
m_screen_depth_texture->tex_image_2d(TextureFormat::DEPTH_COMPONENT32F,
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0,
|
TextureFormat::DEPTH_COMPONENT,
|
||||||
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
GL_FLOAT, nullptr, width, height);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
// m_screen_depth_texture->set_nearest();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
m_screen_depth_texture->set_linear();
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
||||||
m_screen_depth_texture, 0);
|
m_screen_depth_texture->id(), 0);
|
||||||
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
Logger::error("FBO incomplete after resize!");
|
Logger::error("FBO incomplete after resize!");
|
||||||
@@ -525,33 +516,27 @@ void Renderer::updata_framebuffer(int width, int height) {
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_oit_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_oit_fbo);
|
||||||
glDeleteTextures(1, &m_accum_texture);
|
m_accum_texture = std::make_unique<Texture>(TextureType::TEXTURE_2D);
|
||||||
glDeleteTextures(1, &m_reveal_texture);
|
m_accum_texture->tex_image_2d(TextureFormat::RGBA16F, TextureFormat::RGBA,
|
||||||
glDeleteTextures(1, &m_oit_depth_texture);
|
GL_HALF_FLOAT, nullptr, width, height);
|
||||||
glGenTextures(1, &m_accum_texture);
|
m_accum_texture->set_linear();
|
||||||
glBindTexture(GL_TEXTURE_2D, m_accum_texture);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA,
|
|
||||||
GL_HALF_FLOAT, NULL);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||||
m_accum_texture, 0);
|
m_accum_texture->id(), 0);
|
||||||
glGenTextures(1, &m_reveal_texture);
|
m_reveal_texture = std::make_unique<Texture>(TextureType::TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_reveal_texture);
|
m_reveal_texture->tex_image_2d(TextureFormat::R16F, TextureFormat::RED,
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, width, height, 0, GL_RED,
|
GL_HALF_FLOAT, nullptr, width, height);
|
||||||
GL_HALF_FLOAT, NULL);
|
m_reveal_texture->set_linear();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D,
|
||||||
m_reveal_texture, 0);
|
m_reveal_texture->id(), 0);
|
||||||
glGenTextures(1, &m_oit_depth_texture);
|
m_oit_depth_texture = std::make_unique<Texture>(TextureType::TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_oit_depth_texture);
|
m_oit_depth_texture->tex_image_2d(TextureFormat::DEPTH_COMPONENT32F,
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0,
|
TextureFormat::DEPTH_COMPONENT, GL_FLOAT,
|
||||||
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
nullptr, width, height);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
// m_oit_depth_texture->set_nearest();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
m_oit_depth_texture->set_linear();
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
||||||
m_oit_depth_texture, 0);
|
m_oit_depth_texture->id(), 0);
|
||||||
GLenum draw_buffer[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
|
GLenum draw_buffer[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
|
||||||
glDrawBuffers(2, draw_buffer);
|
glDrawBuffers(2, draw_buffer);
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
@@ -565,27 +550,27 @@ void Renderer::updata_framebuffer(int width, int height) {
|
|||||||
if (m_depth_map_fbo == 0) {
|
if (m_depth_map_fbo == 0) {
|
||||||
glGenFramebuffers(1, &m_depth_map_fbo);
|
glGenFramebuffers(1, &m_depth_map_fbo);
|
||||||
}
|
}
|
||||||
glDeleteTextures(1, &m_depth_map_texture);
|
|
||||||
glGenTextures(1, &m_depth_map_texture);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_depth_map_texture);
|
m_depth_map_texture = std::make_unique<Texture>(TextureType::TEXTURE_2D);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, DEPTH_MAP_SIZE,
|
|
||||||
DEPTH_MAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
m_depth_map_texture->tex_image_2d(TextureFormat::DEPTH_COMPONENT32F,
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
TextureFormat::DEPTH_COMPONENT, GL_FLOAT,
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
nullptr, DEPTH_MAP_SIZE, DEPTH_MAP_SIZE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
m_depth_map_texture->set_linear();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
m_depth_map_texture->set_clamp_to_border(false, true, true);
|
||||||
float border_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
float border_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color);
|
|
||||||
// Manually compare shadows
|
// Manually compare shadows
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
m_depth_map_texture->parameterfv(TexturePname::BORDER_COLOR, border_color);
|
||||||
|
m_depth_map_texture->parameter(TexturePname::COMPARE_MODE,
|
||||||
|
TextureParam::T_NONE);
|
||||||
|
|
||||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
|
||||||
// GL_COMPARE_REF_TO_TEXTURE);
|
// GL_COMPARE_REF_TO_TEXTURE);
|
||||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_depth_map_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_depth_map_fbo);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
||||||
m_depth_map_texture, 0);
|
m_depth_map_texture->id(), 0);
|
||||||
glDrawBuffer(GL_NONE);
|
glDrawBuffer(GL_NONE);
|
||||||
glReadBuffer(GL_NONE);
|
glReadBuffer(GL_NONE);
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
@@ -662,14 +647,12 @@ void Renderer::render_world() {
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_depth_map_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_depth_map_fbo);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
for (const auto& snapshot : m_render_snapshots) {
|
for (const auto& snapshot : m_render_snapshots) {
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY,
|
m_texture_manager.get_texture_array()->bind(1);
|
||||||
m_texture_manager.get_texture_array());
|
|
||||||
glBindVertexArray(snapshot->normal_vao);
|
glBindVertexArray(snapshot->normal_vao);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, snapshot->normal_vertices_count);
|
glDrawArrays(GL_TRIANGLES, 0, snapshot->normal_vertices_count);
|
||||||
@@ -686,8 +669,7 @@ void Renderer::render_world() {
|
|||||||
glm::vec2 center_xz{snapshot->center.x, snapshot->center.z};
|
glm::vec2 center_xz{snapshot->center.x, snapshot->center.z};
|
||||||
float dist2d = glm::distance(camera_pos_xz, center_xz);
|
float dist2d = glm::distance(camera_pos_xz, center_xz);
|
||||||
if (dist2d <= CROSS_PLANE_DISTANCE * 16) {
|
if (dist2d <= CROSS_PLANE_DISTANCE * 16) {
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY,
|
m_texture_manager.get_cross_plane_array()->bind(1);
|
||||||
m_texture_manager.get_cross_plane_array());
|
|
||||||
glBindVertexArray(snapshot->cross_vao);
|
glBindVertexArray(snapshot->cross_vao);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0,
|
glDrawArrays(GL_TRIANGLES, 0,
|
||||||
@@ -695,8 +677,9 @@ void Renderer::render_world() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (snapshot->normal_discard_vertices_count != 0) {
|
if (snapshot->normal_discard_vertices_count != 0) {
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY,
|
|
||||||
m_texture_manager.get_texture_array());
|
m_texture_manager.get_texture_array()->bind(1);
|
||||||
|
|
||||||
glBindVertexArray(snapshot->normal_discard_vao);
|
glBindVertexArray(snapshot->normal_discard_vao);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0,
|
glDrawArrays(GL_TRIANGLES, 0,
|
||||||
@@ -751,12 +734,11 @@ void Renderer::render_world() {
|
|||||||
int rendered_sum = 0;
|
int rendered_sum = 0;
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
m_depth_map_texture->bind(0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_depth_map_texture);
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
m_texture_manager.get_texture_array()->bind(1);
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_texture_manager.get_texture_array());
|
m_texture_manager.get_pbr_texture()->bind(2);
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_texture_manager.get_pbr_texture());
|
|
||||||
normal_block_shader.set_loc("enablePBR", m_pbr);
|
normal_block_shader.set_loc("enablePBR", m_pbr);
|
||||||
for (const auto& snapshot : m_render_snapshots) {
|
for (const auto& snapshot : m_render_snapshots) {
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
@@ -789,9 +771,7 @@ void Renderer::render_world() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cross_plane
|
// cross_plane
|
||||||
glActiveTexture(GL_TEXTURE1);
|
m_texture_manager.get_cross_plane_array()->bind(1);
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY,
|
|
||||||
m_texture_manager.get_cross_plane_array());
|
|
||||||
normal_block_shader.set_loc("enablePBR", false);
|
normal_block_shader.set_loc("enablePBR", false);
|
||||||
for (const auto& snapshot : m_render_snapshots) {
|
for (const auto& snapshot : m_render_snapshots) {
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
@@ -855,8 +835,9 @@ void Renderer::render_world() {
|
|||||||
|
|
||||||
set_accum_loc(accum_shader);
|
set_accum_loc(accum_shader);
|
||||||
accum_shader.set_loc("cameraPos", m_camera.get_camera_pos());
|
accum_shader.set_loc("cameraPos", m_camera.get_camera_pos());
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_texture_manager.get_texture_array());
|
m_texture_manager.get_texture_array()->bind(0);
|
||||||
|
|
||||||
for (const auto& snapshot : m_render_snapshots) {
|
for (const auto& snapshot : m_render_snapshots) {
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
continue;
|
continue;
|
||||||
@@ -902,14 +883,9 @@ void Renderer::render_world() {
|
|||||||
water_shader.set_loc("refractStrength", m_refract_strength);
|
water_shader.set_loc("refractStrength", m_refract_strength);
|
||||||
water_shader.set_loc("enablePerturb", m_water_perturb);
|
water_shader.set_loc("enablePerturb", m_water_perturb);
|
||||||
water_shader.set_loc("enableDepthFade", m_water_depth_fade);
|
water_shader.set_loc("enableDepthFade", m_water_depth_fade);
|
||||||
|
m_screen_texture->bind(1);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
m_screen_depth_texture->bind(2);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_screen_texture);
|
m_texture_manager.get_texture_array()->bind(0);
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_screen_depth_texture);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_texture_manager.get_texture_array());
|
|
||||||
for (const auto& snapshot : m_render_snapshots) {
|
for (const auto& snapshot : m_render_snapshots) {
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
continue;
|
continue;
|
||||||
@@ -939,11 +915,8 @@ void Renderer::render_world() {
|
|||||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
m_vao[0].bind();
|
m_vao[0].bind();
|
||||||
|
m_accum_texture->bind(0);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
m_reveal_texture->bind(1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_accum_texture);
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_reveal_texture);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
@@ -973,10 +946,7 @@ void Renderer::render_player() {
|
|||||||
shader.set_loc("samples", m_samples);
|
shader.set_loc("samples", m_samples);
|
||||||
// shader.set_loc("renderDistance", m_world.rendering_distance());
|
// shader.set_loc("renderDistance", m_world.rendering_distance());
|
||||||
// shader.set_loc("skyColor", m_sky_uniform.sky_top);
|
// shader.set_loc("skyColor", m_sky_uniform.sky_top);
|
||||||
|
m_depth_map_texture->bind(0);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_depth_map_texture);
|
|
||||||
|
|
||||||
m_player_renderer.render(shader);
|
m_player_renderer.render(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,21 +50,21 @@ void TextureManager::delet_texture() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint TextureManager::get_block_status_array() const {
|
const Texture* TextureManager::get_block_status_array() const {
|
||||||
return m_block_status_array->id();
|
return m_block_status_array.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint TextureManager::get_texture_array() const {
|
const Texture* TextureManager::get_texture_array() const {
|
||||||
return m_texture_array->id();
|
return m_texture_array.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint TextureManager::get_cross_plane_array() const {
|
const Texture* TextureManager::get_cross_plane_array() const {
|
||||||
return m_cross_plane_array->id();
|
return m_cross_plane_array.get();
|
||||||
}
|
}
|
||||||
GLuint TextureManager::get_ui_array() const { return m_ui_array->id(); }
|
const Texture* TextureManager::get_ui_array() const { return m_ui_array.get(); }
|
||||||
|
|
||||||
GLuint TextureManager::get_pbr_texture() const {
|
const Texture* TextureManager::get_pbr_texture() const {
|
||||||
return m_normal_texture_array->id();
|
return m_normal_texture_array.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::unique_ptr<Texture>>&
|
const std::vector<std::unique_ptr<Texture>>&
|
||||||
@@ -72,7 +72,7 @@ TextureManager::item_textures() const {
|
|||||||
return m_item_textures;
|
return m_item_textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint TextureManager::get_skin() const { return m_skin->id(); }
|
const Texture* TextureManager::get_skin() const { return m_skin.get(); }
|
||||||
|
|
||||||
void TextureManager::load_block_status(unsigned id) {
|
void TextureManager::load_block_status(unsigned id) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user