mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add outline for block that is looked
This commit is contained in:
@@ -13,13 +13,32 @@ TextureManager::~TextureManager() {
|
||||
|
||||
void TextureManager::delet_texture() {
|
||||
glDeleteTextures(1, &m_texture_array);
|
||||
glDeleteTextures(1, &m_block_status_array);
|
||||
LOG::info("Successfully delete all texture");
|
||||
}
|
||||
|
||||
GLuint TextureManager::get_block_status_array() {
|
||||
return m_block_status_array;
|
||||
}
|
||||
|
||||
GLuint TextureManager::get_texture_array() {
|
||||
return m_texture_array;
|
||||
}
|
||||
void TextureManager::load_block_status(int id) {
|
||||
|
||||
CUBED_ASSERT_MSG(id < MAX_BLOCK_STATUS, "Exceed the max status sum limit");
|
||||
std::string path = "assets/texture/status/" + std::to_string(id) + ".png";
|
||||
unsigned char* image_data = nullptr;
|
||||
image_data = (Shader::load_image_data(path));
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_block_status_array);
|
||||
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
|
||||
0 ,0, id,
|
||||
16, 16, 1,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
image_data
|
||||
);
|
||||
Shader::delete_image_data(image_data);
|
||||
}
|
||||
void TextureManager::load_block_texture(unsigned id) {
|
||||
CUBED_ASSERT_MSG(id < MAX_BLOCK_NUM, "Exceed the max block sum limit");
|
||||
const std::string& name = MapTable::get_name_from_id(id);
|
||||
@@ -27,7 +46,7 @@ void TextureManager::load_block_texture(unsigned id) {
|
||||
if (id == 0) {
|
||||
return;
|
||||
}
|
||||
unsigned char * image_data[6];
|
||||
unsigned char* image_data[6];
|
||||
|
||||
std::string block_texture_path = "assets/texture/block/" + name;
|
||||
image_data[0] = (Shader::load_image_data(block_texture_path + "/front.png"));
|
||||
@@ -87,4 +106,33 @@ void TextureManager::init_texture() {
|
||||
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
|
||||
}
|
||||
|
||||
glGenTextures(1, &m_block_status_array);
|
||||
Shader::check_opengl_error();
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_block_status_array);
|
||||
Shader::check_opengl_error();
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
0, GL_RGBA,
|
||||
16, 16,
|
||||
MAX_BLOCK_STATUS,
|
||||
0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, nullptr);
|
||||
Shader::check_opengl_error();
|
||||
for (int i = 0; i < MAX_BLOCK_STATUS; i++) {
|
||||
load_block_status(i);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_block_status_array);
|
||||
Shader::check_opengl_error();
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
Shader::check_opengl_error();
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
Shader::check_opengl_error();
|
||||
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
||||
Shader::check_opengl_error();
|
||||
|
||||
if (max_aniso > 0.0f) {
|
||||
LOG::info("Support anisotropic filtering max_aniso is {}", max_aniso);
|
||||
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user