mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-03 20:28:10 +03:00
Temp commit. Auth3D Object HRC breakdown
This commit is contained in:
+22
-92
@@ -11,13 +11,6 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
struct texture_params {
|
||||
GLenum target;
|
||||
GLint wrap_s;
|
||||
GLint wrap_t;
|
||||
GLint wrap_r;
|
||||
};
|
||||
|
||||
static void texture_get_format_type_by_internal_format(GLenum internal_format, GLenum* format, GLenum* type);
|
||||
static uint32_t texture_get_height_align_mip_level(texture* tex, int32_t mip_level);
|
||||
static uint32_t texture_get_height_mip_level(texture* tex, int32_t mip_level);
|
||||
@@ -34,7 +27,6 @@ static void texture_set_params(GLuint texture, GLenum target, int32_t max_mipmap
|
||||
static GLenum texture_txp_get_internal_format(txp* t);
|
||||
|
||||
std::vector<texture*> texture_storage;
|
||||
std::map<GLuint, texture_params> texture_params_storage;
|
||||
|
||||
texture_id::texture_id() : id(0), index(0) {
|
||||
|
||||
@@ -49,6 +41,22 @@ tex(), target(), internal_format(), max_mipmap_level(), size() {
|
||||
|
||||
}
|
||||
|
||||
uint32_t texture::get_height_align_mip_level(uint8_t mip_level) {
|
||||
uint32_t height = this->height >> mip_level;
|
||||
if (flags & TEXTURE_BLOCK_COMPRESSION)
|
||||
return max_def(height, 4);
|
||||
else
|
||||
return max_def(height, 1);
|
||||
}
|
||||
|
||||
uint32_t texture::get_width_align_mip_level(uint8_t mip_level) {
|
||||
uint32_t width = this->width >> mip_level;
|
||||
if (flags & TEXTURE_BLOCK_COMPRESSION)
|
||||
return max_def(width, 4);
|
||||
else
|
||||
return max_def(width, 1);
|
||||
}
|
||||
|
||||
texture* texture_init(texture_id id) {
|
||||
return texture_storage_create_texture(id);
|
||||
}
|
||||
@@ -202,7 +210,6 @@ bool texture_txp_set_load(txp_set* t, texture*** texs, texture_id* ids) {
|
||||
|
||||
inline void texture_storage_init() {
|
||||
texture_storage = {};
|
||||
texture_params_storage = {};
|
||||
}
|
||||
|
||||
inline texture* texture_storage_create_texture(texture_id id) {
|
||||
@@ -252,7 +259,6 @@ inline void texture_storage_delete_texture(texture_id id) {
|
||||
break;
|
||||
}
|
||||
|
||||
texture_params_storage.erase(tex->tex);
|
||||
glDeleteTextures(1, &tex->tex);
|
||||
delete tex;
|
||||
i = texture_storage.erase(i);
|
||||
@@ -260,90 +266,12 @@ inline void texture_storage_delete_texture(texture_id id) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void texture_storage_set_texture_wrap(GLuint texture, GLint wrap_s, GLint wrap_t) {
|
||||
auto elem = texture_params_storage.find(texture);
|
||||
if (elem == texture_params_storage.end())
|
||||
return;
|
||||
|
||||
texture_params& params = elem->second;
|
||||
if (params.wrap_s != wrap_s) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_S, wrap_s);
|
||||
params.wrap_s = wrap_s;
|
||||
}
|
||||
|
||||
if (params.wrap_t != wrap_t) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_T, wrap_t);
|
||||
params.wrap_t = wrap_t;
|
||||
}
|
||||
}
|
||||
|
||||
inline void texture_storage_set_texture_wrap(GLuint texture, GLint wrap_s, GLint wrap_t, GLint wrap_r) {
|
||||
auto elem = texture_params_storage.find(texture);
|
||||
if (elem == texture_params_storage.end())
|
||||
return;
|
||||
|
||||
texture_params& params = elem->second;
|
||||
if (params.wrap_s != wrap_s) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_S, wrap_s);
|
||||
params.wrap_s = wrap_s;
|
||||
}
|
||||
|
||||
if (params.wrap_t != wrap_t) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_T, wrap_t);
|
||||
params.wrap_t = wrap_t;
|
||||
}
|
||||
|
||||
if (params.wrap_r != wrap_r) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_R, wrap_r);
|
||||
params.wrap_r = wrap_r;
|
||||
}
|
||||
}
|
||||
|
||||
inline void texture_storage_set_texture_wrap_s(GLuint texture, GLint wrap) {
|
||||
auto elem = texture_params_storage.find(texture);
|
||||
if (elem == texture_params_storage.end())
|
||||
return;
|
||||
|
||||
texture_params& params = elem->second;
|
||||
if (params.wrap_s != wrap) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_S, wrap);
|
||||
params.wrap_s = wrap;
|
||||
}
|
||||
}
|
||||
|
||||
inline void texture_storage_set_texture_wrap_t(GLuint texture, GLint wrap) {
|
||||
auto elem = texture_params_storage.find(texture);
|
||||
if (elem == texture_params_storage.end())
|
||||
return;
|
||||
|
||||
texture_params& params = elem->second;
|
||||
if (params.wrap_t != wrap) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_T, wrap);
|
||||
params.wrap_t = wrap;
|
||||
}
|
||||
}
|
||||
|
||||
inline void texture_storage_set_texture_wrap_r(GLuint texture, GLint wrap) {
|
||||
auto elem = texture_params_storage.find(texture);
|
||||
if (elem == texture_params_storage.end())
|
||||
return;
|
||||
|
||||
texture_params& params = elem->second;
|
||||
if (params.wrap_r != wrap) {
|
||||
glTexParameteri(params.target, GL_TEXTURE_WRAP_R, wrap);
|
||||
params.wrap_r = wrap;
|
||||
}
|
||||
}
|
||||
|
||||
inline void texture_storage_free() {
|
||||
for (texture*& i : texture_storage) {
|
||||
if (i) {
|
||||
texture_params_storage.erase(i->tex);
|
||||
if (i)
|
||||
glDeleteTextures(1, &i->tex);
|
||||
}
|
||||
delete i;
|
||||
}
|
||||
texture_params_storage.clear();
|
||||
texture_storage.clear();
|
||||
texture_storage.shrink_to_fit();
|
||||
}
|
||||
@@ -568,7 +496,6 @@ static texture* texture_load_tex(texture_id id, GLenum target,
|
||||
return tex;
|
||||
|
||||
glGenTextures(1, &tex->tex);
|
||||
texture_params_storage.insert({ tex->tex, { target } });
|
||||
switch (target) {
|
||||
case GL_TEXTURE_2D:
|
||||
gl_state_bind_texture_2d(tex->tex);
|
||||
@@ -703,8 +630,11 @@ fail:
|
||||
}
|
||||
|
||||
static void texture_set_params(GLuint texture, GLenum target, int32_t max_mipmap_level, bool use_high_anisotropy) {
|
||||
texture_storage_set_texture_wrap(target, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, (float_t*)&vec4_null);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
static const vec4 border_color = 0.0f;
|
||||
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color);
|
||||
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
|
||||
max_mipmap_level > 0 ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
|
||||
|
||||
Reference in New Issue
Block a user