mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 12:12:28 +00:00
Overhaul GLES3: Add basis for 3D renderer, overhaul materials and textures
This commit is contained in:
parent
d9d871dfbf
commit
2f2064fe3d
@ -117,6 +117,7 @@ void RasterizerCanvasGLES3::_update_transform_to_mat4(const Transform3D &p_trans
|
||||
|
||||
void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_list, const Transform2D &p_canvas_transform, RS::CanvasItemTextureFilter p_default_filter, RS::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
GLES3::MaterialStorage *material_storage = GLES3::MaterialStorage::get_singleton();
|
||||
|
||||
texture_storage->frame.current_rt = nullptr;
|
||||
|
||||
@ -155,7 +156,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
|
||||
state_buffer.screen_pixel_size[0] = 1.0 / render_target_size.x;
|
||||
state_buffer.screen_pixel_size[1] = 1.0 / render_target_size.y;
|
||||
|
||||
state_buffer.time = texture_storage->frame.time;
|
||||
state_buffer.time = state.time;
|
||||
state_buffer.use_pixel_snap = p_snap_2d_vertices_to_pixel;
|
||||
|
||||
state_buffer.directional_light_count = 0; //directional_light_count;
|
||||
@ -178,8 +179,12 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
|
||||
|
||||
//print_line("w: " + itos(ssize.width) + " s: " + rtos(canvas_scale));
|
||||
state_buffer.tex_to_sdf = 1.0 / ((canvas_scale.x + canvas_scale.y) * 0.5);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_state_buffer);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, BASE_UNIFORM_BUFFER_OBJECT, state.canvas_state_buffer);
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(StateBuffer), &state_buffer, GL_STREAM_DRAW);
|
||||
|
||||
GLuint global_buffer = material_storage->global_variables_get_uniform_buffer();
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, GLOBAL_UNIFORM_BUFFER_OBJECT, global_buffer);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
}
|
||||
|
||||
@ -197,8 +202,6 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
|
||||
r_sdf_used = false;
|
||||
int item_count = 0;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
||||
Item *ci = p_item_list;
|
||||
while (ci) {
|
||||
// just add all items for now
|
||||
@ -215,7 +218,6 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, bool p_to_backbuffer) {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
GLES3::MaterialStorage *material_storage = GLES3::MaterialStorage::get_singleton();
|
||||
Item *current_clip = nullptr;
|
||||
|
||||
@ -229,88 +231,31 @@ void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_cou
|
||||
RID prev_material;
|
||||
uint32_t index = 0;
|
||||
|
||||
state.current_shader_version = state.canvas_shader_default_version;
|
||||
|
||||
for (int i = 0; i < p_item_count; i++) {
|
||||
Item *ci = items[i];
|
||||
|
||||
RID material = ci->material_owner == nullptr ? ci->material : ci->material_owner->material;
|
||||
GLES3::Material *material_ptr = material_storage->get_material(material);
|
||||
|
||||
if (material.is_null() && ci->canvas_group != nullptr) {
|
||||
material = default_canvas_group_material;
|
||||
}
|
||||
|
||||
if (material != prev_material) {
|
||||
GLES3::Shader *shader_ptr = nullptr;
|
||||
|
||||
if (material_ptr) {
|
||||
shader_ptr = material_ptr->shader;
|
||||
|
||||
if (shader_ptr && shader_ptr->mode != RS::SHADER_CANVAS_ITEM) {
|
||||
shader_ptr = nullptr; // not a canvas item shader, don't use.
|
||||
}
|
||||
GLES3::CanvasMaterialData *material_data = nullptr;
|
||||
if (material.is_valid()) {
|
||||
material_data = static_cast<GLES3::CanvasMaterialData *>(material_storage->material_get_data(material, RS::SHADER_CANVAS_ITEM));
|
||||
}
|
||||
|
||||
if (shader_ptr) {
|
||||
if (true) { //check that shader has changed
|
||||
if (shader_ptr->canvas_item.uses_time) {
|
||||
RenderingServerDefault::redraw_request();
|
||||
}
|
||||
//state.canvas_shader.version_bind_shader(shader_ptr->version, CanvasShaderGLES3::MODE_QUAD);
|
||||
state.current_shader_version = shader_ptr->version;
|
||||
if (material_data) {
|
||||
if (material_data->shader_data->version.is_valid() && material_data->shader_data->valid) {
|
||||
// Bind uniform buffer and textures
|
||||
material_data->bind_uniforms();
|
||||
state.current_shader_version = material_data->shader_data->version;
|
||||
} else {
|
||||
state.current_shader_version = state.canvas_shader_default_version;
|
||||
}
|
||||
|
||||
int tc = material_ptr->textures.size();
|
||||
Pair<StringName, RID> *textures = material_ptr->textures.ptrw();
|
||||
|
||||
ShaderCompiler::GeneratedCode::Texture *texture_uniforms = shader_ptr->texture_uniforms.ptrw();
|
||||
|
||||
for (int ti = 0; ti < tc; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + ti);
|
||||
|
||||
GLES3::Texture *t = texture_storage->get_texture(textures[ti].second);
|
||||
|
||||
if (!t) {
|
||||
switch (texture_uniforms[i].hint) {
|
||||
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO:
|
||||
case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: {
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
|
||||
} break;
|
||||
case ShaderLanguage::ShaderNode::Uniform::HINT_ANISOTROPY: {
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex);
|
||||
} break;
|
||||
case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: {
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
||||
} break;
|
||||
default: {
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
||||
} break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//Set texture filter and repeat texture_uniforms[i].filter texture_uniforms[i].repeat
|
||||
|
||||
if (t->redraw_if_visible) {
|
||||
RenderingServerDefault::redraw_request();
|
||||
}
|
||||
|
||||
t = t->get_ptr();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (t->detect_normal && texture_uniforms[i].hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL) {
|
||||
t->detect_normal(t->detect_normal_ud);
|
||||
}
|
||||
#endif
|
||||
if (t->render_target) {
|
||||
t->render_target->used_in_frame = true;
|
||||
}
|
||||
|
||||
glBindTexture(t->target, t->tex_id);
|
||||
}
|
||||
|
||||
} else {
|
||||
//state.canvas_shader.version_bind_shader(state.canvas_shader_default_version, CanvasShaderGLES3::MODE_QUAD);
|
||||
state.current_shader_version = state.canvas_shader_default_version;
|
||||
}
|
||||
prev_material = material;
|
||||
@ -389,7 +334,7 @@ void RasterizerCanvasGLES3::_render_item(RID p_render_target, const Item *p_item
|
||||
state.current_command = Item::Command::TYPE_RECT;
|
||||
}
|
||||
_bind_canvas_texture(rect->texture, current_filter, current_repeat, r_index, last_texture, texpixel_size);
|
||||
state.canvas_shader.version_bind_shader(state.current_shader_version, CanvasShaderGLES3::MODE_QUAD);
|
||||
GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_bind_shader(state.current_shader_version, CanvasShaderGLES3::MODE_QUAD);
|
||||
|
||||
Rect2 src_rect;
|
||||
Rect2 dst_rect;
|
||||
@ -552,7 +497,7 @@ void RasterizerCanvasGLES3::_render_item(RID p_render_target, const Item *p_item
|
||||
state.current_command = Item::Command::TYPE_POLYGON;
|
||||
}
|
||||
_bind_canvas_texture(polygon->texture, current_filter, current_repeat, r_index, last_texture, texpixel_size);
|
||||
state.canvas_shader.version_bind_shader(state.current_shader_version, CanvasShaderGLES3::MODE_ATTRIBUTES);
|
||||
GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_bind_shader(state.current_shader_version, CanvasShaderGLES3::MODE_ATTRIBUTES);
|
||||
|
||||
state.current_primitive = polygon->primitive;
|
||||
state.instance_data_array[r_index].modulation[0] = base_color.r;
|
||||
@ -566,16 +511,18 @@ void RasterizerCanvasGLES3::_render_item(RID p_render_target, const Item *p_item
|
||||
state.instance_data_array[r_index].ninepatch_margins[j] = 0;
|
||||
}
|
||||
|
||||
// If the previous operation is not done yet, allocated a new buffer
|
||||
GLint syncStatus;
|
||||
glGetSynciv(state.fences[state.current_buffer], GL_SYNC_STATUS, sizeof(GLint), nullptr, &syncStatus);
|
||||
if (syncStatus == GL_UNSIGNALED) {
|
||||
_allocate_instance_data_buffer();
|
||||
} else {
|
||||
glDeleteSync(state.fences[state.current_buffer]);
|
||||
// If the previous operation is not done yet, allocate a new buffer
|
||||
if (state.fences[state.current_buffer] != GLsync()) {
|
||||
GLint syncStatus;
|
||||
glGetSynciv(state.fences[state.current_buffer], GL_SYNC_STATUS, sizeof(GLint), nullptr, &syncStatus);
|
||||
if (syncStatus == GL_UNSIGNALED) {
|
||||
_allocate_instance_data_buffer();
|
||||
} else {
|
||||
glDeleteSync(state.fences[state.current_buffer]);
|
||||
}
|
||||
}
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 3, state.canvas_instance_data_buffers[state.current_buffer]);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, INSTANCE_UNIFORM_BUFFER_OBJECT, state.canvas_instance_data_buffers[state.current_buffer]);
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
//WebGL 2.0 does not support mapping buffers, so use slow glBufferData instead
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(InstanceData), &state.instance_data_array[0], GL_DYNAMIC_DRAW);
|
||||
@ -609,7 +556,7 @@ void RasterizerCanvasGLES3::_render_item(RID p_render_target, const Item *p_item
|
||||
state.current_command = Item::Command::TYPE_PRIMITIVE;
|
||||
}
|
||||
_bind_canvas_texture(RID(), current_filter, current_repeat, r_index, last_texture, texpixel_size);
|
||||
state.canvas_shader.version_bind_shader(state.current_shader_version, CanvasShaderGLES3::MODE_PRIMITIVE);
|
||||
GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_bind_shader(state.current_shader_version, CanvasShaderGLES3::MODE_PRIMITIVE);
|
||||
|
||||
for (uint32_t j = 0; j < MIN(3u, primitive->point_count); j++) {
|
||||
state.instance_data_array[r_index].points[j * 2 + 0] = primitive->points[j].x;
|
||||
@ -771,15 +718,17 @@ void RasterizerCanvasGLES3::_render_item(RID p_render_target, const Item *p_item
|
||||
void RasterizerCanvasGLES3::_render_batch(uint32_t &r_index) {
|
||||
if (state.end_batch && r_index > 0) {
|
||||
// If the previous operation is not done yet, allocate a new buffer
|
||||
GLint syncStatus;
|
||||
glGetSynciv(state.fences[state.current_buffer], GL_SYNC_STATUS, sizeof(GLint), nullptr, &syncStatus);
|
||||
if (syncStatus == GL_UNSIGNALED) {
|
||||
_allocate_instance_data_buffer();
|
||||
} else {
|
||||
glDeleteSync(state.fences[state.current_buffer]);
|
||||
if (state.fences[state.current_buffer] != GLsync()) {
|
||||
GLint syncStatus;
|
||||
glGetSynciv(state.fences[state.current_buffer], GL_SYNC_STATUS, sizeof(GLint), nullptr, &syncStatus);
|
||||
if (syncStatus == GL_UNSIGNALED) {
|
||||
_allocate_instance_data_buffer();
|
||||
} else {
|
||||
glDeleteSync(state.fences[state.current_buffer]);
|
||||
}
|
||||
}
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 3, state.canvas_instance_data_buffers[state.current_buffer]);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, INSTANCE_UNIFORM_BUFFER_OBJECT, state.canvas_instance_data_buffers[state.current_buffer]);
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
//WebGL 2.0 does not support mapping buffers, so use slow glBufferData instead
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(InstanceData) * r_index, state.instance_data_array, GL_DYNAMIC_DRAW);
|
||||
@ -903,7 +852,8 @@ void RasterizerCanvasGLES3::canvas_begin() {
|
||||
reset_canvas();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
||||
GLES3::Texture *tex = texture_storage->get_texture(texture_storage->texture_gl_get_default(GLES3::DEFAULT_GL_TEXTURE_WHITE));
|
||||
glBindTexture(GL_TEXTURE_2D, tex->tex_id);
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES3::canvas_end() {
|
||||
@ -961,11 +911,9 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
||||
ct->size_cache = Size2i(1, 1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
||||
|
||||
GLES3::Texture *tex = texture_storage->get_texture(texture_storage->texture_gl_get_default(GLES3::DEFAULT_GL_TEXTURE_WHITE));
|
||||
glBindTexture(GL_TEXTURE_2D, tex->tex_id);
|
||||
} else {
|
||||
texture = texture->get_ptr();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->tex_id);
|
||||
|
||||
@ -973,8 +921,8 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
||||
state.current_tex_ptr = texture;
|
||||
ct->size_cache = Size2i(texture->width, texture->height);
|
||||
|
||||
texture->GLSetFilter(GL_TEXTURE_2D, filter);
|
||||
texture->GLSetRepeat(GL_TEXTURE_2D, repeat);
|
||||
texture->gl_set_filter(filter);
|
||||
texture->gl_set_repeat(repeat);
|
||||
}
|
||||
|
||||
GLES3::Texture *normal_map = texture_storage->get_texture(ct->normal_map);
|
||||
@ -983,17 +931,16 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
||||
state.current_normal = RID();
|
||||
ct->use_normal_cache = false;
|
||||
glActiveTexture(GL_TEXTURE0 + GLES3::Config::get_singleton()->max_texture_image_units - 6);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
||||
GLES3::Texture *tex = texture_storage->get_texture(texture_storage->texture_gl_get_default(GLES3::DEFAULT_GL_TEXTURE_NORMAL));
|
||||
glBindTexture(GL_TEXTURE_2D, tex->tex_id);
|
||||
|
||||
} else {
|
||||
normal_map = normal_map->get_ptr();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config->max_texture_image_units - 6);
|
||||
glBindTexture(GL_TEXTURE_2D, normal_map->tex_id);
|
||||
state.current_normal = ct->normal_map;
|
||||
ct->use_normal_cache = true;
|
||||
texture->GLSetFilter(GL_TEXTURE_2D, filter);
|
||||
texture->GLSetRepeat(GL_TEXTURE_2D, repeat);
|
||||
texture->gl_set_filter(filter);
|
||||
texture->gl_set_repeat(repeat);
|
||||
}
|
||||
|
||||
GLES3::Texture *specular_map = texture_storage->get_texture(ct->specular);
|
||||
@ -1002,17 +949,15 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
||||
state.current_specular = RID();
|
||||
ct->use_specular_cache = false;
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config->max_texture_image_units - 7);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
||||
|
||||
GLES3::Texture *tex = texture_storage->get_texture(texture_storage->texture_gl_get_default(GLES3::DEFAULT_GL_TEXTURE_WHITE));
|
||||
glBindTexture(GL_TEXTURE_2D, tex->tex_id);
|
||||
} else {
|
||||
specular_map = specular_map->get_ptr();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config->max_texture_image_units - 7);
|
||||
glBindTexture(GL_TEXTURE_2D, specular_map->tex_id);
|
||||
state.current_specular = ct->specular;
|
||||
ct->use_specular_cache = true;
|
||||
texture->GLSetFilter(GL_TEXTURE_2D, filter);
|
||||
texture->GLSetRepeat(GL_TEXTURE_2D, repeat);
|
||||
texture->gl_set_filter(filter);
|
||||
texture->gl_set_repeat(repeat);
|
||||
}
|
||||
|
||||
if (ct->use_specular_cache) {
|
||||
@ -1260,7 +1205,19 @@ void RasterizerCanvasGLES3::_allocate_instance_data_buffer() {
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES3::initialize() {
|
||||
void RasterizerCanvasGLES3::set_time(double p_time) {
|
||||
state.time = p_time;
|
||||
}
|
||||
|
||||
RasterizerCanvasGLES3 *RasterizerCanvasGLES3::singleton = nullptr;
|
||||
|
||||
RasterizerCanvasGLES3 *RasterizerCanvasGLES3::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
RasterizerCanvasGLES3::RasterizerCanvasGLES3(RasterizerStorageGLES3 *p_storage) {
|
||||
singleton = this;
|
||||
storage = p_storage;
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
GLES3::MaterialStorage *material_storage = GLES3::MaterialStorage::get_singleton();
|
||||
|
||||
@ -1386,9 +1343,7 @@ void RasterizerCanvasGLES3::initialize() {
|
||||
}
|
||||
|
||||
//state.canvas_shadow_shader.init();
|
||||
|
||||
int uniform_max_size;
|
||||
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &uniform_max_size);
|
||||
int uniform_max_size = storage->config->max_uniform_buffer_size;
|
||||
if (uniform_max_size < 65536) {
|
||||
state.max_lights_per_render = 64;
|
||||
state.max_instances_per_batch = 128;
|
||||
@ -1402,6 +1357,7 @@ void RasterizerCanvasGLES3::initialize() {
|
||||
state.fences.resize(64);
|
||||
glGenBuffers(64, state.canvas_instance_data_buffers.ptr());
|
||||
for (int i = 0; i < 64; i++) {
|
||||
state.fences[i] = GLsync();
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, state.canvas_instance_data_buffers[i]);
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(InstanceData) * state.max_instances_per_batch, nullptr, GL_DYNAMIC_DRAW);
|
||||
}
|
||||
@ -1419,9 +1375,9 @@ void RasterizerCanvasGLES3::initialize() {
|
||||
global_defines += "#define MAX_LIGHTS " + itos(state.max_instances_per_batch) + "\n";
|
||||
global_defines += "#define MAX_DRAW_DATA_INSTANCES " + itos(state.max_instances_per_batch) + "\n";
|
||||
|
||||
state.canvas_shader.initialize(global_defines);
|
||||
state.canvas_shader_default_version = state.canvas_shader.version_create();
|
||||
state.canvas_shader.version_bind_shader(state.canvas_shader_default_version, CanvasShaderGLES3::MODE_QUAD);
|
||||
GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.initialize(global_defines);
|
||||
state.canvas_shader_default_version = GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_create();
|
||||
GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_bind_shader(state.canvas_shader_default_version, CanvasShaderGLES3::MODE_QUAD);
|
||||
|
||||
//state.canvas_shader.set_conditional(CanvasOldShaderGLES3::USE_RGBA_SHADOWS, storage->config->use_rgba_2d_shadows);
|
||||
|
||||
@ -1463,32 +1419,19 @@ void fragment() {
|
||||
state.using_transparent_rt = false;
|
||||
state.using_skeleton = false;
|
||||
state.current_shader_version = state.canvas_shader_default_version;
|
||||
}
|
||||
|
||||
RasterizerCanvasGLES3 *RasterizerCanvasGLES3::singleton = nullptr;
|
||||
|
||||
RasterizerCanvasGLES3 *RasterizerCanvasGLES3::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
RasterizerCanvasGLES3::RasterizerCanvasGLES3(RasterizerStorageGLES3 *p_storage) {
|
||||
singleton = this;
|
||||
storage = p_storage;
|
||||
initialize();
|
||||
state.time = 0.0;
|
||||
}
|
||||
|
||||
RasterizerCanvasGLES3::~RasterizerCanvasGLES3() {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
GLES3::MaterialStorage *material_storage = GLES3::MaterialStorage::get_singleton();
|
||||
|
||||
state.canvas_shader.version_free(state.canvas_shader_default_version);
|
||||
GLES3::MaterialStorage::get_singleton()->shaders.canvas_shader.version_free(state.canvas_shader_default_version);
|
||||
material_storage->material_free(default_canvas_group_material);
|
||||
material_storage->shader_free(default_canvas_group_shader);
|
||||
texture_storage->canvas_texture_free(default_canvas_texture);
|
||||
singleton = nullptr;
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES3::finalize() {
|
||||
glDeleteBuffers(1, &data.canvas_quad_vertices);
|
||||
glDeleteVertexArrays(1, &data.canvas_quad_array);
|
||||
|
||||
|
@ -53,13 +53,6 @@ class RasterizerCanvasGLES3 : public RendererCanvasRender {
|
||||
_FORCE_INLINE_ void _update_transform_2d_to_mat4(const Transform2D &p_transform, float *p_mat4);
|
||||
_FORCE_INLINE_ void _update_transform_to_mat4(const Transform3D &p_transform, float *p_mat4);
|
||||
|
||||
enum {
|
||||
BASE_UNIFORM_BUFFER_OBJECT = 0,
|
||||
MATERIAL_UNIFORM_BUFFER_OBJECT = 1,
|
||||
TRANSFORMS_UNIFORM_BUFFER_OBJECT = 2,
|
||||
CANVAS_TEXTURE_UNIFORM_BUFFER_OBJECT = 3,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
FLAGS_INSTANCING_MASK = 0x7F,
|
||||
@ -104,6 +97,15 @@ class RasterizerCanvasGLES3 : public RendererCanvasRender {
|
||||
};
|
||||
|
||||
public:
|
||||
//TODO move to Material storage
|
||||
enum {
|
||||
BASE_UNIFORM_BUFFER_OBJECT = 0,
|
||||
GLOBAL_UNIFORM_BUFFER_OBJECT = 1,
|
||||
LIGHT_UNIFORM_BUFFER_OBJECT = 2,
|
||||
INSTANCE_UNIFORM_BUFFER_OBJECT = 3,
|
||||
MATERIAL_UNIFORM_BUFFER_OBJECT = 4,
|
||||
};
|
||||
|
||||
struct StateBuffer {
|
||||
float canvas_transform[16];
|
||||
float screen_transform[16];
|
||||
@ -170,7 +172,7 @@ public:
|
||||
|
||||
InstanceData *instance_data_array = nullptr;
|
||||
bool canvas_texscreen_used;
|
||||
CanvasShaderGLES3 canvas_shader;
|
||||
//CanvasShaderGLES3 canvas_shader;
|
||||
RID canvas_shader_current_version;
|
||||
RID canvas_shader_default_version;
|
||||
//CanvasShadowShaderGLES3 canvas_shadow_shader;
|
||||
@ -203,6 +205,8 @@ public:
|
||||
|
||||
// FROM RD Renderer
|
||||
|
||||
double time = 0.0;
|
||||
|
||||
uint32_t max_lights_per_render;
|
||||
uint32_t max_lights_per_item;
|
||||
uint32_t max_instances_per_batch;
|
||||
@ -273,11 +277,10 @@ public:
|
||||
void _end_batch(uint32_t &p_max_index);
|
||||
void _allocate_instance_data_buffer();
|
||||
|
||||
void initialize();
|
||||
void finalize();
|
||||
void set_time(double p_time);
|
||||
|
||||
static RasterizerCanvasGLES3 *get_singleton();
|
||||
RasterizerCanvasGLES3(RasterizerStorageGLES3 *storage);
|
||||
RasterizerCanvasGLES3(RasterizerStorageGLES3 *p_storage);
|
||||
~RasterizerCanvasGLES3();
|
||||
};
|
||||
|
||||
|
@ -88,8 +88,6 @@
|
||||
#endif
|
||||
|
||||
void RasterizerGLES3::begin_frame(double frame_step) {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
|
||||
frame++;
|
||||
delta = frame_step;
|
||||
|
||||
@ -98,11 +96,8 @@ void RasterizerGLES3::begin_frame(double frame_step) {
|
||||
double time_roll_over = GLOBAL_GET("rendering/limits/time/time_rollover_secs");
|
||||
time_total = Math::fmod(time_total, time_roll_over);
|
||||
|
||||
texture_storage->frame.time = time_total;
|
||||
texture_storage->frame.count++;
|
||||
texture_storage->frame.delta = frame_step;
|
||||
|
||||
storage->update_dirty_resources();
|
||||
canvas->set_time(time_total);
|
||||
scene->set_time(time_total, frame_step);
|
||||
|
||||
storage->info.render_final = storage->info.render;
|
||||
storage->info.render.reset();
|
||||
@ -197,10 +192,18 @@ typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userP
|
||||
|
||||
void RasterizerGLES3::initialize() {
|
||||
print_line("OpenGL Renderer: " + RS::get_singleton()->get_video_adapter_name());
|
||||
}
|
||||
|
||||
texture_storage->set_main_thread_id(Thread::get_caller_id());
|
||||
// make sure the OS knows to only access the renderer from the main thread
|
||||
OS::get_singleton()->set_render_main_thread_mode(OS::RENDER_MAIN_THREAD_ONLY);
|
||||
void RasterizerGLES3::finalize() {
|
||||
memdelete(scene);
|
||||
memdelete(canvas);
|
||||
memdelete(storage);
|
||||
memdelete(light_storage);
|
||||
memdelete(particles_storage);
|
||||
memdelete(mesh_storage);
|
||||
memdelete(material_storage);
|
||||
memdelete(texture_storage);
|
||||
memdelete(config);
|
||||
}
|
||||
|
||||
RasterizerGLES3::RasterizerGLES3() {
|
||||
@ -264,19 +267,14 @@ RasterizerGLES3::RasterizerGLES3() {
|
||||
light_storage = memnew(GLES3::LightStorage);
|
||||
storage = memnew(RasterizerStorageGLES3);
|
||||
canvas = memnew(RasterizerCanvasGLES3(storage));
|
||||
scene = memnew(RasterizerSceneGLES3);
|
||||
scene = memnew(RasterizerSceneGLES3(storage));
|
||||
|
||||
texture_storage->set_main_thread_id(Thread::get_caller_id());
|
||||
// make sure the OS knows to only access the renderer from the main thread
|
||||
OS::get_singleton()->set_render_main_thread_mode(OS::RENDER_MAIN_THREAD_ONLY);
|
||||
}
|
||||
|
||||
RasterizerGLES3::~RasterizerGLES3() {
|
||||
memdelete(scene);
|
||||
memdelete(canvas);
|
||||
memdelete(storage);
|
||||
memdelete(light_storage);
|
||||
memdelete(particles_storage);
|
||||
memdelete(mesh_storage);
|
||||
memdelete(material_storage);
|
||||
memdelete(texture_storage);
|
||||
memdelete(config);
|
||||
}
|
||||
|
||||
void RasterizerGLES3::prepare_for_blitting_render_targets() {
|
||||
@ -298,7 +296,7 @@ void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, Display
|
||||
}
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
|
||||
glBlitFramebuffer(0, 0, rt->width, rt->height, 0, p_screen_rect.size.y, p_screen_rect.size.x, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBlitFramebuffer(0, 0, rt->size.x, rt->size.y, 0, p_screen_rect.size.y, p_screen_rect.size.x, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
|
||||
// is this p_screen useless in a multi window environment?
|
||||
@ -340,10 +338,8 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
|
||||
|
||||
canvas->canvas_begin();
|
||||
|
||||
RID texture = texture_storage->texture_create();
|
||||
//texture_storage.texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_use_filter ? VS::TEXTURE_FLAG_FILTER : 0);
|
||||
texture_storage->_texture_allocate_internal(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), RenderingDevice::TEXTURE_TYPE_2D);
|
||||
texture_storage->texture_set_data(texture, p_image);
|
||||
RID texture = texture_storage->texture_allocate();
|
||||
texture_storage->texture_2d_initialize(texture, p_image);
|
||||
|
||||
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
|
||||
Rect2 screenrect;
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
|
||||
void end_frame(bool p_swap_buffers);
|
||||
|
||||
void finalize() {}
|
||||
void finalize();
|
||||
|
||||
static RendererCompositor *_create_current() {
|
||||
return memnew(RasterizerGLES3);
|
||||
|
@ -29,10 +29,18 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "rasterizer_scene_gles3.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "servers/rendering/rendering_server_default.h"
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
// TODO: 3D support not implemented yet.
|
||||
uint64_t RasterizerSceneGLES3::auto_exposure_counter = 2;
|
||||
|
||||
RasterizerSceneGLES3 *RasterizerSceneGLES3::singleton = nullptr;
|
||||
|
||||
RasterizerSceneGLES3 *RasterizerSceneGLES3::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
RasterizerSceneGLES3::GeometryInstance *RasterizerSceneGLES3::geometry_instance_create(RID p_base) {
|
||||
return nullptr;
|
||||
@ -137,39 +145,130 @@ int RasterizerSceneGLES3::get_directional_light_shadow_size(RID p_light_intance)
|
||||
void RasterizerSceneGLES3::set_directional_shadow_count(int p_count) {
|
||||
}
|
||||
|
||||
/* SDFGI UPDATE */
|
||||
|
||||
void RasterizerSceneGLES3::sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) {
|
||||
}
|
||||
|
||||
int RasterizerSceneGLES3::sdfgi_get_pending_region_count(RID p_render_buffers) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
AABB RasterizerSceneGLES3::sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
uint32_t RasterizerSceneGLES3::sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SKY API */
|
||||
|
||||
void RasterizerSceneGLES3::Sky::free() {
|
||||
if (radiance != 0) {
|
||||
glDeleteTextures(1, &radiance);
|
||||
radiance = 0;
|
||||
glDeleteFramebuffers(1, &radiance_framebuffer);
|
||||
radiance_framebuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
RID RasterizerSceneGLES3::sky_allocate() {
|
||||
return RID();
|
||||
return sky_owner.allocate_rid();
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::sky_initialize(RID p_rid) {
|
||||
sky_owner.initialize_rid(p_rid);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::sky_set_radiance_size(RID p_sky, int p_radiance_size) {
|
||||
Sky *sky = sky_owner.get_or_null(p_sky);
|
||||
ERR_FAIL_COND(!sky);
|
||||
ERR_FAIL_COND_MSG(p_radiance_size < 32 || p_radiance_size > 2048, "Sky radiance size must be between 32 and 2048");
|
||||
|
||||
if (sky->radiance_size == p_radiance_size) {
|
||||
return; // No need to update
|
||||
}
|
||||
|
||||
sky->radiance_size = p_radiance_size;
|
||||
|
||||
sky->free();
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::sky_set_mode(RID p_sky, RS::SkyMode p_samples) {
|
||||
void RasterizerSceneGLES3::sky_set_mode(RID p_sky, RS::SkyMode p_mode) {
|
||||
Sky *sky = sky_owner.get_or_null(p_sky);
|
||||
ERR_FAIL_COND(!sky);
|
||||
|
||||
if (sky->mode == p_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
sky->mode = p_mode;
|
||||
|
||||
if (sky->mode == RS::SKY_MODE_REALTIME) {
|
||||
WARN_PRINT_ONCE("The OpenGL renderer does not support the Real Time Sky Update Mode yet. Please use High Quality Mode instead");
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::sky_set_material(RID p_sky, RID p_material) {
|
||||
Sky *sky = sky_owner.get_or_null(p_sky);
|
||||
ERR_FAIL_COND(!sky);
|
||||
|
||||
if (sky->material == p_material) {
|
||||
return;
|
||||
}
|
||||
|
||||
sky->material = p_material;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::_invalidate_sky(Sky *p_sky) {
|
||||
if (!p_sky->dirty) {
|
||||
p_sky->dirty = true;
|
||||
p_sky->dirty_list = dirty_sky_list;
|
||||
dirty_sky_list = p_sky;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::_update_dirty_skys() {
|
||||
Sky *sky = dirty_sky_list;
|
||||
|
||||
while (sky) {
|
||||
if (sky->radiance == 0) {
|
||||
//int mipmaps = Image::get_image_required_mipmaps(sky->radiance_size, sky->radiance_size, Image::FORMAT_RGBAH) + 1;
|
||||
|
||||
//uint32_t w = sky->radiance_size, h = sky->radiance_size;
|
||||
//int layers = sky_globals.roughness_layers;
|
||||
glGenFramebuffers(1, &sky->radiance_framebuffer);
|
||||
|
||||
glGenTextures(1, &sky->radiance);
|
||||
}
|
||||
|
||||
sky->reflection_dirty = true;
|
||||
sky->processing_layer = 0;
|
||||
|
||||
Sky *next = sky->dirty_list;
|
||||
sky->dirty_list = nullptr;
|
||||
sky->dirty = false;
|
||||
sky = next;
|
||||
}
|
||||
|
||||
dirty_sky_list = nullptr;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::_draw_sky(Sky *p_sky, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_custom_fov, float p_energy, const Basis &p_sky_orientation) {
|
||||
ERR_FAIL_COND(!p_sky);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_BLEND);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glColorMask(1, 1, 1, 1);
|
||||
|
||||
//state.sky_shader.version_bind_shader(sky_globals.default_shader, SkyShaderGLES3::MODE_BACKGROUND);
|
||||
//glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.canvas_instance_data_buffers[state.current_buffer]); // Canvas data updated here
|
||||
//glBindBufferBase(GL_UNIFORM_BUFFER, 1, state.canvas_instance_data_buffers[state.current_buffer]); // Global data
|
||||
//glBindBufferBase(GL_UNIFORM_BUFFER, 2, state.canvas_instance_data_buffers[state.current_buffer]); // Directional light data
|
||||
//glBindBufferBase(GL_UNIFORM_BUFFER, 3, state.canvas_instance_data_buffers[state.current_buffer]); // Material uniforms
|
||||
|
||||
// Camera
|
||||
CameraMatrix camera;
|
||||
|
||||
if (p_custom_fov) {
|
||||
float near_plane = p_projection.get_z_near();
|
||||
float far_plane = p_projection.get_z_far();
|
||||
float aspect = p_projection.get_aspect();
|
||||
|
||||
camera.set_perspective(p_custom_fov, aspect, near_plane, far_plane);
|
||||
|
||||
} else {
|
||||
camera = p_projection;
|
||||
}
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
}
|
||||
|
||||
Ref<Image> RasterizerSceneGLES3::sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) {
|
||||
@ -179,52 +278,107 @@ Ref<Image> RasterizerSceneGLES3::sky_bake_panorama(RID p_sky, float p_energy, bo
|
||||
/* ENVIRONMENT API */
|
||||
|
||||
RID RasterizerSceneGLES3::environment_allocate() {
|
||||
return RID();
|
||||
return environment_owner.allocate_rid();
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_initialize(RID p_rid) {
|
||||
environment_owner.initialize_rid(p_rid);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_background(RID p_env, RS::EnvironmentBG p_bg) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->background = p_bg;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_sky(RID p_env, RID p_sky) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->sky = p_sky;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_sky_custom_fov(RID p_env, float p_scale) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->sky_custom_fov = p_scale;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_sky_orientation(RID p_env, const Basis &p_orientation) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->sky_orientation = p_orientation;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_bg_color(RID p_env, const Color &p_color) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->bg_color = p_color;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_bg_energy(RID p_env, float p_energy) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->bg_energy = p_energy;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_canvas_max_layer(RID p_env, int p_max_layer) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->canvas_max_layer = p_max_layer;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->ambient_light = p_color;
|
||||
env->ambient_source = p_ambient;
|
||||
env->ambient_light_energy = p_energy;
|
||||
env->ambient_sky_contribution = p_sky_contribution;
|
||||
env->reflection_source = p_reflection_source;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, float p_glow_map_strength, RID p_glow_map) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
ERR_FAIL_COND_MSG(p_levels.size() != 7, "Size of array of glow levels must be 7");
|
||||
env->glow_enabled = p_enable;
|
||||
env->glow_levels = p_levels;
|
||||
env->glow_intensity = p_intensity;
|
||||
env->glow_strength = p_strength;
|
||||
env->glow_mix = p_mix;
|
||||
env->glow_bloom = p_bloom_threshold;
|
||||
env->glow_blend_mode = p_blend_mode;
|
||||
env->glow_hdr_bleed_threshold = p_hdr_bleed_threshold;
|
||||
env->glow_hdr_bleed_scale = p_hdr_bleed_scale;
|
||||
env->glow_hdr_luminance_cap = p_hdr_luminance_cap;
|
||||
env->glow_map_strength = p_glow_map_strength;
|
||||
env->glow_map = p_glow_map;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_glow_set_use_bicubic_upscale(bool p_enable) {
|
||||
glow_bicubic_upscale = p_enable;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_glow_set_use_high_quality(bool p_enable) {
|
||||
glow_high_quality = p_enable;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->ssr_enabled = p_enable;
|
||||
env->ssr_max_steps = p_max_steps;
|
||||
env->ssr_fade_in = p_fade_int;
|
||||
env->ssr_fade_out = p_fade_out;
|
||||
env->ssr_depth_tolerance = p_depth_tolerance;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) {
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) {
|
||||
@ -248,12 +402,43 @@ void RasterizerSceneGLES3::environment_set_sdfgi_frames_to_update_light(RS::Envi
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->exposure = p_exposure;
|
||||
env->tone_mapper = p_tone_mapper;
|
||||
if (!env->auto_exposure && p_auto_exposure) {
|
||||
env->auto_exposure_version = ++auto_exposure_counter;
|
||||
}
|
||||
env->auto_exposure = p_auto_exposure;
|
||||
env->white = p_white;
|
||||
env->min_luminance = p_min_luminance;
|
||||
env->max_luminance = p_max_luminance;
|
||||
env->auto_exp_speed = p_auto_exp_speed;
|
||||
env->auto_exp_scale = p_auto_exp_scale;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->adjustments_enabled = p_enable;
|
||||
env->adjustments_brightness = p_brightness;
|
||||
env->adjustments_contrast = p_contrast;
|
||||
env->adjustments_saturation = p_saturation;
|
||||
env->use_1d_color_correction = p_use_1d_color_correction;
|
||||
env->color_correction = p_color_correction;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND(!env);
|
||||
env->fog_enabled = p_enable;
|
||||
env->fog_light_color = p_light_color;
|
||||
env->fog_light_energy = p_light_energy;
|
||||
env->fog_sun_scatter = p_sun_scatter;
|
||||
env->fog_density = p_density;
|
||||
env->fog_height = p_height;
|
||||
env->fog_height_density = p_height_density;
|
||||
env->fog_aerial_perspective = p_aerial_perspective;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_albedo, const Color &p_emission, float p_emission_energy, float p_anisotropy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount, float p_ambient_inject) {
|
||||
@ -266,19 +451,25 @@ void RasterizerSceneGLES3::environment_set_volumetric_fog_filter_active(bool p_e
|
||||
}
|
||||
|
||||
Ref<Image> RasterizerSceneGLES3::environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) {
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND_V(!env, Ref<Image>());
|
||||
return Ref<Image>();
|
||||
}
|
||||
|
||||
bool RasterizerSceneGLES3::is_environment(RID p_env) const {
|
||||
return false;
|
||||
return environment_owner.owns(p_env);
|
||||
}
|
||||
|
||||
RS::EnvironmentBG RasterizerSceneGLES3::environment_get_background(RID p_env) const {
|
||||
return RS::ENV_BG_KEEP;
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND_V(!env, RS::ENV_BG_MAX);
|
||||
return env->background;
|
||||
}
|
||||
|
||||
int RasterizerSceneGLES3::environment_get_canvas_max_layer(RID p_env) const {
|
||||
return 0;
|
||||
Environment *env = environment_owner.get_or_null(p_env);
|
||||
ERR_FAIL_COND_V(!env, 0);
|
||||
return env->canvas_max_layer;
|
||||
}
|
||||
|
||||
RID RasterizerSceneGLES3::camera_effects_allocate() {
|
||||
@ -409,6 +600,148 @@ void RasterizerSceneGLES3::voxel_gi_set_quality(RS::VoxelGIQuality) {
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, const PagedArray<RID> &p_fog_volumes, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data, RendererScene::RenderInfo *r_render_info) {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
RENDER_TIMESTAMP("Setup 3D Scene");
|
||||
// assign render data
|
||||
// Use the format from rendererRD
|
||||
RenderDataGLES3 render_data;
|
||||
{
|
||||
render_data.render_buffers = p_render_buffers;
|
||||
|
||||
// Our first camera is used by default
|
||||
render_data.cam_transform = p_camera_data->main_transform;
|
||||
render_data.cam_projection = p_camera_data->main_projection;
|
||||
render_data.view_projection[0] = p_camera_data->main_projection;
|
||||
render_data.cam_ortogonal = p_camera_data->is_ortogonal;
|
||||
|
||||
render_data.view_count = p_camera_data->view_count;
|
||||
for (uint32_t v = 0; v < p_camera_data->view_count; v++) {
|
||||
render_data.view_projection[v] = p_camera_data->view_projection[v];
|
||||
}
|
||||
|
||||
render_data.z_near = p_camera_data->main_projection.get_z_near();
|
||||
render_data.z_far = p_camera_data->main_projection.get_z_far();
|
||||
|
||||
render_data.instances = &p_instances;
|
||||
render_data.lights = &p_lights;
|
||||
render_data.reflection_probes = &p_reflection_probes;
|
||||
//render_data.voxel_gi_instances = &p_voxel_gi_instances;
|
||||
//render_data.decals = &p_decals;
|
||||
//render_data.lightmaps = &p_lightmaps;
|
||||
//render_data.fog_volumes = &p_fog_volumes;
|
||||
render_data.environment = p_environment;
|
||||
render_data.camera_effects = p_camera_effects;
|
||||
render_data.shadow_atlas = p_shadow_atlas;
|
||||
render_data.reflection_atlas = p_reflection_atlas;
|
||||
render_data.reflection_probe = p_reflection_probe;
|
||||
render_data.reflection_probe_pass = p_reflection_probe_pass;
|
||||
|
||||
// this should be the same for all cameras..
|
||||
render_data.lod_distance_multiplier = p_camera_data->main_projection.get_lod_multiplier();
|
||||
render_data.lod_camera_plane = Plane(-p_camera_data->main_transform.basis.get_axis(Vector3::AXIS_Z), p_camera_data->main_transform.get_origin());
|
||||
|
||||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_DISABLE_LOD) {
|
||||
render_data.screen_mesh_lod_threshold = 0.0;
|
||||
} else {
|
||||
render_data.screen_mesh_lod_threshold = p_screen_mesh_lod_threshold;
|
||||
}
|
||||
render_data.render_info = r_render_info;
|
||||
}
|
||||
|
||||
PagedArray<RID> empty;
|
||||
|
||||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_UNSHADED) {
|
||||
render_data.lights = ∅
|
||||
render_data.reflection_probes = ∅
|
||||
}
|
||||
|
||||
RenderBuffers *rb = nullptr;
|
||||
//RasterizerStorageGLES3::RenderTarget *rt = nullptr;
|
||||
if (p_render_buffers.is_valid()) {
|
||||
rb = render_buffers_owner.get_or_null(p_render_buffers);
|
||||
ERR_FAIL_COND(!rb);
|
||||
//rt = texture_storage->render_target_owner.get_or_null(rb->render_target);
|
||||
//ERR_FAIL_COND(!rt);
|
||||
}
|
||||
|
||||
Color clear_color;
|
||||
if (p_render_buffers.is_valid()) {
|
||||
clear_color = texture_storage->render_target_get_clear_request_color(rb->render_target);
|
||||
} else {
|
||||
clear_color = storage->get_default_clear_color();
|
||||
}
|
||||
|
||||
Environment *env = environment_owner.get_or_null(p_environment);
|
||||
|
||||
bool fb_cleared = false;
|
||||
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
/* Depth Prepass */
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, rb->framebuffer);
|
||||
|
||||
if (!fb_cleared) {
|
||||
glClearDepth(1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
bool draw_sky = false;
|
||||
bool keep_color = false;
|
||||
|
||||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW) {
|
||||
clear_color = Color(0, 0, 0, 1);
|
||||
}
|
||||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW) {
|
||||
clear_color = Color(0, 0, 0, 1); //in overdraw mode, BG should always be black
|
||||
} else if (is_environment(p_environment)) {
|
||||
RS::EnvironmentBG bg_mode = environment_get_background(p_environment);
|
||||
float bg_energy = env->bg_energy; //environment_get_bg_energy(p_environment);
|
||||
switch (bg_mode) {
|
||||
case RS::ENV_BG_CLEAR_COLOR: {
|
||||
clear_color.r *= bg_energy;
|
||||
clear_color.g *= bg_energy;
|
||||
clear_color.b *= bg_energy;
|
||||
} break;
|
||||
case RS::ENV_BG_COLOR: {
|
||||
clear_color = env->bg_color; //environment_get_bg_color(p_environment);
|
||||
clear_color.r *= bg_energy;
|
||||
clear_color.g *= bg_energy;
|
||||
clear_color.b *= bg_energy;
|
||||
} break;
|
||||
case RS::ENV_BG_SKY: {
|
||||
draw_sky = true;
|
||||
} break;
|
||||
case RS::ENV_BG_CANVAS: {
|
||||
keep_color = true;
|
||||
} break;
|
||||
case RS::ENV_BG_KEEP: {
|
||||
keep_color = true;
|
||||
} break;
|
||||
case RS::ENV_BG_CAMERA_FEED: {
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!keep_color) {
|
||||
glClearBufferfv(GL_COLOR, 0, clear_color.components);
|
||||
}
|
||||
|
||||
if (draw_sky) {
|
||||
//_draw_sky(sky, render_data.cam_projection, render_data.cam_transform, env->sky_custom_fov, env->bg_energy, env->sky_orientation);
|
||||
}
|
||||
|
||||
if (p_render_buffers.is_valid()) {
|
||||
/*
|
||||
RENDER_TIMESTAMP("Tonemap");
|
||||
_render_buffers_post_process_and_tonemap(&render_data);
|
||||
*/
|
||||
|
||||
_render_buffers_debug_draw(p_render_buffers, p_shadow_atlas, p_occluder_debug_tex);
|
||||
}
|
||||
texture_storage->render_target_disable_clear_request(rb->render_target);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) {
|
||||
@ -417,20 +750,203 @@ void RasterizerSceneGLES3::render_material(const Transform3D &p_cam_transform, c
|
||||
void RasterizerSceneGLES3::render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) {
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::set_scene_pass(uint64_t p_pass) {
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::set_time(double p_time, double p_step) {
|
||||
time = p_time;
|
||||
time_step = p_step;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) {
|
||||
debug_draw = p_debug_draw;
|
||||
}
|
||||
|
||||
RID RasterizerSceneGLES3::render_buffers_create() {
|
||||
return RID();
|
||||
RenderBuffers rb;
|
||||
return render_buffers_owner.make_rid(rb);
|
||||
}
|
||||
|
||||
/* BACK FBO */
|
||||
/* For MSAA */
|
||||
/*
|
||||
#ifndef JAVASCRIPT_ENABLED
|
||||
if (rt->msaa >= RS::VIEWPORT_MSAA_2X && rt->msaa <= RS::VIEWPORT_MSAA_8X) {
|
||||
rt->multisample_active = true;
|
||||
|
||||
static const int msaa_value[] = { 0, 2, 4, 8, 16 };
|
||||
int msaa = msaa_value[rt->msaa];
|
||||
|
||||
int max_samples = 0;
|
||||
glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
|
||||
if (msaa > max_samples) {
|
||||
WARN_PRINT("MSAA must be <= GL_MAX_SAMPLES, falling-back to GL_MAX_SAMPLES = " + itos(max_samples));
|
||||
msaa = max_samples;
|
||||
}
|
||||
|
||||
//regular fbo
|
||||
glGenFramebuffers(1, &rt->multisample_fbo);
|
||||
bind_framebuffer(rt->multisample_fbo);
|
||||
|
||||
glGenRenderbuffers(1, &rt->multisample_depth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rt->multisample_depth);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, config.depth_buffer_internalformat, rt->size.x, rt->size.y);
|
||||
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->multisample_depth);
|
||||
|
||||
glGenRenderbuffers(1, &rt->multisample_color);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rt->multisample_color);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->size.x, rt->size.y);
|
||||
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rt->multisample_color);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
// Delete allocated resources and default to no MSAA
|
||||
WARN_PRINT_ONCE("Cannot allocate back framebuffer for MSAA");
|
||||
printf("err status: %x\n", status);
|
||||
rt->multisample_active = false;
|
||||
|
||||
glDeleteFramebuffers(1, &rt->multisample_fbo);
|
||||
rt->multisample_fbo = 0;
|
||||
|
||||
glDeleteRenderbuffers(1, &rt->multisample_depth);
|
||||
rt->multisample_depth = 0;
|
||||
|
||||
glDeleteRenderbuffers(1, &rt->multisample_color);
|
||||
rt->multisample_color = 0;
|
||||
}
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
bind_framebuffer(0);
|
||||
|
||||
} else
|
||||
#endif // JAVASCRIPT_ENABLED
|
||||
{
|
||||
rt->multisample_active = false;
|
||||
}
|
||||
*/
|
||||
|
||||
// copy texscreen buffers
|
||||
// if (!(rt->flags[RendererStorage::RENDER_TARGET_NO_SAMPLING])) {
|
||||
/*
|
||||
if (false) {
|
||||
glGenTextures(1, &rt->copy_screen_effect.color);
|
||||
glBindTexture(GL_TEXTURE_2D, rt->copy_screen_effect.color);
|
||||
|
||||
if (rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rt->size.x, rt->size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
} else {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, rt->size.x, rt->size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glGenFramebuffers(1, &rt->copy_screen_effect.fbo);
|
||||
bind_framebuffer(rt->copy_screen_effect.fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->copy_screen_effect.color, 0);
|
||||
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
_clear_render_target(rt);
|
||||
ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void RasterizerSceneGLES3::render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_internal_width, int p_internal_height, int p_width, int p_height, float p_fsr_sharpness, float p_fsr_mipmap_bias, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding, uint32_t p_view_count) {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
|
||||
RenderBuffers *rb = render_buffers_owner.get_or_null(p_render_buffers);
|
||||
ERR_FAIL_COND(!rb);
|
||||
|
||||
//rb->internal_width = p_internal_width; // ignore for now
|
||||
//rb->internal_height = p_internal_height;
|
||||
rb->width = p_width;
|
||||
rb->height = p_height;
|
||||
//rb->fsr_sharpness = p_fsr_sharpness;
|
||||
rb->render_target = p_render_target;
|
||||
//rb->msaa = p_msaa;
|
||||
//rb->screen_space_aa = p_screen_space_aa;
|
||||
//rb->use_debanding = p_use_debanding;
|
||||
//rb->view_count = p_view_count;
|
||||
|
||||
_free_render_buffer_data(rb);
|
||||
|
||||
GLES3::RenderTarget *rt = texture_storage->get_render_target(p_render_target);
|
||||
|
||||
// framebuffer
|
||||
glGenFramebuffers(1, &rb->framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, rb->framebuffer);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, rt->color);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0);
|
||||
|
||||
glGenTextures(1, &rb->depth_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, rb->depth_texture);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, rt->size.x, rt->size.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rb->depth_texture, 0);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, texture_storage->system_fbo);
|
||||
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
_free_render_buffer_data(rb);
|
||||
WARN_PRINT("Could not create 3D renderbuffer, status: " + texture_storage->get_framebuffer_error(status));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::_free_render_buffer_data(RenderBuffers *rb) {
|
||||
if (rb->depth_texture) {
|
||||
glDeleteTextures(1, &rb->depth_texture);
|
||||
rb->depth_texture = 0;
|
||||
}
|
||||
if (rb->framebuffer) {
|
||||
glDeleteFramebuffers(1, &rb->framebuffer);
|
||||
rb->framebuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//clear render buffers
|
||||
/*
|
||||
|
||||
|
||||
if (rt->copy_screen_effect.color) {
|
||||
glDeleteFramebuffers(1, &rt->copy_screen_effect.fbo);
|
||||
rt->copy_screen_effect.fbo = 0;
|
||||
|
||||
glDeleteTextures(1, &rt->copy_screen_effect.color);
|
||||
rt->copy_screen_effect.color = 0;
|
||||
}
|
||||
|
||||
if (rt->multisample_active) {
|
||||
glDeleteFramebuffers(1, &rt->multisample_fbo);
|
||||
rt->multisample_fbo = 0;
|
||||
|
||||
glDeleteRenderbuffers(1, &rt->multisample_depth);
|
||||
rt->multisample_depth = 0;
|
||||
|
||||
glDeleteRenderbuffers(1, &rt->multisample_color);
|
||||
|
||||
rt->multisample_color = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
void RasterizerSceneGLES3::_render_buffers_debug_draw(RID p_render_buffers, RID p_shadow_atlas, RID p_occlusion_buffer) {
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::gi_set_use_half_resolution(bool p_enable) {
|
||||
@ -454,10 +970,27 @@ TypedArray<Image> RasterizerSceneGLES3::bake_render_uv2(RID p_base, const Vector
|
||||
}
|
||||
|
||||
bool RasterizerSceneGLES3::free(RID p_rid) {
|
||||
return false;
|
||||
if (environment_owner.owns(p_rid)) {
|
||||
environment_owner.free(p_rid);
|
||||
} else if (sky_owner.owns(p_rid)) {
|
||||
Sky *sky = sky_owner.get_or_null(p_rid);
|
||||
ERR_FAIL_COND_V(!sky, false);
|
||||
sky->free();
|
||||
sky_owner.free(p_rid);
|
||||
} else if (render_buffers_owner.owns(p_rid)) {
|
||||
RenderBuffers *rb = render_buffers_owner.get_or_null(p_rid);
|
||||
ERR_FAIL_COND_V(!rb, false);
|
||||
_free_render_buffer_data(rb);
|
||||
render_buffers_owner.free(p_rid);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::update() {
|
||||
_update_dirty_skys();
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES3::sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) {
|
||||
@ -469,7 +1002,48 @@ void RasterizerSceneGLES3::decals_set_filter(RS::DecalFilter p_filter) {
|
||||
void RasterizerSceneGLES3::light_projectors_set_filter(RS::LightProjectorFilter p_filter) {
|
||||
}
|
||||
|
||||
RasterizerSceneGLES3::RasterizerSceneGLES3() {
|
||||
RasterizerSceneGLES3::RasterizerSceneGLES3(RasterizerStorageGLES3 *p_storage) {
|
||||
GLES3::MaterialStorage *material_storage = GLES3::MaterialStorage::get_singleton();
|
||||
storage = p_storage;
|
||||
|
||||
{
|
||||
// Initialize Sky stuff
|
||||
sky_globals.roughness_layers = GLOBAL_GET("rendering/reflections/sky_reflections/roughness_layers");
|
||||
sky_globals.ggx_samples = GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples");
|
||||
|
||||
String global_defines;
|
||||
global_defines += "#define MAX_GLOBAL_VARIABLES 256\n"; // TODO: this is arbitrary for now
|
||||
global_defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(sky_globals.max_directional_lights) + "\n";
|
||||
state.sky_shader.initialize(global_defines);
|
||||
sky_globals.shader_default_version = state.sky_shader.version_create();
|
||||
state.sky_shader.version_bind_shader(sky_globals.shader_default_version, SkyShaderGLES3::MODE_BACKGROUND);
|
||||
}
|
||||
|
||||
{
|
||||
sky_globals.default_shader = material_storage->shader_allocate();
|
||||
|
||||
material_storage->shader_initialize(sky_globals.default_shader);
|
||||
|
||||
material_storage->shader_set_code(sky_globals.default_shader, R"(
|
||||
// Default sky shader.
|
||||
|
||||
shader_type sky;
|
||||
|
||||
void sky() {
|
||||
COLOR = vec3(0.0);
|
||||
}
|
||||
)");
|
||||
sky_globals.default_material = material_storage->material_allocate();
|
||||
material_storage->material_initialize(sky_globals.default_material);
|
||||
|
||||
material_storage->material_set_shader(sky_globals.default_material, sky_globals.default_shader);
|
||||
}
|
||||
}
|
||||
|
||||
RasterizerSceneGLES3::~RasterizerSceneGLES3() {
|
||||
state.sky_shader.version_free(sky_globals.shader_default_version);
|
||||
storage->free(sky_globals.default_material);
|
||||
storage->free(sky_globals.default_shader);
|
||||
}
|
||||
|
||||
#endif // GLES3_ENABLED
|
||||
|
@ -36,15 +36,314 @@
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "core/templates/self_list.h"
|
||||
#include "rasterizer_storage_gles3.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
#include "servers/rendering_server.h"
|
||||
#include "shader_gles3.h"
|
||||
#include "shaders/sky.glsl.gen.h"
|
||||
|
||||
// Copied from renderer_scene_render_rd
|
||||
struct RenderDataGLES3 {
|
||||
RID render_buffers = RID();
|
||||
|
||||
Transform3D cam_transform = Transform3D();
|
||||
CameraMatrix cam_projection = CameraMatrix();
|
||||
bool cam_ortogonal = false;
|
||||
|
||||
// For stereo rendering
|
||||
uint32_t view_count = 1;
|
||||
CameraMatrix view_projection[RendererSceneRender::MAX_RENDER_VIEWS];
|
||||
|
||||
float z_near = 0.0;
|
||||
float z_far = 0.0;
|
||||
|
||||
const PagedArray<RendererSceneRender::GeometryInstance *> *instances = nullptr;
|
||||
const PagedArray<RID> *lights = nullptr;
|
||||
const PagedArray<RID> *reflection_probes = nullptr;
|
||||
//const PagedArray<RID> *voxel_gi_instances = nullptr;
|
||||
//const PagedArray<RID> *decals = nullptr;
|
||||
//const PagedArray<RID> *lightmaps = nullptr;
|
||||
//const PagedArray<RID> *fog_volumes = nullptr;
|
||||
RID environment = RID();
|
||||
RID camera_effects = RID();
|
||||
RID shadow_atlas = RID();
|
||||
RID reflection_atlas = RID();
|
||||
RID reflection_probe = RID();
|
||||
int reflection_probe_pass = 0;
|
||||
|
||||
float lod_distance_multiplier = 0.0;
|
||||
Plane lod_camera_plane = Plane();
|
||||
float screen_mesh_lod_threshold = 0.0;
|
||||
|
||||
uint32_t directional_light_count = 0;
|
||||
|
||||
RendererScene::RenderInfo *render_info = nullptr;
|
||||
};
|
||||
|
||||
class RasterizerStorageGLES3;
|
||||
class RasterizerCanvasGLES3;
|
||||
|
||||
class RasterizerSceneGLES3 : public RendererSceneRender {
|
||||
private:
|
||||
static RasterizerSceneGLES3 *singleton;
|
||||
RS::ViewportDebugDraw debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED;
|
||||
uint64_t scene_pass = 0;
|
||||
|
||||
/* Sky */
|
||||
struct SkyGlobals {
|
||||
RID shader_current_version;
|
||||
RID shader_default_version;
|
||||
RID default_material;
|
||||
RID default_shader;
|
||||
uint32_t max_directional_lights = 4;
|
||||
uint32_t roughness_layers = 8;
|
||||
uint32_t ggx_samples = 128;
|
||||
} sky_globals;
|
||||
|
||||
protected:
|
||||
double time;
|
||||
double time_step = 0;
|
||||
|
||||
struct RenderBuffers {
|
||||
int internal_width = 0;
|
||||
int internal_height = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
//float fsr_sharpness = 0.2f;
|
||||
RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
|
||||
//RS::ViewportScreenSpaceAA screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED;
|
||||
//bool use_debanding = false;
|
||||
//uint32_t view_count = 1;
|
||||
|
||||
RID render_target;
|
||||
GLuint internal_texture = 0; // Used for rendering when post effects are enabled
|
||||
GLuint depth_texture = 0; // Main depth texture
|
||||
GLuint framebuffer = 0; // Main framebuffer, contains internal_texture and depth_texture or render_target->color and depth_texture
|
||||
|
||||
//built-in textures used for ping pong image processing and blurring
|
||||
struct Blur {
|
||||
RID texture;
|
||||
|
||||
struct Mipmap {
|
||||
RID texture;
|
||||
int width;
|
||||
int height;
|
||||
GLuint fbo;
|
||||
};
|
||||
|
||||
Vector<Mipmap> mipmaps;
|
||||
};
|
||||
|
||||
Blur blur[2]; //the second one starts from the first mipmap
|
||||
|
||||
/*
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
GLuint depth = 0;
|
||||
|
||||
GLuint multisample_fbo = 0;
|
||||
GLuint multisample_color = 0;
|
||||
GLuint multisample_depth = 0;
|
||||
bool multisample_active = false;
|
||||
|
||||
struct Effect {
|
||||
GLuint fbo = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
GLuint color = 0;
|
||||
|
||||
Effect() {
|
||||
}
|
||||
};
|
||||
|
||||
Effect copy_screen_effect;
|
||||
|
||||
struct MipMaps {
|
||||
struct Size {
|
||||
GLuint fbo;
|
||||
GLuint color;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
Vector<Size> sizes;
|
||||
GLuint color = 0;
|
||||
int levels = 0;
|
||||
|
||||
MipMaps() {
|
||||
}
|
||||
};
|
||||
|
||||
MipMaps mip_maps[2];
|
||||
|
||||
*/
|
||||
};
|
||||
|
||||
bool screen_space_roughness_limiter = false;
|
||||
float screen_space_roughness_limiter_amount = 0.25;
|
||||
float screen_space_roughness_limiter_limit = 0.18;
|
||||
|
||||
mutable RID_Owner<RenderBuffers, true> render_buffers_owner;
|
||||
|
||||
void _free_render_buffer_data(RenderBuffers *rb);
|
||||
void _allocate_blur_textures(RenderBuffers *rb);
|
||||
void _allocate_depth_backbuffer_textures(RenderBuffers *rb);
|
||||
|
||||
void _render_buffers_debug_draw(RID p_render_buffers, RID p_shadow_atlas, RID p_occlusion_buffer);
|
||||
|
||||
/* Environment */
|
||||
|
||||
struct Environment {
|
||||
// BG
|
||||
RS::EnvironmentBG background = RS::ENV_BG_CLEAR_COLOR;
|
||||
RID sky;
|
||||
float sky_custom_fov = 0.0;
|
||||
Basis sky_orientation;
|
||||
Color bg_color;
|
||||
float bg_energy = 1.0;
|
||||
int canvas_max_layer = 0;
|
||||
RS::EnvironmentAmbientSource ambient_source = RS::ENV_AMBIENT_SOURCE_BG;
|
||||
Color ambient_light;
|
||||
float ambient_light_energy = 1.0;
|
||||
float ambient_sky_contribution = 1.0;
|
||||
RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG;
|
||||
Color ao_color;
|
||||
|
||||
/// Tonemap
|
||||
|
||||
RS::EnvironmentToneMapper tone_mapper;
|
||||
float exposure = 1.0;
|
||||
float white = 1.0;
|
||||
bool auto_exposure = false;
|
||||
float min_luminance = 0.2;
|
||||
float max_luminance = 8.0;
|
||||
float auto_exp_speed = 0.2;
|
||||
float auto_exp_scale = 0.5;
|
||||
uint64_t auto_exposure_version = 0;
|
||||
|
||||
// Fog
|
||||
bool fog_enabled = false;
|
||||
Color fog_light_color = Color(0.5, 0.6, 0.7);
|
||||
float fog_light_energy = 1.0;
|
||||
float fog_sun_scatter = 0.0;
|
||||
float fog_density = 0.001;
|
||||
float fog_height = 0.0;
|
||||
float fog_height_density = 0.0; //can be negative to invert effect
|
||||
float fog_aerial_perspective = 0.0;
|
||||
|
||||
/// Glow
|
||||
bool glow_enabled = false;
|
||||
Vector<float> glow_levels;
|
||||
float glow_intensity = 0.8;
|
||||
float glow_strength = 1.0;
|
||||
float glow_bloom = 0.0;
|
||||
float glow_mix = 0.01;
|
||||
RS::EnvironmentGlowBlendMode glow_blend_mode = RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT;
|
||||
float glow_hdr_bleed_threshold = 1.0;
|
||||
float glow_hdr_luminance_cap = 12.0;
|
||||
float glow_hdr_bleed_scale = 2.0;
|
||||
float glow_map_strength = 1.0;
|
||||
RID glow_map = RID();
|
||||
|
||||
/// SSAO
|
||||
bool ssao_enabled = false;
|
||||
float ssao_radius = 1.0;
|
||||
float ssao_intensity = 2.0;
|
||||
float ssao_power = 1.5;
|
||||
float ssao_detail = 0.5;
|
||||
float ssao_horizon = 0.06;
|
||||
float ssao_sharpness = 0.98;
|
||||
float ssao_direct_light_affect = 0.0;
|
||||
float ssao_ao_channel_affect = 0.0;
|
||||
|
||||
/// SSR
|
||||
bool ssr_enabled = false;
|
||||
int ssr_max_steps = 64;
|
||||
float ssr_fade_in = 0.15;
|
||||
float ssr_fade_out = 2.0;
|
||||
float ssr_depth_tolerance = 0.2;
|
||||
|
||||
/// Adjustments
|
||||
bool adjustments_enabled = false;
|
||||
float adjustments_brightness = 1.0f;
|
||||
float adjustments_contrast = 1.0f;
|
||||
float adjustments_saturation = 1.0f;
|
||||
bool use_1d_color_correction = false;
|
||||
RID color_correction = RID();
|
||||
};
|
||||
|
||||
RS::EnvironmentSSAOQuality ssao_quality = RS::ENV_SSAO_QUALITY_MEDIUM;
|
||||
bool ssao_half_size = false;
|
||||
bool ssao_using_half_size = false;
|
||||
float ssao_adaptive_target = 0.5;
|
||||
int ssao_blur_passes = 2;
|
||||
float ssao_fadeout_from = 50.0;
|
||||
float ssao_fadeout_to = 300.0;
|
||||
|
||||
bool glow_bicubic_upscale = false;
|
||||
bool glow_high_quality = false;
|
||||
RS::EnvironmentSSRRoughnessQuality ssr_roughness_quality = RS::ENV_SSR_ROUGHNESS_QUALITY_LOW;
|
||||
|
||||
static uint64_t auto_exposure_counter;
|
||||
|
||||
mutable RID_Owner<Environment, true> environment_owner;
|
||||
|
||||
/* Sky */
|
||||
|
||||
struct Sky {
|
||||
// Screen Buffers
|
||||
GLuint half_res_pass = 0;
|
||||
GLuint half_res_framebuffer = 0;
|
||||
GLuint quarter_res_pass = 0;
|
||||
GLuint quarter_res_framebuffer = 0;
|
||||
Size2i screen_size = Size2i(0, 0);
|
||||
|
||||
// Radiance Cubemap
|
||||
GLuint radiance = 0;
|
||||
GLuint radiance_framebuffer = 0;
|
||||
|
||||
RID material;
|
||||
RID uniform_buffer;
|
||||
|
||||
int radiance_size = 256;
|
||||
|
||||
RS::SkyMode mode = RS::SKY_MODE_AUTOMATIC;
|
||||
|
||||
//ReflectionData reflection;
|
||||
bool reflection_dirty = false;
|
||||
bool dirty = false;
|
||||
int processing_layer = 0;
|
||||
Sky *dirty_list = nullptr;
|
||||
|
||||
//State to track when radiance cubemap needs updating
|
||||
//SkyMaterialData *prev_material;
|
||||
Vector3 prev_position = Vector3(0.0, 0.0, 0.0);
|
||||
float prev_time = 0.0f;
|
||||
|
||||
void free();
|
||||
bool set_radiance_size(int p_radiance_size);
|
||||
bool set_mode(RS::SkyMode p_mode);
|
||||
bool set_material(RID p_material);
|
||||
Ref<Image> bake_panorama(float p_energy, int p_roughness_layers, const Size2i &p_size);
|
||||
};
|
||||
|
||||
Sky *dirty_sky_list = nullptr;
|
||||
mutable RID_Owner<Sky, true> sky_owner;
|
||||
|
||||
void _invalidate_sky(Sky *p_sky);
|
||||
void _update_dirty_skys();
|
||||
void _draw_sky(Sky *p_sky, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_custom_fov, float p_energy, const Basis &p_sky_orientation);
|
||||
|
||||
public:
|
||||
RasterizerStorageGLES3 *storage;
|
||||
RasterizerCanvasGLES3 *canvas;
|
||||
|
||||
// References to shaders are needed in public space so they can be accessed in RasterizerStorageGLES3
|
||||
struct State {
|
||||
//SceneShaderGLES3 scene_shader;
|
||||
SkyShaderGLES3 sky_shader;
|
||||
} state;
|
||||
|
||||
GeometryInstance *geometry_instance_create(RID p_base) override;
|
||||
@ -88,17 +387,17 @@ public:
|
||||
|
||||
/* SDFGI UPDATE */
|
||||
|
||||
void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) override;
|
||||
int sdfgi_get_pending_region_count(RID p_render_buffers) const override;
|
||||
AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const override;
|
||||
uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const override;
|
||||
void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) override {}
|
||||
int sdfgi_get_pending_region_count(RID p_render_buffers) const override { return 0; }
|
||||
AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const override { return AABB(); }
|
||||
uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const override { return 0; }
|
||||
|
||||
/* SKY API */
|
||||
|
||||
RID sky_allocate() override;
|
||||
void sky_initialize(RID p_rid) override;
|
||||
void sky_set_radiance_size(RID p_sky, int p_radiance_size) override;
|
||||
void sky_set_mode(RID p_sky, RS::SkyMode p_samples) override;
|
||||
void sky_set_mode(RID p_sky, RS::SkyMode p_mode) override;
|
||||
void sky_set_material(RID p_sky, RID p_material) override;
|
||||
Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) override;
|
||||
|
||||
@ -199,9 +498,19 @@ public:
|
||||
void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override;
|
||||
void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) override;
|
||||
|
||||
void set_scene_pass(uint64_t p_pass) override;
|
||||
void set_scene_pass(uint64_t p_pass) override {
|
||||
scene_pass = p_pass;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint64_t get_scene_pass() {
|
||||
return scene_pass;
|
||||
}
|
||||
|
||||
void set_time(double p_time, double p_step) override;
|
||||
void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) override;
|
||||
_FORCE_INLINE_ RS::ViewportDebugDraw get_debug_draw_mode() const {
|
||||
return debug_draw;
|
||||
}
|
||||
|
||||
RID render_buffers_create() override;
|
||||
void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_internal_width, int p_internal_height, int p_width, int p_height, float p_fsr_sharpness, float p_fsr_mipmap_bias, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding, uint32_t p_view_count) override;
|
||||
@ -222,7 +531,9 @@ public:
|
||||
void decals_set_filter(RS::DecalFilter p_filter) override;
|
||||
void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override;
|
||||
|
||||
RasterizerSceneGLES3();
|
||||
static RasterizerSceneGLES3 *get_singleton();
|
||||
RasterizerSceneGLES3(RasterizerStorageGLES3 *p_storage);
|
||||
~RasterizerSceneGLES3();
|
||||
};
|
||||
|
||||
#endif // GLES3_ENABLED
|
||||
|
@ -38,24 +38,6 @@
|
||||
#include "rasterizer_scene_gles3.h"
|
||||
#include "servers/rendering/shader_language.h"
|
||||
|
||||
void RasterizerStorageGLES3::bind_quad_array() const {
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
|
||||
//glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
|
||||
//glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8));
|
||||
|
||||
//glEnableVertexAttribArray(RS::ARRAY_VERTEX);
|
||||
//glEnableVertexAttribArray(RS::ARRAY_TEX_UV);
|
||||
}
|
||||
|
||||
RID RasterizerStorageGLES3::sky_create() {
|
||||
Sky *sky = memnew(Sky);
|
||||
sky->radiance = 0;
|
||||
return sky_owner.make_rid(sky);
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::base_update_dependency(RID p_base, DependencyTracker *p_instance) {
|
||||
}
|
||||
|
||||
@ -236,13 +218,9 @@ RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) {
|
||||
glGenTextures(1, &cls->distance);
|
||||
glBindTexture(GL_TEXTURE_2D, cls->distance);
|
||||
if (config->use_rgba_2d_shadows) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cls->size, cls->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, cls->size, cls->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
} else {
|
||||
#ifdef GLES_OVER_GL
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cls->size, cls->height, 0, _RED_OES, GL_FLOAT, nullptr);
|
||||
#else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_FLOAT, cls->size, cls->height, 0, _RED_OES, GL_FLOAT, NULL);
|
||||
#endif
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, cls->size, cls->height, 0, GL_RED, GL_FLOAT, nullptr);
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
@ -394,13 +372,6 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
|
||||
return true;
|
||||
} else if (GLES3::TextureStorage::get_singleton()->owns_canvas_texture(p_rid)) {
|
||||
GLES3::TextureStorage::get_singleton()->canvas_texture_free(p_rid);
|
||||
return true;
|
||||
} else if (sky_owner.owns(p_rid)) {
|
||||
Sky *sky = sky_owner.get_or_null(p_rid);
|
||||
sky_set_texture(p_rid, RID(), 256);
|
||||
sky_owner.free(p_rid);
|
||||
memdelete(sky);
|
||||
|
||||
return true;
|
||||
} else if (GLES3::MaterialStorage::get_singleton()->owns_shader(p_rid)) {
|
||||
GLES3::MaterialStorage::get_singleton()->shader_free(p_rid);
|
||||
@ -535,16 +506,23 @@ bool RasterizerStorageGLES3::free(RID p_rid) {
|
||||
}
|
||||
|
||||
bool RasterizerStorageGLES3::has_os_feature(const String &p_feature) const {
|
||||
if (p_feature == "rgtc") {
|
||||
return config->rgtc_supported;
|
||||
}
|
||||
|
||||
if (p_feature == "s3tc") {
|
||||
return config->s3tc_supported;
|
||||
}
|
||||
|
||||
if (p_feature == "bptc") {
|
||||
return config->bptc_supported;
|
||||
}
|
||||
if (p_feature == "etc") {
|
||||
return config->etc_supported;
|
||||
}
|
||||
|
||||
if (p_feature == "skinning_fallback") {
|
||||
return config->use_skeleton_software;
|
||||
if (p_feature == "etc2") {
|
||||
return config->etc2_supported;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -652,100 +630,6 @@ RenderingDevice::DeviceType RasterizerStorageGLES3::get_video_adapter_type() con
|
||||
void RasterizerStorageGLES3::initialize() {
|
||||
config = GLES3::Config::get_singleton();
|
||||
|
||||
//picky requirements for these
|
||||
config->support_shadow_cubemaps = config->support_depth_texture && config->support_write_depth && config->support_depth_cubemaps;
|
||||
|
||||
// the use skeleton software path should be used if either float texture is not supported,
|
||||
// OR max_vertex_texture_image_units is zero
|
||||
config->use_skeleton_software = (config->float_texture_supported == false) || (config->max_vertex_texture_image_units == 0);
|
||||
|
||||
{
|
||||
// quad for copying stuff
|
||||
|
||||
glGenBuffers(1, &resources.quadie);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
|
||||
{
|
||||
const float qv[16] = {
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
-1,
|
||||
1,
|
||||
0,
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, qv, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
{
|
||||
//default textures
|
||||
|
||||
glGenTextures(1, &resources.white_tex);
|
||||
unsigned char whitetexdata[8 * 8 * 3];
|
||||
for (int i = 0; i < 8 * 8 * 3; i++) {
|
||||
whitetexdata[i] = 255;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, resources.white_tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glGenTextures(1, &resources.black_tex);
|
||||
unsigned char blacktexdata[8 * 8 * 3];
|
||||
for (int i = 0; i < 8 * 8 * 3; i++) {
|
||||
blacktexdata[i] = 0;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, resources.black_tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, blacktexdata);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glGenTextures(1, &resources.normal_tex);
|
||||
unsigned char normaltexdata[8 * 8 * 3];
|
||||
for (int i = 0; i < 8 * 8 * 3; i += 3) {
|
||||
normaltexdata[i + 0] = 128;
|
||||
normaltexdata[i + 1] = 128;
|
||||
normaltexdata[i + 2] = 255;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, resources.normal_tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, normaltexdata);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glGenTextures(1, &resources.aniso_tex);
|
||||
unsigned char anisotexdata[8 * 8 * 3];
|
||||
for (int i = 0; i < 8 * 8 * 3; i += 3) {
|
||||
anisotexdata[i + 0] = 255;
|
||||
anisotexdata[i + 1] = 128;
|
||||
anisotexdata[i + 2] = 0;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, resources.aniso_tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, anisotexdata);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
// skeleton buffer
|
||||
{
|
||||
resources.skeleton_transform_buffer_size = 0;
|
||||
@ -754,49 +638,41 @@ void RasterizerStorageGLES3::initialize() {
|
||||
|
||||
// radical inverse vdc cache texture
|
||||
// used for cubemap filtering
|
||||
if (true /*||config->float_texture_supported*/) { //uint8 is similar and works everywhere
|
||||
glGenTextures(1, &resources.radical_inverse_vdc_cache_tex);
|
||||
glGenTextures(1, &resources.radical_inverse_vdc_cache_tex);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, resources.radical_inverse_vdc_cache_tex);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, resources.radical_inverse_vdc_cache_tex);
|
||||
/*
|
||||
uint8_t radical_inverse[512];
|
||||
|
||||
uint8_t radical_inverse[512];
|
||||
for (uint32_t i = 0; i < 512; i++) {
|
||||
uint32_t bits = i;
|
||||
|
||||
for (uint32_t i = 0; i < 512; i++) {
|
||||
uint32_t bits = i;
|
||||
bits = (bits << 16) | (bits >> 16);
|
||||
bits = ((bits & 0x55555555) << 1) | ((bits & 0xAAAAAAAA) >> 1);
|
||||
bits = ((bits & 0x33333333) << 2) | ((bits & 0xCCCCCCCC) >> 2);
|
||||
bits = ((bits & 0x0F0F0F0F) << 4) | ((bits & 0xF0F0F0F0) >> 4);
|
||||
bits = ((bits & 0x00FF00FF) << 8) | ((bits & 0xFF00FF00) >> 8);
|
||||
|
||||
bits = (bits << 16) | (bits >> 16);
|
||||
bits = ((bits & 0x55555555) << 1) | ((bits & 0xAAAAAAAA) >> 1);
|
||||
bits = ((bits & 0x33333333) << 2) | ((bits & 0xCCCCCCCC) >> 2);
|
||||
bits = ((bits & 0x0F0F0F0F) << 4) | ((bits & 0xF0F0F0F0) >> 4);
|
||||
bits = ((bits & 0x00FF00FF) << 8) | ((bits & 0xFF00FF00) >> 8);
|
||||
|
||||
float value = float(bits) * 2.3283064365386963e-10;
|
||||
radical_inverse[i] = uint8_t(CLAMP(value * 255.0, 0, 255));
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 512, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, radical_inverse);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //need this for proper sampling
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
float value = float(bits) * 2.3283064365386963e-10;
|
||||
radical_inverse[i] = uint8_t(CLAMP(value * 255.0, 0, 255));
|
||||
}
|
||||
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 512, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, radical_inverse);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //need this for proper sampling
|
||||
*/
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
{
|
||||
glGenFramebuffers(1, &resources.mipmap_blur_fbo);
|
||||
glGenTextures(1, &resources.mipmap_blur_color);
|
||||
}
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
//this needs to be enabled manually in OpenGL 2.1
|
||||
|
||||
if (config->extensions.has("GL_ARB_seamless_cube_map")) {
|
||||
glEnable(_EXT_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
}
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -804,10 +680,8 @@ void RasterizerStorageGLES3::finalize() {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::_copy_screen() {
|
||||
bind_quad_array();
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::update_memory_info() {
|
||||
}
|
||||
|
||||
@ -816,10 +690,8 @@ uint64_t RasterizerStorageGLES3::get_rendering_info(RS::RenderingInfo p_info) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::update_dirty_resources() {
|
||||
GLES3::MaterialStorage::get_singleton()->update_dirty_shaders();
|
||||
GLES3::MaterialStorage::get_singleton()->update_dirty_materials();
|
||||
// update_dirty_skeletons();
|
||||
// update_dirty_multimeshes();
|
||||
GLES3::MaterialStorage::get_singleton()->_update_global_variables();
|
||||
GLES3::MaterialStorage::get_singleton()->_update_queued_materials();
|
||||
}
|
||||
|
||||
RasterizerStorageGLES3::RasterizerStorageGLES3() {
|
||||
|
@ -55,19 +55,12 @@ public:
|
||||
GLES3::Config *config;
|
||||
|
||||
struct Resources {
|
||||
GLuint white_tex;
|
||||
GLuint black_tex;
|
||||
GLuint normal_tex;
|
||||
GLuint aniso_tex;
|
||||
|
||||
GLuint mipmap_blur_fbo;
|
||||
GLuint mipmap_blur_color;
|
||||
|
||||
GLuint radical_inverse_vdc_cache_tex;
|
||||
bool use_rgba_2d_shadows;
|
||||
|
||||
GLuint quadie;
|
||||
|
||||
size_t skeleton_transform_buffer_size;
|
||||
GLuint skeleton_transform_buffer;
|
||||
LocalVector<float> skeleton_transform_cpu_buffer;
|
||||
@ -107,8 +100,6 @@ public:
|
||||
|
||||
} info;
|
||||
|
||||
void bind_quad_array() const;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////API////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -116,20 +107,6 @@ public:
|
||||
public:
|
||||
virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) override;
|
||||
|
||||
/* SKY API */
|
||||
// not sure if used in godot 4?
|
||||
struct Sky {
|
||||
RID self;
|
||||
RID panorama;
|
||||
GLuint radiance;
|
||||
int radiance_size;
|
||||
};
|
||||
|
||||
mutable RID_PtrOwner<Sky> sky_owner;
|
||||
|
||||
RID sky_create();
|
||||
void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size);
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
||||
RID voxel_gi_allocate() override;
|
||||
@ -278,6 +255,9 @@ public:
|
||||
void buffer_orphan_and_upload(unsigned int p_buffer_size, unsigned int p_offset, unsigned int p_data_size, const void *p_data, GLenum p_target = GL_ARRAY_BUFFER, GLenum p_usage = GL_DYNAMIC_DRAW, bool p_optional_orphan = false) const;
|
||||
bool safe_buffer_sub_data(unsigned int p_total_buffer_size, GLenum p_target, unsigned int p_offset, unsigned int p_data_size, const void *p_data, unsigned int &r_offset_after) const;
|
||||
|
||||
//bool validate_framebuffer(); // Validate currently bound framebuffer, does not touch global state
|
||||
String get_framebuffer_error(GLenum p_status);
|
||||
|
||||
RasterizerStorageGLES3();
|
||||
~RasterizerStorageGLES3();
|
||||
};
|
||||
@ -319,6 +299,21 @@ inline void RasterizerStorageGLES3::buffer_orphan_and_upload(unsigned int p_buff
|
||||
glBufferSubData(p_target, p_offset, p_data_size, p_data);
|
||||
}
|
||||
|
||||
inline String RasterizerStorageGLES3::get_framebuffer_error(GLenum p_status) {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (p_status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
||||
} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
||||
} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
|
||||
} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
|
||||
}
|
||||
#endif
|
||||
return itos(p_status);
|
||||
}
|
||||
|
||||
#endif // GLES3_ENABLED
|
||||
|
||||
#endif // RASTERIZER_STORAGE_OPENGL_H
|
||||
|
@ -165,6 +165,7 @@ void ShaderGLES3::_build_variant_code(StringBuilder &builder, uint32_t p_variant
|
||||
builder.append("\n"); //make sure defines begin at newline
|
||||
builder.append(general_defines.get_data());
|
||||
builder.append(variant_defines[p_variant]);
|
||||
builder.append("\n");
|
||||
for (int j = 0; j < p_version->custom_defines.size(); j++) {
|
||||
builder.append(p_version->custom_defines[j].get_data());
|
||||
}
|
||||
@ -327,7 +328,7 @@ void ShaderGLES3::_compile_specialization(Version::Specialization &spec, uint32_
|
||||
glDeleteProgram(spec.id);
|
||||
spec.id = 0;
|
||||
|
||||
ERR_PRINT("No OpenGL program link log. What the frick?");
|
||||
ERR_PRINT("No OpenGL program link log. Something is wrong.");
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
@ -552,9 +553,11 @@ void ShaderGLES3::_clear_version(Version *p_version) {
|
||||
|
||||
for (int i = 0; i < variant_count; i++) {
|
||||
for (OAHashMap<uint64_t, Version::Specialization>::Iterator it = p_version->variants[i].iter(); it.valid; it = p_version->variants[i].next_iter(it)) {
|
||||
glDeleteShader(it.value->vert_id);
|
||||
glDeleteShader(it.value->frag_id);
|
||||
glDeleteProgram(it.value->id);
|
||||
if (it.value->id != 0) {
|
||||
glDeleteShader(it.value->vert_id);
|
||||
glDeleteShader(it.value->frag_id);
|
||||
glDeleteProgram(it.value->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ private:
|
||||
void _clear_version(Version *p_version);
|
||||
void _initialize_version(Version *p_version);
|
||||
|
||||
RID_Owner<Version> version_owner;
|
||||
RID_Owner<Version, true> version_owner;
|
||||
|
||||
struct StageTemplate {
|
||||
struct Chunk {
|
||||
|
@ -5,3 +5,4 @@ Import("env")
|
||||
if "GLES3_GLSL" in env["BUILDERS"]:
|
||||
env.GLES3_GLSL("canvas.glsl")
|
||||
env.GLES3_GLSL("copy.glsl")
|
||||
env.GLES3_GLSL("sky.glsl")
|
||||
|
@ -286,7 +286,7 @@ in vec2 pixel_size_interp;
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
uniform MaterialUniforms{
|
||||
layout(std140) uniform MaterialUniforms{
|
||||
//ubo:4
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
179
drivers/gles3/shaders/sky.glsl
Normal file
179
drivers/gles3/shaders/sky.glsl
Normal file
@ -0,0 +1,179 @@
|
||||
/* clang-format off */
|
||||
#[modes]
|
||||
|
||||
mode_background =
|
||||
mode_half_res = #define USE_HALF_RES_PASS
|
||||
mode_quarter_res = #define USE_QUARTER_RES_PASS
|
||||
mode_cubemap = #define USE_CUBEMAP_PASS
|
||||
mode_cubemap_half_res = #define USE_CUBEMAP_PASS \n#define USE_HALF_RES_PASS
|
||||
mode_cubemap_quarter_res = #define USE_CUBEMAP_PASS \n#define USE_QUARTER_RES_PASS
|
||||
|
||||
#[specializations]
|
||||
|
||||
#[vertex]
|
||||
|
||||
#ifdef USE_GLES_OVER_GL
|
||||
#define lowp
|
||||
#define mediump
|
||||
#define highp
|
||||
#else
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
#endif
|
||||
|
||||
out vec2 uv_interp;
|
||||
/* clang-format on */
|
||||
|
||||
void main() {
|
||||
// One big triangle to cover the whole screen
|
||||
vec2 base_arr[3] = vec2[](vec2(-1.0, -2.0), vec2(-1.0, 2.0), vec2(2.0, 2.0));
|
||||
uv_interp = base_arr[gl_VertexID];
|
||||
gl_Position = vec4(uv_interp, 1.0, 1.0);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
#[fragment]
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
|
||||
#ifdef USE_GLES_OVER_GL
|
||||
#define lowp
|
||||
#define mediump
|
||||
#define highp
|
||||
#else
|
||||
#if defined(USE_HIGHP_PRECISION)
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
#else
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
in vec2 uv_interp;
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
uniform samplerCube radiance; //texunit:-1
|
||||
#ifdef USE_CUBEMAP_PASS
|
||||
uniform samplerCube half_res; //texunit:-2
|
||||
uniform samplerCube quarter_res; //texunit:-3
|
||||
#else
|
||||
uniform sampler2D half_res; //texunit:-2
|
||||
uniform sampler2D quarter_res; //texunit:-3
|
||||
#endif
|
||||
|
||||
layout(std140) uniform CanvasData { //ubo:0
|
||||
mat3 orientation;
|
||||
vec4 projection;
|
||||
vec4 position_multiplier;
|
||||
float time;
|
||||
float luminance_multiplier;
|
||||
float pad1;
|
||||
float pad2;
|
||||
};
|
||||
|
||||
layout(std140) uniform GlobalVariableData { //ubo:1
|
||||
vec4 global_variables[MAX_GLOBAL_VARIABLES];
|
||||
};
|
||||
|
||||
struct DirectionalLightData {
|
||||
vec4 direction_energy;
|
||||
vec4 color_size;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
layout(std140) uniform DirectionalLights { //ubo:2
|
||||
DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
|
||||
}
|
||||
directional_lights;
|
||||
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(std140) uniform MaterialUniforms{
|
||||
//ubo:3
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
||||
} material;
|
||||
#endif
|
||||
|
||||
#GLOBALS
|
||||
|
||||
#ifdef USE_CUBEMAP_PASS
|
||||
#define AT_CUBEMAP_PASS true
|
||||
#else
|
||||
#define AT_CUBEMAP_PASS false
|
||||
#endif
|
||||
|
||||
#ifdef USE_HALF_RES_PASS
|
||||
#define AT_HALF_RES_PASS true
|
||||
#else
|
||||
#define AT_HALF_RES_PASS false
|
||||
#endif
|
||||
|
||||
#ifdef USE_QUARTER_RES_PASS
|
||||
#define AT_QUARTER_RES_PASS true
|
||||
#else
|
||||
#define AT_QUARTER_RES_PASS false
|
||||
#endif
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
vec3 cube_normal;
|
||||
cube_normal.z = -1.0;
|
||||
cube_normal.x = (uv_interp.x + projection.x) / projection.y;
|
||||
cube_normal.y = (-uv_interp.y - projection.z) / projection.w;
|
||||
cube_normal = mat3(orientation) * cube_normal;
|
||||
cube_normal.z = -cube_normal.z;
|
||||
cube_normal = normalize(cube_normal);
|
||||
|
||||
vec2 uv = uv_interp * 0.5 + 0.5;
|
||||
|
||||
vec2 panorama_coords = vec2(atan(cube_normal.x, cube_normal.z), acos(cube_normal.y));
|
||||
|
||||
if (panorama_coords.x < 0.0) {
|
||||
panorama_coords.x += M_PI * 2.0;
|
||||
}
|
||||
|
||||
panorama_coords /= vec2(M_PI * 2.0, M_PI);
|
||||
|
||||
vec3 color = vec3(0.0, 0.0, 0.0);
|
||||
float alpha = 1.0; // Only available to subpasses
|
||||
vec4 half_res_color = vec4(1.0);
|
||||
vec4 quarter_res_color = vec4(1.0);
|
||||
vec4 custom_fog = vec4(0.0);
|
||||
|
||||
#ifdef USE_CUBEMAP_PASS
|
||||
vec3 inverted_cube_normal = cube_normal;
|
||||
inverted_cube_normal.z *= -1.0;
|
||||
#ifdef USES_HALF_RES_COLOR
|
||||
half_res_color = texture(samplerCube(half_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), inverted_cube_normal) * luminance_multiplier;
|
||||
#endif
|
||||
#ifdef USES_QUARTER_RES_COLOR
|
||||
quarter_res_color = texture(samplerCube(quarter_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), inverted_cube_normal) * luminance_multiplier;
|
||||
#endif
|
||||
#else
|
||||
#ifdef USES_HALF_RES_COLOR
|
||||
half_res_color = textureLod(sampler2D(half_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) * luminance_multiplier;
|
||||
#endif
|
||||
#ifdef USES_QUARTER_RES_COLOR
|
||||
quarter_res_color = textureLod(sampler2D(quarter_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) * luminance_multiplier;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
{
|
||||
|
||||
#CODE : SKY
|
||||
|
||||
}
|
||||
|
||||
frag_color.rgb = color * position_multiplier.w / luminance_multiplier;
|
||||
frag_color.a = alpha;
|
||||
|
||||
// Blending is disabled for Sky, so alpha doesn't blend
|
||||
// alpha is used for subsurface scattering so make sure it doesn't get applied to Sky
|
||||
if (!AT_CUBEMAP_PASS && !AT_HALF_RES_PASS && !AT_QUARTER_RES_PASS) {
|
||||
frag_color.a = 0.0;
|
||||
}
|
||||
}
|
@ -31,40 +31,50 @@
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "config.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/templates/vector.h"
|
||||
|
||||
using namespace GLES3;
|
||||
|
||||
#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
|
||||
Config *Config::singleton = nullptr;
|
||||
|
||||
Config::Config() {
|
||||
singleton = this;
|
||||
|
||||
{
|
||||
const GLubyte *extension_string = glGetString(GL_EXTENSIONS);
|
||||
|
||||
Vector<String> exts = String((const char *)extension_string).split(" ");
|
||||
|
||||
for (int i = 0; i < exts.size(); i++) {
|
||||
extensions.insert(exts[i]);
|
||||
int max_extensions = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &max_extensions);
|
||||
for (int i = 0; i < max_extensions; i++) {
|
||||
const GLubyte *s = glGetStringi(GL_EXTENSIONS, i);
|
||||
if (!s) {
|
||||
break;
|
||||
}
|
||||
extensions.insert((const char *)s);
|
||||
}
|
||||
}
|
||||
|
||||
keep_original_textures = true; // false
|
||||
shrink_textures_x2 = false;
|
||||
depth_internalformat = GL_DEPTH_COMPONENT;
|
||||
depth_type = GL_UNSIGNED_INT;
|
||||
|
||||
srgb_decode_supported = extensions.has("GL_EXT_texture_sRGB_decode");
|
||||
etc2_supported = true;
|
||||
#ifdef GLES_OVER_GL
|
||||
float_texture_supported = true;
|
||||
s3tc_supported = true;
|
||||
etc_supported = false;
|
||||
etc_supported = false; // extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
|
||||
bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("EXT_texture_compression_bptc");
|
||||
rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
|
||||
support_npot_repeat_mipmap = true;
|
||||
depth_buffer_internalformat = GL_DEPTH_COMPONENT24;
|
||||
#else
|
||||
float_texture_supported = extensions.has("GL_ARB_texture_float") || extensions.has("GL_OES_texture_float");
|
||||
s3tc_supported = extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc");
|
||||
etc_supported = extensions.has("GL_OES_compressed_ETC1_RGB8_texture") || extensions.has("WEBGL_compressed_texture_etc1");
|
||||
bptc_supported = false;
|
||||
rgtc_supported = false;
|
||||
support_npot_repeat_mipmap = extensions.has("GL_OES_texture_npot");
|
||||
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
@ -86,23 +96,13 @@ Config::Config() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
//TODO: causes huge problems with desktop video drivers. Making false for now, needs to be true to render SCREEN_TEXTURE mipmaps
|
||||
render_to_mipmap_supported = false;
|
||||
#else
|
||||
//check if mipmaps can be used for SCREEN_TEXTURE and Glow on Mobile and web platforms
|
||||
render_to_mipmap_supported = extensions.has("GL_OES_fbo_render_mipmap") && extensions.has("GL_EXT_texture_lod");
|
||||
#endif
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
use_rgba_2d_shadows = false;
|
||||
support_depth_texture = true;
|
||||
use_rgba_3d_shadows = false;
|
||||
support_depth_cubemaps = true;
|
||||
#else
|
||||
use_rgba_2d_shadows = !(float_texture_supported && extensions.has("GL_EXT_texture_rg"));
|
||||
support_depth_texture = extensions.has("GL_OES_depth_texture") || extensions.has("WEBGL_depth_texture");
|
||||
use_rgba_3d_shadows = !support_depth_texture;
|
||||
use_rgba_3d_shadows = false;
|
||||
support_depth_cubemaps = extensions.has("GL_OES_depth_texture_cube_map");
|
||||
#endif
|
||||
|
||||
@ -130,20 +130,25 @@ Config::Config() {
|
||||
support_half_float_vertices = false;
|
||||
}
|
||||
|
||||
etc_supported = extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
|
||||
latc_supported = extensions.has("GL_EXT_texture_compression_latc");
|
||||
bptc_supported = extensions.has("GL_ARB_texture_compression_bptc");
|
||||
rgtc_supported = extensions.has("GL_EXT_texture_compression_rgtc") || extensions.has("GL_ARB_texture_compression_rgtc") || extensions.has("EXT_texture_compression_rgtc");
|
||||
bptc_supported = extensions.has("GL_ARB_texture_compression_bptc") || extensions.has("EXT_texture_compression_bptc");
|
||||
srgb_decode_supported = extensions.has("GL_EXT_texture_sRGB_decode");
|
||||
//picky requirements for these
|
||||
support_shadow_cubemaps = support_write_depth && support_depth_cubemaps;
|
||||
// the use skeleton software path should be used if either float texture is not supported,
|
||||
// OR max_vertex_texture_image_units is zero
|
||||
use_skeleton_software = (float_texture_supported == false) || (max_vertex_texture_image_units == 0);
|
||||
|
||||
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max_vertex_texture_image_units);
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
|
||||
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_uniform_buffer_size);
|
||||
|
||||
support_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic");
|
||||
if (support_anisotropic_filter) {
|
||||
glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_level);
|
||||
anisotropic_level = MIN(float(1 << int(ProjectSettings::get_singleton()->get("rendering/textures/default_filters/anisotropic_filtering_level"))), anisotropic_level);
|
||||
}
|
||||
|
||||
force_vertex_shading = false; //GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
|
||||
use_fast_texture_filter = false; //GLOBAL_GET("rendering/quality/filters/use_nearest_mipmap_filter");
|
||||
// should_orphan = GLOBAL_GET("rendering/options/api_usage_legacy/orphan_buffers");
|
||||
use_nearest_mip_filter = GLOBAL_GET("rendering/textures/default_filters/use_nearest_mipmap_filter");
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
|
@ -51,13 +51,13 @@ private:
|
||||
static Config *singleton;
|
||||
|
||||
public:
|
||||
bool shrink_textures_x2;
|
||||
bool use_fast_texture_filter;
|
||||
bool use_nearest_mip_filter;
|
||||
bool use_skeleton_software;
|
||||
|
||||
int max_vertex_texture_image_units;
|
||||
int max_texture_image_units;
|
||||
int max_texture_size;
|
||||
int max_uniform_buffer_size;
|
||||
|
||||
// TODO implement wireframe in OpenGL
|
||||
// bool generate_wireframes;
|
||||
@ -84,12 +84,10 @@ public:
|
||||
bool support_write_depth;
|
||||
bool support_half_float_vertices;
|
||||
bool support_npot_repeat_mipmap;
|
||||
bool support_depth_texture;
|
||||
bool support_depth_cubemaps;
|
||||
|
||||
bool support_shadow_cubemaps;
|
||||
|
||||
bool render_to_mipmap_supported;
|
||||
bool support_anisotropic_filter;
|
||||
float anisotropic_level;
|
||||
|
||||
GLuint depth_internalformat;
|
||||
GLuint depth_type;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -44,193 +44,246 @@
|
||||
|
||||
#include "drivers/gles3/shaders/copy.glsl.gen.h"
|
||||
|
||||
#include "../shaders/canvas.glsl.gen.h"
|
||||
#include "../shaders/sky.glsl.gen.h"
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
/* SHADER Structs */
|
||||
|
||||
struct Shaders {
|
||||
ShaderCompiler compiler;
|
||||
CanvasShaderGLES3 canvas_shader;
|
||||
SkyShaderGLES3 sky_shader;
|
||||
|
||||
CopyShaderGLES3 copy;
|
||||
RID copy_version;
|
||||
//CubemapFilterShaderGLES3 cubemap_filter;
|
||||
|
||||
ShaderCompiler::IdentifierActions actions_canvas;
|
||||
ShaderCompiler::IdentifierActions actions_scene;
|
||||
ShaderCompiler::IdentifierActions actions_particles;
|
||||
ShaderCompiler compiler_canvas;
|
||||
ShaderCompiler compiler_scene;
|
||||
ShaderCompiler compiler_particles;
|
||||
ShaderCompiler compiler_sky;
|
||||
};
|
||||
|
||||
struct ShaderData {
|
||||
virtual void set_code(const String &p_Code) = 0;
|
||||
virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index) = 0;
|
||||
virtual void get_param_list(List<PropertyInfo> *p_param_list) const = 0;
|
||||
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const = 0;
|
||||
virtual bool is_param_texture(const StringName &p_param) const = 0;
|
||||
virtual bool is_animated() const = 0;
|
||||
virtual bool casts_shadows() const = 0;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const = 0;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const { return RS::ShaderNativeSourceCode(); }
|
||||
|
||||
virtual ~ShaderData() {}
|
||||
};
|
||||
|
||||
typedef ShaderData *(*ShaderDataRequestFunction)();
|
||||
|
||||
struct Material;
|
||||
|
||||
struct Shader {
|
||||
RID self;
|
||||
|
||||
RS::ShaderMode mode;
|
||||
ShaderGLES3 *shader = nullptr;
|
||||
ShaderData *data = nullptr;
|
||||
String code;
|
||||
SelfList<Material>::List materials;
|
||||
|
||||
Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
|
||||
RID version;
|
||||
|
||||
SelfList<Shader> dirty_list;
|
||||
|
||||
Map<StringName, Map<int, RID>> default_textures;
|
||||
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
bool valid;
|
||||
|
||||
String path;
|
||||
|
||||
uint32_t index;
|
||||
uint64_t last_pass;
|
||||
|
||||
struct CanvasItem {
|
||||
enum BlendMode {
|
||||
BLEND_MODE_MIX,
|
||||
BLEND_MODE_ADD,
|
||||
BLEND_MODE_SUB,
|
||||
BLEND_MODE_MUL,
|
||||
BLEND_MODE_PMALPHA,
|
||||
};
|
||||
|
||||
int blend_mode;
|
||||
|
||||
enum LightMode {
|
||||
LIGHT_MODE_NORMAL,
|
||||
LIGHT_MODE_UNSHADED,
|
||||
LIGHT_MODE_LIGHT_ONLY
|
||||
};
|
||||
|
||||
int light_mode;
|
||||
|
||||
bool uses_screen_texture;
|
||||
bool uses_screen_uv;
|
||||
bool uses_time;
|
||||
bool uses_modulate;
|
||||
bool uses_color;
|
||||
bool uses_vertex;
|
||||
|
||||
// all these should disable item joining if used in a custom shader
|
||||
bool uses_model_matrix;
|
||||
bool uses_extra_matrix;
|
||||
bool uses_projection_matrix;
|
||||
bool uses_instance_custom;
|
||||
|
||||
} canvas_item;
|
||||
|
||||
struct Spatial {
|
||||
enum BlendMode {
|
||||
BLEND_MODE_MIX,
|
||||
BLEND_MODE_ADD,
|
||||
BLEND_MODE_SUB,
|
||||
BLEND_MODE_MUL,
|
||||
};
|
||||
|
||||
int blend_mode;
|
||||
|
||||
enum DepthDrawMode {
|
||||
DEPTH_DRAW_OPAQUE,
|
||||
DEPTH_DRAW_ALWAYS,
|
||||
DEPTH_DRAW_NEVER,
|
||||
DEPTH_DRAW_ALPHA_PREPASS,
|
||||
};
|
||||
|
||||
int depth_draw_mode;
|
||||
|
||||
enum CullMode {
|
||||
CULL_MODE_FRONT,
|
||||
CULL_MODE_BACK,
|
||||
CULL_MODE_DISABLED,
|
||||
};
|
||||
|
||||
int cull_mode;
|
||||
|
||||
bool uses_alpha;
|
||||
bool uses_alpha_scissor;
|
||||
bool unshaded;
|
||||
bool no_depth_test;
|
||||
bool uses_vertex;
|
||||
bool uses_discard;
|
||||
bool uses_sss;
|
||||
bool uses_screen_texture;
|
||||
bool uses_depth_texture;
|
||||
bool uses_time;
|
||||
bool uses_tangent;
|
||||
bool uses_ensure_correct_normals;
|
||||
bool writes_modelview_or_projection;
|
||||
bool uses_vertex_lighting;
|
||||
bool uses_world_coordinates;
|
||||
|
||||
} spatial;
|
||||
|
||||
struct Particles {
|
||||
} particles;
|
||||
|
||||
bool uses_vertex_time;
|
||||
bool uses_fragment_time;
|
||||
|
||||
Shader() :
|
||||
dirty_list(this) {
|
||||
shader = nullptr;
|
||||
valid = false;
|
||||
version = RID();
|
||||
last_pass = 0;
|
||||
}
|
||||
RS::ShaderMode mode;
|
||||
Map<StringName, Map<int, RID>> default_texture_parameter;
|
||||
Set<Material *> owners;
|
||||
};
|
||||
|
||||
/* MATERIAL Structs */
|
||||
/* Material structs */
|
||||
|
||||
struct MaterialData {
|
||||
void update_uniform_buffer(const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Map<StringName, Variant> &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color);
|
||||
void update_textures(const Map<StringName, Variant> &p_parameters, const Map<StringName, Map<int, RID>> &p_default_textures, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, RID *p_textures, bool p_use_linear_color);
|
||||
|
||||
virtual void set_render_priority(int p_priority) = 0;
|
||||
virtual void set_next_pass(RID p_pass) = 0;
|
||||
virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) = 0;
|
||||
virtual void bind_uniforms() = 0;
|
||||
virtual ~MaterialData();
|
||||
|
||||
// Used internally by all Materials
|
||||
void update_parameters_internal(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const Map<StringName, ShaderLanguage::ShaderNode::Uniform> &p_uniforms, const uint32_t *p_uniform_offsets, const Vector<ShaderCompiler::GeneratedCode::Texture> &p_texture_uniforms, const Map<StringName, Map<int, RID>> &p_default_texture_params, uint32_t p_ubo_size);
|
||||
|
||||
protected:
|
||||
Vector<uint8_t> ubo_data;
|
||||
GLuint uniform_buffer = GLuint(0);
|
||||
Vector<RID> texture_cache;
|
||||
|
||||
private:
|
||||
friend class MaterialStorage;
|
||||
RID self;
|
||||
List<RID>::Element *global_buffer_E = nullptr;
|
||||
List<RID>::Element *global_texture_E = nullptr;
|
||||
uint64_t global_textures_pass = 0;
|
||||
Map<StringName, uint64_t> used_global_textures;
|
||||
|
||||
//internally by update_parameters_internal
|
||||
};
|
||||
|
||||
typedef MaterialData *(*MaterialDataRequestFunction)(ShaderData *);
|
||||
|
||||
struct Material {
|
||||
RID self;
|
||||
MaterialData *data = nullptr;
|
||||
Shader *shader = nullptr;
|
||||
//shortcut to shader data and type
|
||||
RS::ShaderMode shader_mode = RS::SHADER_MAX;
|
||||
uint32_t shader_id = 0;
|
||||
bool uniform_dirty = false;
|
||||
bool texture_dirty = false;
|
||||
Map<StringName, Variant> params;
|
||||
SelfList<Material> list;
|
||||
SelfList<Material> dirty_list;
|
||||
Vector<Pair<StringName, RID>> textures;
|
||||
float line_width;
|
||||
int render_priority;
|
||||
|
||||
int32_t priority = 0;
|
||||
RID next_pass;
|
||||
SelfList<Material> update_element;
|
||||
|
||||
uint32_t index;
|
||||
uint64_t last_pass;
|
||||
|
||||
// Map<Geometry *, int> geometry_owners;
|
||||
// Map<InstanceBaseDependency *, int> instance_owners;
|
||||
|
||||
bool can_cast_shadow_cache;
|
||||
bool is_animated_cache;
|
||||
RendererStorage::Dependency dependency;
|
||||
|
||||
Material() :
|
||||
list(this),
|
||||
dirty_list(this) {
|
||||
can_cast_shadow_cache = false;
|
||||
is_animated_cache = false;
|
||||
shader = nullptr;
|
||||
line_width = 1.0;
|
||||
last_pass = 0;
|
||||
render_priority = 0;
|
||||
}
|
||||
update_element(this) {}
|
||||
};
|
||||
|
||||
// CanvasItem Materials
|
||||
|
||||
struct CanvasShaderData : public ShaderData {
|
||||
enum BlendMode { //used internally
|
||||
BLEND_MODE_MIX,
|
||||
BLEND_MODE_ADD,
|
||||
BLEND_MODE_SUB,
|
||||
BLEND_MODE_MUL,
|
||||
BLEND_MODE_PMALPHA,
|
||||
BLEND_MODE_DISABLED,
|
||||
};
|
||||
|
||||
bool valid;
|
||||
RID version;
|
||||
//PipelineVariants pipeline_variants;
|
||||
String path;
|
||||
|
||||
Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size;
|
||||
|
||||
String code;
|
||||
Map<StringName, Map<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_screen_texture = false;
|
||||
bool uses_sdf = false;
|
||||
bool uses_time = false;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
|
||||
virtual bool is_param_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
CanvasShaderData();
|
||||
virtual ~CanvasShaderData();
|
||||
};
|
||||
|
||||
ShaderData *_create_canvas_shader_func();
|
||||
|
||||
struct CanvasMaterialData : public MaterialData {
|
||||
CanvasShaderData *shader_data = nullptr;
|
||||
|
||||
virtual void set_render_priority(int p_priority) {}
|
||||
virtual void set_next_pass(RID p_pass) {}
|
||||
virtual void update_parameters(const Map<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty);
|
||||
virtual void bind_uniforms();
|
||||
virtual ~CanvasMaterialData();
|
||||
};
|
||||
|
||||
MaterialData *_create_canvas_material_func(ShaderData *p_shader);
|
||||
|
||||
/* Global variable structs */
|
||||
struct GlobalVariables {
|
||||
enum {
|
||||
BUFFER_DIRTY_REGION_SIZE = 1024
|
||||
};
|
||||
struct Variable {
|
||||
Set<RID> texture_materials; // materials using this
|
||||
|
||||
RS::GlobalVariableType type;
|
||||
Variant value;
|
||||
Variant override;
|
||||
int32_t buffer_index; //for vectors
|
||||
int32_t buffer_elements; //for vectors
|
||||
};
|
||||
|
||||
HashMap<StringName, Variable> variables;
|
||||
|
||||
struct Value {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
};
|
||||
|
||||
struct ValueInt {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t z;
|
||||
int32_t w;
|
||||
};
|
||||
|
||||
struct ValueUInt {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
uint32_t z;
|
||||
uint32_t w;
|
||||
};
|
||||
|
||||
struct ValueUsage {
|
||||
uint32_t elements = 0;
|
||||
};
|
||||
|
||||
List<RID> materials_using_buffer;
|
||||
List<RID> materials_using_texture;
|
||||
|
||||
GLuint buffer = GLuint(0);
|
||||
Value *buffer_values = nullptr;
|
||||
ValueUsage *buffer_usage = nullptr;
|
||||
bool *buffer_dirty_regions = nullptr;
|
||||
uint32_t buffer_dirty_region_count = 0;
|
||||
|
||||
uint32_t buffer_size;
|
||||
|
||||
bool must_update_texture_materials = false;
|
||||
bool must_update_buffer_materials = false;
|
||||
|
||||
HashMap<RID, int32_t> instance_buffer_pos;
|
||||
};
|
||||
|
||||
class MaterialStorage : public RendererMaterialStorage {
|
||||
private:
|
||||
friend struct MaterialData;
|
||||
static MaterialStorage *singleton;
|
||||
|
||||
/* GLOBAL VARIABLE API */
|
||||
|
||||
GlobalVariables global_variables;
|
||||
|
||||
int32_t _global_variable_allocate(uint32_t p_elements);
|
||||
void _global_variable_store_in_buffer(int32_t p_index, RS::GlobalVariableType p_type, const Variant &p_value);
|
||||
void _global_variable_mark_buffer_dirty(int32_t p_index, int32_t p_elements);
|
||||
|
||||
/* SHADER API */
|
||||
|
||||
mutable Shaders shaders;
|
||||
|
||||
mutable RID_PtrOwner<Shader> shader_owner;
|
||||
mutable SelfList<Shader>::List _shader_dirty_list;
|
||||
ShaderDataRequestFunction shader_data_request_func[RS::SHADER_MAX];
|
||||
mutable RID_Owner<Shader, true> shader_owner;
|
||||
|
||||
/* MATERIAL API */
|
||||
MaterialDataRequestFunction material_data_request_func[RS::SHADER_MAX];
|
||||
mutable RID_Owner<Material, true> material_owner;
|
||||
|
||||
mutable SelfList<Material>::List _material_dirty_list;
|
||||
mutable RID_PtrOwner<Material> material_owner;
|
||||
SelfList<Material>::List material_update_list;
|
||||
|
||||
//static void _material_uniform_set_erased(void *p_material);
|
||||
|
||||
public:
|
||||
static MaterialStorage *get_singleton();
|
||||
@ -238,8 +291,12 @@ public:
|
||||
MaterialStorage();
|
||||
virtual ~MaterialStorage();
|
||||
|
||||
Shaders shaders;
|
||||
|
||||
/* GLOBAL VARIABLE API */
|
||||
|
||||
void _update_global_variables();
|
||||
|
||||
virtual void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value) override;
|
||||
virtual void global_variable_remove(const StringName &p_name) override;
|
||||
virtual Vector<StringName> global_variable_get_list() const override;
|
||||
@ -248,6 +305,7 @@ public:
|
||||
virtual void global_variable_set_override(const StringName &p_name, const Variant &p_value) override;
|
||||
virtual Variant global_variable_get(const StringName &p_name) const override;
|
||||
virtual RS::GlobalVariableType global_variable_get_type(const StringName &p_name) const override;
|
||||
RS::GlobalVariableType global_variable_get_type_internal(const StringName &p_name) const;
|
||||
|
||||
virtual void global_variables_load_settings(bool p_load_textures = true) override;
|
||||
virtual void global_variables_clear() override;
|
||||
@ -256,6 +314,8 @@ public:
|
||||
virtual void global_variables_instance_free(RID p_instance) override;
|
||||
virtual void global_variables_instance_update(RID p_instance, int p_index, const Variant &p_value) override;
|
||||
|
||||
GLuint global_variables_get_uniform_buffer() const;
|
||||
|
||||
/* SHADER API */
|
||||
|
||||
Shader *get_shader(RID p_rid) { return shader_owner.get_or_null(p_rid); };
|
||||
@ -267,68 +327,56 @@ public:
|
||||
virtual void shader_initialize(RID p_rid) override;
|
||||
virtual void shader_free(RID p_rid) override;
|
||||
|
||||
//RID shader_create() override;
|
||||
|
||||
virtual void shader_set_code(RID p_shader, const String &p_code) override;
|
||||
virtual String shader_get_code(RID p_shader) const override;
|
||||
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override;
|
||||
|
||||
virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) override;
|
||||
virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const override;
|
||||
virtual Variant shader_get_param_default(RID p_shader, const StringName &p_param) const override;
|
||||
|
||||
virtual RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override { return RS::ShaderNativeSourceCode(); };
|
||||
|
||||
void _update_shader(Shader *p_shader) const;
|
||||
void update_dirty_shaders();
|
||||
|
||||
// new
|
||||
Variant shader_get_param_default(RID p_material, const StringName &p_param) const override { return Variant(); }
|
||||
virtual RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override;
|
||||
|
||||
/* MATERIAL API */
|
||||
|
||||
Material *get_material(RID p_rid) { return material_owner.get_or_null(p_rid); };
|
||||
bool owns_material(RID p_rid) { return material_owner.owns(p_rid); };
|
||||
|
||||
void _material_make_dirty(Material *p_material) const;
|
||||
void _material_queue_update(Material *material, bool p_uniform, bool p_texture);
|
||||
void _update_queued_materials();
|
||||
|
||||
// void _material_add_geometry(RID p_material, Geometry *p_geometry);
|
||||
// void _material_remove_geometry(RID p_material, Geometry *p_geometry);
|
||||
|
||||
void _update_material(Material *p_material);
|
||||
|
||||
// new
|
||||
virtual void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) override {}
|
||||
virtual void material_update_dependency(RID p_material, RendererStorage::DependencyTracker *p_instance) override {}
|
||||
|
||||
// old
|
||||
virtual RID material_allocate() override;
|
||||
virtual void material_initialize(RID p_rid) override;
|
||||
|
||||
virtual void material_free(RID p_rid) override;
|
||||
|
||||
//RID material_create() override;
|
||||
|
||||
virtual void material_set_shader(RID p_material, RID p_shader) override;
|
||||
virtual RID material_get_shader(RID p_material) const;
|
||||
|
||||
virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) override;
|
||||
virtual Variant material_get_param(RID p_material, const StringName &p_param) const override;
|
||||
virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const;
|
||||
|
||||
void material_set_line_width(RID p_material, float p_width);
|
||||
virtual void material_set_next_pass(RID p_material, RID p_next_material) override;
|
||||
virtual void material_set_render_priority(RID p_material, int priority) override;
|
||||
|
||||
virtual bool material_is_animated(RID p_material) override;
|
||||
virtual bool material_casts_shadows(RID p_material) override;
|
||||
bool material_uses_tangents(RID p_material);
|
||||
bool material_uses_ensure_correct_normals(RID p_material);
|
||||
|
||||
void material_add_instance_owner(RID p_material, RendererStorage::DependencyTracker *p_instance);
|
||||
void material_remove_instance_owner(RID p_material, RendererStorage::DependencyTracker *p_instance);
|
||||
virtual void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) override;
|
||||
|
||||
void material_set_render_priority(RID p_material, int priority) override;
|
||||
virtual void material_update_dependency(RID p_material, RendererStorage::DependencyTracker *p_instance) override;
|
||||
|
||||
void update_dirty_materials();
|
||||
_FORCE_INLINE_ uint32_t material_get_shader_id(RID p_material) {
|
||||
Material *material = material_owner.get_or_null(p_material);
|
||||
return material->shader_id;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ MaterialData *material_get_data(RID p_material, RS::ShaderMode p_shader_mode) {
|
||||
Material *material = material_owner.get_or_null(p_material);
|
||||
if (!material || material->shader_mode != p_shader_mode) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return material->data;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace GLES3
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -49,6 +49,9 @@
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
|
||||
#define _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#define _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
@ -86,15 +89,20 @@ namespace GLES3 {
|
||||
#define glClearDepth glClearDepthf
|
||||
#endif //!GLES_OVER_GL
|
||||
|
||||
enum OpenGLTextureFlags {
|
||||
TEXTURE_FLAG_MIPMAPS = 1, /// Enable automatic mipmap generation - when available
|
||||
TEXTURE_FLAG_REPEAT = 2, /// Repeat texture (Tiling), otherwise Clamping
|
||||
TEXTURE_FLAG_FILTER = 4, /// Create texture with linear (or available) filter
|
||||
TEXTURE_FLAG_ANISOTROPIC_FILTER = 8,
|
||||
TEXTURE_FLAG_CONVERT_TO_LINEAR = 16,
|
||||
TEXTURE_FLAG_MIRRORED_REPEAT = 32, /// Repeat texture, with alternate sections mirrored
|
||||
TEXTURE_FLAG_USED_FOR_STREAMING = 2048,
|
||||
TEXTURE_FLAGS_DEFAULT = TEXTURE_FLAG_REPEAT | TEXTURE_FLAG_MIPMAPS | TEXTURE_FLAG_FILTER
|
||||
enum DefaultGLTexture {
|
||||
DEFAULT_GL_TEXTURE_WHITE,
|
||||
DEFAULT_GL_TEXTURE_BLACK,
|
||||
DEFAULT_GL_TEXTURE_NORMAL,
|
||||
DEFAULT_GL_TEXTURE_ANISO,
|
||||
DEFAULT_GL_TEXTURE_DEPTH,
|
||||
DEFAULT_GL_TEXTURE_CUBEMAP_BLACK,
|
||||
//DEFAULT_GL_TEXTURE_CUBEMAP_ARRAY_BLACK, // Cubemap Arrays not supported in GL 3.3 or GL ES 3.0
|
||||
DEFAULT_GL_TEXTURE_CUBEMAP_WHITE,
|
||||
DEFAULT_GL_TEXTURE_3D_WHITE,
|
||||
DEFAULT_GL_TEXTURE_3D_BLACK,
|
||||
DEFAULT_GL_TEXTURE_2D_ARRAY_WHITE,
|
||||
DEFAULT_GL_TEXTURE_2D_UINT,
|
||||
DEFAULT_GL_TEXTURE_MAX
|
||||
};
|
||||
|
||||
struct CanvasTexture {
|
||||
@ -118,99 +126,81 @@ struct RenderTarget;
|
||||
struct Texture {
|
||||
RID self;
|
||||
|
||||
Texture *proxy = nullptr;
|
||||
Set<Texture *> proxy_owners;
|
||||
bool is_proxy = false;
|
||||
bool is_render_target = false;
|
||||
|
||||
RID proxy_to = RID();
|
||||
Vector<RID> proxies;
|
||||
|
||||
String path;
|
||||
uint32_t flags;
|
||||
int width, height, depth;
|
||||
int alloc_width, alloc_height;
|
||||
Image::Format format;
|
||||
RenderingDevice::TextureType type;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int depth = 0;
|
||||
int mipmaps = 1;
|
||||
int layers = 1;
|
||||
int alloc_width = 0;
|
||||
int alloc_height = 0;
|
||||
Image::Format format = Image::FORMAT_R8;
|
||||
|
||||
GLenum target;
|
||||
GLenum gl_format_cache;
|
||||
GLenum gl_internal_format_cache;
|
||||
GLenum gl_type_cache;
|
||||
enum Type {
|
||||
TYPE_2D,
|
||||
TYPE_LAYERED,
|
||||
TYPE_3D
|
||||
};
|
||||
|
||||
int data_size;
|
||||
int total_data_size;
|
||||
bool ignore_mipmaps;
|
||||
Type type;
|
||||
RS::TextureLayeredType layered_type = RS::TEXTURE_LAYERED_2D_ARRAY;
|
||||
|
||||
bool compressed;
|
||||
GLenum target = GL_TEXTURE_2D;
|
||||
GLenum gl_format_cache = 0;
|
||||
GLenum gl_internal_format_cache = 0;
|
||||
GLenum gl_type_cache = 0;
|
||||
|
||||
bool srgb;
|
||||
int total_data_size = 0;
|
||||
|
||||
int mipmaps;
|
||||
bool compressed = false;
|
||||
|
||||
bool resize_to_po2;
|
||||
bool srgb = false;
|
||||
|
||||
bool active;
|
||||
GLenum tex_id;
|
||||
bool resize_to_po2 = false;
|
||||
|
||||
uint16_t stored_cube_sides;
|
||||
bool active = false;
|
||||
GLuint tex_id = 0;
|
||||
|
||||
uint16_t stored_cube_sides = 0;
|
||||
|
||||
RenderTarget *render_target = nullptr;
|
||||
|
||||
Vector<Ref<Image>> images;
|
||||
Ref<Image> image_cache_2d;
|
||||
|
||||
bool redraw_if_visible;
|
||||
bool redraw_if_visible = false;
|
||||
|
||||
RS::TextureDetectCallback detect_3d;
|
||||
void *detect_3d_ud = nullptr;
|
||||
RS::TextureDetectCallback detect_3d_callback = nullptr;
|
||||
void *detect_3d_callback_ud = nullptr;
|
||||
|
||||
RS::TextureDetectCallback detect_srgb;
|
||||
RS::TextureDetectCallback detect_srgb = nullptr;
|
||||
void *detect_srgb_ud = nullptr;
|
||||
|
||||
RS::TextureDetectCallback detect_normal;
|
||||
void *detect_normal_ud = nullptr;
|
||||
RS::TextureDetectCallback detect_normal_callback = nullptr;
|
||||
void *detect_normal_callback_ud = nullptr;
|
||||
|
||||
RS::TextureDetectRoughnessCallback detect_roughness_callback = nullptr;
|
||||
void *detect_roughness_callback_ud = nullptr;
|
||||
|
||||
CanvasTexture *canvas_texture = nullptr;
|
||||
|
||||
// some silly opengl shenanigans where
|
||||
// texture coords start from bottom left, means we need to draw render target textures upside down
|
||||
// to be compatible with vulkan etc.
|
||||
bool is_upside_down() const {
|
||||
if (proxy) {
|
||||
return proxy->is_upside_down();
|
||||
}
|
||||
|
||||
return render_target != nullptr;
|
||||
}
|
||||
|
||||
Texture() {
|
||||
create();
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ Texture *get_ptr() {
|
||||
if (proxy) {
|
||||
return proxy; //->get_ptr(); only one level of indirection, else not inlining possible.
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
~Texture() {
|
||||
destroy();
|
||||
|
||||
if (tex_id != 0) {
|
||||
glDeleteTextures(1, &tex_id);
|
||||
}
|
||||
}
|
||||
|
||||
void copy_from(const Texture &o) {
|
||||
proxy = o.proxy;
|
||||
flags = o.flags;
|
||||
proxy_to = o.proxy_to;
|
||||
is_proxy = o.is_proxy;
|
||||
width = o.width;
|
||||
height = o.height;
|
||||
alloc_width = o.alloc_width;
|
||||
alloc_height = o.alloc_height;
|
||||
format = o.format;
|
||||
type = o.type;
|
||||
layered_type = o.layered_type;
|
||||
target = o.target;
|
||||
data_size = o.data_size;
|
||||
total_data_size = o.total_data_size;
|
||||
ignore_mipmaps = o.ignore_mipmaps;
|
||||
compressed = o.compressed;
|
||||
mipmaps = o.mipmaps;
|
||||
resize_to_po2 = o.resize_to_po2;
|
||||
@ -218,102 +208,95 @@ struct Texture {
|
||||
tex_id = o.tex_id;
|
||||
stored_cube_sides = o.stored_cube_sides;
|
||||
render_target = o.render_target;
|
||||
is_render_target = o.is_render_target;
|
||||
redraw_if_visible = o.redraw_if_visible;
|
||||
detect_3d = o.detect_3d;
|
||||
detect_3d_ud = o.detect_3d_ud;
|
||||
detect_3d_callback = o.detect_3d_callback;
|
||||
detect_3d_callback_ud = o.detect_3d_callback_ud;
|
||||
detect_srgb = o.detect_srgb;
|
||||
detect_srgb_ud = o.detect_srgb_ud;
|
||||
detect_normal = o.detect_normal;
|
||||
detect_normal_ud = o.detect_normal_ud;
|
||||
|
||||
images.clear();
|
||||
}
|
||||
|
||||
void create() {
|
||||
proxy = nullptr;
|
||||
flags = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
alloc_width = 0;
|
||||
alloc_height = 0;
|
||||
format = Image::FORMAT_L8;
|
||||
type = RenderingDevice::TEXTURE_TYPE_2D;
|
||||
target = 0;
|
||||
data_size = 0;
|
||||
total_data_size = 0;
|
||||
ignore_mipmaps = false;
|
||||
compressed = false;
|
||||
mipmaps = 0;
|
||||
resize_to_po2 = false;
|
||||
active = false;
|
||||
tex_id = 0;
|
||||
stored_cube_sides = 0;
|
||||
render_target = nullptr;
|
||||
redraw_if_visible = false;
|
||||
detect_3d = nullptr;
|
||||
detect_3d_ud = nullptr;
|
||||
detect_srgb = nullptr;
|
||||
detect_srgb_ud = nullptr;
|
||||
detect_normal = nullptr;
|
||||
detect_normal_ud = nullptr;
|
||||
}
|
||||
void destroy() {
|
||||
images.clear();
|
||||
|
||||
for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) {
|
||||
E->get()->proxy = nullptr;
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
proxy->proxy_owners.erase(this);
|
||||
}
|
||||
detect_normal_callback = o.detect_normal_callback;
|
||||
detect_normal_callback_ud = o.detect_normal_callback_ud;
|
||||
detect_roughness_callback = o.detect_roughness_callback;
|
||||
detect_roughness_callback_ud = o.detect_roughness_callback_ud;
|
||||
}
|
||||
|
||||
// texture state
|
||||
void GLSetFilter(GLenum p_target, RS::CanvasItemTextureFilter p_filter) {
|
||||
void gl_set_filter(RS::CanvasItemTextureFilter p_filter) {
|
||||
if (p_filter == state_filter) {
|
||||
return;
|
||||
}
|
||||
Config *config = Config::get_singleton();
|
||||
state_filter = p_filter;
|
||||
GLint pmin = GL_LINEAR; // param min
|
||||
GLint pmag = GL_LINEAR; // param mag
|
||||
GLenum pmin = GL_NEAREST; // param min
|
||||
GLenum pmag = GL_NEAREST; // param mag
|
||||
GLint max_lod = 1000;
|
||||
bool use_anisotropy = false;
|
||||
switch (state_filter) {
|
||||
default: {
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: {
|
||||
pmin = GL_LINEAR_MIPMAP_LINEAR;
|
||||
pmag = GL_LINEAR;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST: {
|
||||
pmin = GL_NEAREST;
|
||||
pmag = GL_NEAREST;
|
||||
max_lod = 0;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR: {
|
||||
pmin = GL_LINEAR;
|
||||
pmag = GL_LINEAR;
|
||||
max_lod = 0;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: {
|
||||
use_anisotropy = true;
|
||||
};
|
||||
[[fallthrough]];
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: {
|
||||
pmin = GL_NEAREST_MIPMAP_NEAREST;
|
||||
pmag = GL_NEAREST;
|
||||
if (config->use_nearest_mip_filter) {
|
||||
pmin = GL_NEAREST_MIPMAP_NEAREST;
|
||||
} else {
|
||||
pmin = GL_NEAREST_MIPMAP_LINEAR;
|
||||
}
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC: {
|
||||
use_anisotropy = true;
|
||||
};
|
||||
[[fallthrough]];
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: {
|
||||
pmag = GL_LINEAR;
|
||||
if (config->use_nearest_mip_filter) {
|
||||
pmin = GL_LINEAR_MIPMAP_NEAREST;
|
||||
|
||||
} else {
|
||||
pmin = GL_LINEAR_MIPMAP_LINEAR;
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
glTexParameteri(p_target, GL_TEXTURE_MIN_FILTER, pmin);
|
||||
glTexParameteri(p_target, GL_TEXTURE_MAG_FILTER, pmag);
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, pmin);
|
||||
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, pmag);
|
||||
glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, max_lod);
|
||||
if (config->support_anisotropic_filter && use_anisotropy) {
|
||||
glTexParameterf(target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config->anisotropic_level);
|
||||
}
|
||||
}
|
||||
void GLSetRepeat(GLenum p_target, RS::CanvasItemTextureRepeat p_repeat) {
|
||||
void gl_set_repeat(RS::CanvasItemTextureRepeat p_repeat) {
|
||||
if (p_repeat == state_repeat) {
|
||||
return;
|
||||
}
|
||||
state_repeat = p_repeat;
|
||||
GLint prep = GL_CLAMP_TO_EDGE; // parameter repeat
|
||||
GLenum prep = GL_CLAMP_TO_EDGE; // parameter repeat
|
||||
switch (state_repeat) {
|
||||
default: {
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: {
|
||||
prep = GL_REPEAT;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: {
|
||||
prep = GL_MIRRORED_REPEAT;
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
glTexParameteri(p_target, GL_TEXTURE_WRAP_S, prep);
|
||||
glTexParameteri(p_target, GL_TEXTURE_WRAP_T, prep);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, prep);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_R, prep);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_S, prep);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -322,54 +305,46 @@ private:
|
||||
};
|
||||
|
||||
struct RenderTarget {
|
||||
RID self;
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
GLuint depth = 0;
|
||||
|
||||
GLuint multisample_fbo = 0;
|
||||
GLuint multisample_color = 0;
|
||||
GLuint multisample_depth = 0;
|
||||
bool multisample_active = false;
|
||||
|
||||
struct Effect {
|
||||
GLuint fbo = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
GLuint color = 0;
|
||||
};
|
||||
|
||||
Effect copy_screen_effect;
|
||||
|
||||
struct MipMaps {
|
||||
struct Size {
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
GLuint fbo;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
Vector<Size> sizes;
|
||||
GLuint color = 0;
|
||||
int levels = 0;
|
||||
};
|
||||
|
||||
MipMaps mip_maps[2];
|
||||
MipMaps() {
|
||||
}
|
||||
};
|
||||
|
||||
struct External {
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
GLuint depth = 0;
|
||||
RID texture;
|
||||
|
||||
External() {
|
||||
}
|
||||
} external;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
Point2i position = Point2i(0, 0);
|
||||
Size2i size = Size2i(0, 0);
|
||||
RID self;
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
|
||||
bool flags[RendererTextureStorage::RENDER_TARGET_FLAG_MAX] = {};
|
||||
GLuint color_internal_format = GL_RGBA8;
|
||||
GLuint color_format = GL_RGBA;
|
||||
GLuint color_type = GL_UNSIGNED_BYTE;
|
||||
Image::Format image_format = Image::FORMAT_RGBA8;
|
||||
|
||||
MipMaps mip_maps[2];
|
||||
bool mip_maps_allocated = false;
|
||||
|
||||
bool flags[RendererTextureStorage::RENDER_TARGET_FLAG_MAX];
|
||||
|
||||
// instead of allocating sized render targets immediately,
|
||||
// defer this for faster startup
|
||||
@ -377,14 +352,8 @@ struct RenderTarget {
|
||||
bool used_in_frame = false;
|
||||
RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;
|
||||
|
||||
bool use_fxaa = false;
|
||||
bool use_debanding = false;
|
||||
|
||||
RID texture;
|
||||
|
||||
bool used_dof_blur_near = false;
|
||||
bool mip_maps_allocated = false;
|
||||
|
||||
Color clear_color = Color(1, 1, 1, 1);
|
||||
bool clear_requested = false;
|
||||
|
||||
@ -392,7 +361,6 @@ struct RenderTarget {
|
||||
for (int i = 0; i < RendererTextureStorage::RENDER_TARGET_FLAG_MAX; ++i) {
|
||||
flags[i] = false;
|
||||
}
|
||||
external.fbo = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -400,6 +368,8 @@ class TextureStorage : public RendererTextureStorage {
|
||||
private:
|
||||
static TextureStorage *singleton;
|
||||
|
||||
RID default_gl_textures[DEFAULT_GL_TEXTURE_MAX];
|
||||
|
||||
Thread::ID _main_thread_id = 0;
|
||||
bool _is_main_thread();
|
||||
|
||||
@ -409,16 +379,13 @@ private:
|
||||
|
||||
/* Texture API */
|
||||
|
||||
mutable RID_PtrOwner<Texture> texture_owner;
|
||||
mutable RID_Owner<Texture> texture_owner;
|
||||
|
||||
Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const;
|
||||
void _texture_set_state_from_flags(Texture *p_tex);
|
||||
|
||||
void texture_set_proxy(RID p_texture, RID p_proxy);
|
||||
|
||||
/* Render Target API */
|
||||
|
||||
mutable RID_PtrOwner<RenderTarget> render_target_owner;
|
||||
mutable RID_Owner<RenderTarget> render_target_owner;
|
||||
|
||||
// make access easier to these
|
||||
struct Dimensions {
|
||||
@ -443,6 +410,10 @@ public:
|
||||
TextureStorage();
|
||||
virtual ~TextureStorage();
|
||||
|
||||
_FORCE_INLINE_ RID texture_gl_get_default(DefaultGLTexture p_texture) {
|
||||
return default_gl_textures[p_texture];
|
||||
}
|
||||
|
||||
/* Canvas Texture API */
|
||||
|
||||
CanvasTexture *get_canvas_texture(RID p_rid) { return canvas_texture_owner.get_or_null(p_rid); };
|
||||
@ -460,16 +431,20 @@ public:
|
||||
|
||||
/* Texture API */
|
||||
|
||||
Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); };
|
||||
Texture *get_texture(RID p_rid) {
|
||||
Texture *texture = texture_owner.get_or_null(p_rid);
|
||||
if (texture && texture->is_proxy) {
|
||||
return texture_owner.get_or_null(texture->proxy_to);
|
||||
}
|
||||
return texture;
|
||||
};
|
||||
bool owns_texture(RID p_rid) { return texture_owner.owns(p_rid); };
|
||||
RID make_rid(Texture *p_texture) { return texture_owner.make_rid(p_texture); };
|
||||
|
||||
void set_main_thread_id(Thread::ID p_id);
|
||||
|
||||
virtual bool can_create_resources_async() const override;
|
||||
|
||||
RID texture_create();
|
||||
void _texture_allocate_internal(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingDevice::TextureType p_type, uint32_t p_flags = TEXTURE_FLAGS_DEFAULT);
|
||||
|
||||
virtual RID texture_allocate() override;
|
||||
virtual void texture_free(RID p_rid) override;
|
||||
@ -481,7 +456,7 @@ public:
|
||||
|
||||
virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override;
|
||||
virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override{};
|
||||
virtual void texture_proxy_update(RID p_proxy, RID p_base) override{};
|
||||
virtual void texture_proxy_update(RID p_proxy, RID p_base) override;
|
||||
|
||||
//these two APIs can be used together or in combination with the others.
|
||||
virtual void texture_2d_placeholder_initialize(RID p_texture) override;
|
||||
@ -501,7 +476,7 @@ public:
|
||||
virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
|
||||
void texture_set_detect_srgb_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata);
|
||||
virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
|
||||
virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override{};
|
||||
virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override;
|
||||
|
||||
virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override;
|
||||
|
||||
@ -512,18 +487,14 @@ public:
|
||||
void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0);
|
||||
void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer = 0);
|
||||
//Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const;
|
||||
void texture_set_flags(RID p_texture, uint32_t p_flags);
|
||||
uint32_t texture_get_flags(RID p_texture) const;
|
||||
void texture_set_sampler(RID p_texture, RS::CanvasItemTextureFilter p_filter, RS::CanvasItemTextureRepeat p_repeat);
|
||||
Image::Format texture_get_format(RID p_texture) const;
|
||||
RenderingDevice::TextureType texture_get_type(RID p_texture) const;
|
||||
uint32_t texture_get_texid(RID p_texture) const;
|
||||
uint32_t texture_get_width(RID p_texture) const;
|
||||
uint32_t texture_get_height(RID p_texture) const;
|
||||
uint32_t texture_get_depth(RID p_texture) const;
|
||||
void texture_bind(RID p_texture, uint32_t p_texture_no);
|
||||
void texture_set_shrink_all_x2_on_set_data(bool p_enable);
|
||||
RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const;
|
||||
void textures_keep_original(bool p_enable);
|
||||
|
||||
/* DECAL API */
|
||||
|
||||
@ -550,29 +521,18 @@ public:
|
||||
|
||||
static GLuint system_fbo;
|
||||
|
||||
// TODO this should be moved back to storage or removed
|
||||
struct Frame {
|
||||
GLES3::RenderTarget *current_rt;
|
||||
|
||||
// these 2 may have been superseded by the equivalents in the render target.
|
||||
// these may be able to be removed.
|
||||
bool clear_request;
|
||||
Color clear_request_color;
|
||||
|
||||
float time;
|
||||
float delta;
|
||||
uint64_t count;
|
||||
|
||||
Frame() {
|
||||
// current_rt = nullptr;
|
||||
// clear_request = false;
|
||||
}
|
||||
} frame;
|
||||
|
||||
RenderTarget *get_render_target(RID p_rid) { return render_target_owner.get_or_null(p_rid); };
|
||||
bool owns_render_target(RID p_rid) { return render_target_owner.owns(p_rid); };
|
||||
|
||||
void _render_target_clear(RenderTarget *rt);
|
||||
void _render_target_allocate(RenderTarget *rt);
|
||||
// TODO these internals should be private
|
||||
void _clear_render_target(RenderTarget *rt);
|
||||
void _update_render_target(RenderTarget *rt);
|
||||
void _create_render_target_backbuffer(RenderTarget *rt);
|
||||
void _set_current_render_target(RID p_render_target);
|
||||
|
||||
virtual RID render_target_create() override;
|
||||
@ -586,9 +546,6 @@ public:
|
||||
virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) override;
|
||||
virtual bool render_target_was_used(RID p_render_target) override;
|
||||
void render_target_clear_used(RID p_render_target);
|
||||
void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa);
|
||||
void render_target_set_use_fxaa(RID p_render_target, bool p_fxaa);
|
||||
void render_target_set_use_debanding(RID p_render_target, bool p_debanding);
|
||||
|
||||
// new
|
||||
void render_target_set_as_unused(RID p_render_target) override {
|
||||
@ -604,8 +561,33 @@ public:
|
||||
void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override;
|
||||
Rect2i render_target_get_sdf_rect(RID p_render_target) const override;
|
||||
void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override;
|
||||
|
||||
void bind_framebuffer(GLuint framebuffer) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
}
|
||||
|
||||
void bind_framebuffer_system() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);
|
||||
}
|
||||
|
||||
String get_framebuffer_error(GLenum p_status);
|
||||
};
|
||||
|
||||
inline String TextureStorage::get_framebuffer_error(GLenum p_status) {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (p_status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
||||
} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
||||
} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
|
||||
} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
|
||||
return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
|
||||
}
|
||||
#endif
|
||||
return itos(p_status);
|
||||
}
|
||||
|
||||
} // namespace GLES3
|
||||
|
||||
#endif // !GLES3_ENABLED
|
||||
|
Loading…
Reference in New Issue
Block a user