Split dummy renderer classes into separate files
Split canvas_texture_storage and texture_storage from render_storage class
This commit is contained in:
parent
cfd21adf64
commit
57e5a33623
55 changed files with 5272 additions and 4169 deletions
|
|
@ -5,3 +5,4 @@ Import("env")
|
|||
env.add_source_files(env.drivers_sources, "*.cpp")
|
||||
|
||||
SConscript("shaders/SCsub")
|
||||
SConscript("storage/SCsub")
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@
|
|||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "servers/rendering/rendering_server_default.h"
|
||||
#include "storage/canvas_texture_storage.h"
|
||||
#include "storage/config.h"
|
||||
|
||||
#ifndef GLES_OVER_GL
|
||||
#define glClearDepth glClearDepthf
|
||||
|
|
@ -260,7 +262,7 @@ void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_cou
|
|||
for (int ti = 0; ti < tc; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + ti);
|
||||
|
||||
RasterizerStorageGLES3::Texture *t = storage->texture_owner.get_or_null(textures[ti].second);
|
||||
GLES3::Texture *t = texture_storage->get_texture(textures[ti].second);
|
||||
|
||||
if (!t) {
|
||||
switch (texture_uniforms[i].hint) {
|
||||
|
|
@ -915,20 +917,20 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
|||
state.end_batch = true;
|
||||
_render_batch(r_index);
|
||||
|
||||
RasterizerStorageGLES3::CanvasTexture *ct = nullptr;
|
||||
GLES3::CanvasTexture *ct = nullptr;
|
||||
|
||||
RasterizerStorageGLES3::Texture *t = storage->texture_owner.get_or_null(p_texture);
|
||||
GLES3::Texture *t = texture_storage->get_texture(p_texture);
|
||||
|
||||
if (t) {
|
||||
//regular texture
|
||||
if (!t->canvas_texture) {
|
||||
t->canvas_texture = memnew(RasterizerStorageGLES3::CanvasTexture);
|
||||
t->canvas_texture = memnew(GLES3::CanvasTexture);
|
||||
t->canvas_texture->diffuse = p_texture;
|
||||
}
|
||||
|
||||
ct = t->canvas_texture;
|
||||
} else {
|
||||
ct = storage->canvas_texture_owner.get_or_null(p_texture);
|
||||
ct = GLES3::CanvasTextureStorage::get_singleton()->get_canvas_texture(p_texture);
|
||||
}
|
||||
|
||||
if (!ct) {
|
||||
|
|
@ -943,7 +945,7 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
|||
RS::CanvasItemTextureRepeat repeat = ct->texture_repeat != RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT ? ct->texture_repeat : p_base_repeat;
|
||||
ERR_FAIL_COND(repeat == RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT);
|
||||
|
||||
RasterizerStorageGLES3::Texture *texture = storage->texture_owner.get_or_null(ct->diffuse);
|
||||
GLES3::Texture *texture = texture_storage->get_texture(ct->diffuse);
|
||||
|
||||
if (!texture) {
|
||||
state.current_tex = RID();
|
||||
|
|
@ -967,18 +969,18 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
|||
texture->GLSetRepeat(GL_TEXTURE_2D, repeat);
|
||||
}
|
||||
|
||||
RasterizerStorageGLES3::Texture *normal_map = storage->texture_owner.get_or_null(ct->normal_map);
|
||||
GLES3::Texture *normal_map = texture_storage->get_texture(ct->normal_map);
|
||||
|
||||
if (!normal_map) {
|
||||
state.current_normal = RID();
|
||||
ct->use_normal_cache = false;
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6);
|
||||
glActiveTexture(GL_TEXTURE0 + GLES3::Config::get_singleton()->max_texture_image_units - 6);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);
|
||||
|
||||
} else {
|
||||
normal_map = normal_map->get_ptr();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6);
|
||||
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;
|
||||
|
|
@ -986,18 +988,18 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe
|
|||
texture->GLSetRepeat(GL_TEXTURE_2D, repeat);
|
||||
}
|
||||
|
||||
RasterizerStorageGLES3::Texture *specular_map = storage->texture_owner.get_or_null(ct->specular);
|
||||
GLES3::Texture *specular_map = texture_storage->get_texture(ct->specular);
|
||||
|
||||
if (!specular_map) {
|
||||
state.current_specular = RID();
|
||||
ct->use_specular_cache = false;
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 7);
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config->max_texture_image_units - 7);
|
||||
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
|
||||
|
||||
} else {
|
||||
specular_map = specular_map->get_ptr();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 7);
|
||||
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;
|
||||
|
|
@ -1249,6 +1251,10 @@ void RasterizerCanvasGLES3::_allocate_instance_data_buffer() {
|
|||
}
|
||||
|
||||
void RasterizerCanvasGLES3::initialize() {
|
||||
// !BAS! shouldn't we be obtaining storage here as well?
|
||||
canvas_texture_storage = GLES3::CanvasTextureStorage::get_singleton();
|
||||
texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
|
||||
// quad buffer
|
||||
{
|
||||
glGenBuffers(1, &data.canvas_quad_vertices);
|
||||
|
|
@ -1408,7 +1414,7 @@ void RasterizerCanvasGLES3::initialize() {
|
|||
state.canvas_shader_default_version = state.canvas_shader.version_create();
|
||||
state.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);
|
||||
//state.canvas_shader.set_conditional(CanvasOldShaderGLES3::USE_RGBA_SHADOWS, storage->config->use_rgba_2d_shadows);
|
||||
|
||||
//state.canvas_shader.bind();
|
||||
|
||||
|
|
@ -1441,8 +1447,8 @@ void fragment() {
|
|||
storage->material_set_shader(default_canvas_group_material, default_canvas_group_shader);
|
||||
}
|
||||
|
||||
default_canvas_texture = storage->canvas_texture_allocate();
|
||||
storage->canvas_texture_initialize(default_canvas_texture);
|
||||
default_canvas_texture = canvas_texture_storage->canvas_texture_allocate();
|
||||
canvas_texture_storage->canvas_texture_initialize(default_canvas_texture);
|
||||
|
||||
state.using_light = nullptr;
|
||||
state.using_transparent_rt = false;
|
||||
|
|
@ -1456,7 +1462,7 @@ RasterizerCanvasGLES3::~RasterizerCanvasGLES3() {
|
|||
state.canvas_shader.version_free(state.canvas_shader_default_version);
|
||||
storage->free(default_canvas_group_material);
|
||||
storage->free(default_canvas_group_shader);
|
||||
storage->free(default_canvas_texture);
|
||||
canvas_texture_storage->canvas_texture_free(default_canvas_texture);
|
||||
}
|
||||
|
||||
void RasterizerCanvasGLES3::finalize() {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@
|
|||
#include "rasterizer_storage_gles3.h"
|
||||
#include "servers/rendering/renderer_canvas_render.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "storage/canvas_texture_storage.h"
|
||||
#include "storage/texture_storage.h"
|
||||
|
||||
#include "shaders/canvas.glsl.gen.h"
|
||||
|
||||
|
|
@ -184,7 +186,7 @@ public:
|
|||
RID current_tex = RID();
|
||||
RID current_normal = RID();
|
||||
RID current_specular = RID();
|
||||
RasterizerStorageGLES3::Texture *current_tex_ptr;
|
||||
GLES3::Texture *current_tex_ptr;
|
||||
RID current_shader_version = RID();
|
||||
RS::PrimitiveType current_primitive = RS::PRIMITIVE_MAX;
|
||||
uint32_t current_primitive_points = 0;
|
||||
|
|
@ -217,6 +219,8 @@ public:
|
|||
|
||||
RasterizerSceneGLES3 *scene_render;
|
||||
|
||||
GLES3::CanvasTextureStorage *canvas_texture_storage;
|
||||
GLES3::TextureStorage *texture_storage;
|
||||
RasterizerStorageGLES3 *storage;
|
||||
|
||||
void _set_uniforms();
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userP
|
|||
void RasterizerGLES3::initialize() {
|
||||
print_verbose("Using OpenGL video driver");
|
||||
|
||||
storage._main_thread_id = Thread::get_caller_id();
|
||||
texture_storage.set_main_thread_id(Thread::get_caller_id());
|
||||
|
||||
#ifdef GLAD_ENABLED
|
||||
if (!gladLoadGL()) {
|
||||
|
|
@ -271,7 +271,7 @@ void RasterizerGLES3::prepare_for_blitting_render_targets() {
|
|||
void RasterizerGLES3::_blit_render_target_to_screen(RID p_render_target, DisplayServer::WindowID p_screen, const Rect2 &p_screen_rect) {
|
||||
ERR_FAIL_COND(storage.frame.current_rt);
|
||||
|
||||
RasterizerStorageGLES3::RenderTarget *rt = storage.render_target_owner.get_or_null(p_render_target);
|
||||
GLES3::RenderTarget *rt = storage.render_target_owner.get_or_null(p_render_target);
|
||||
ERR_FAIL_COND(!rt);
|
||||
|
||||
// TODO: do we need a keep 3d linear option?
|
||||
|
|
@ -324,10 +324,10 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
|
|||
|
||||
canvas.canvas_begin();
|
||||
|
||||
RID texture = storage.texture_create();
|
||||
//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);
|
||||
storage._texture_allocate_internal(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), RenderingDevice::TEXTURE_TYPE_2D);
|
||||
storage.texture_set_data(texture, p_image);
|
||||
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);
|
||||
|
||||
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
|
||||
Rect2 screenrect;
|
||||
|
|
@ -349,13 +349,13 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
|
|||
screenrect.position += ((Size2(win_size.width, win_size.height) - screenrect.size) / 2.0).floor();
|
||||
}
|
||||
|
||||
RasterizerStorageGLES3::Texture *t = storage.texture_owner.get_or_null(texture);
|
||||
glActiveTexture(GL_TEXTURE0 + storage.config.max_texture_image_units - 1);
|
||||
GLES3::Texture *t = texture_storage.get_texture(texture);
|
||||
glActiveTexture(GL_TEXTURE0 + config.max_texture_image_units - 1);
|
||||
glBindTexture(GL_TEXTURE_2D, t->tex_id);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
canvas.canvas_end();
|
||||
|
||||
storage.free(texture);
|
||||
texture_storage.texture_free(texture);
|
||||
|
||||
end_frame(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@
|
|||
#include "rasterizer_scene_gles3.h"
|
||||
#include "rasterizer_storage_gles3.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "storage/canvas_texture_storage.h"
|
||||
#include "storage/config.h"
|
||||
#include "storage/render_target_storage.h"
|
||||
#include "storage/texture_storage.h"
|
||||
|
||||
class RasterizerGLES3 : public RendererCompositor {
|
||||
private:
|
||||
|
|
@ -46,6 +50,9 @@ private:
|
|||
double time_total = 0.0;
|
||||
|
||||
protected:
|
||||
GLES3::Config config;
|
||||
GLES3::CanvasTextureStorage canvas_texture_storage;
|
||||
GLES3::TextureStorage texture_storage;
|
||||
RasterizerStorageGLES3 storage;
|
||||
RasterizerCanvasGLES3 canvas;
|
||||
RasterizerSceneGLES3 scene;
|
||||
|
|
@ -53,6 +60,8 @@ protected:
|
|||
void _blit_render_target_to_screen(RID p_render_target, DisplayServer::WindowID p_screen, const Rect2 &p_screen_rect);
|
||||
|
||||
public:
|
||||
RendererCanvasTextureStorage *get_canvas_texture_storage() { return &canvas_texture_storage; }
|
||||
RendererTextureStorage *get_texture_storage() { return &texture_storage; }
|
||||
RendererStorage *get_storage() { return &storage; }
|
||||
RendererCanvasRender *get_canvas() { return &canvas; }
|
||||
RendererSceneRender *get_scene() { return &scene; }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -40,6 +40,10 @@
|
|||
#include "servers/rendering/renderer_storage.h"
|
||||
#include "servers/rendering/shader_compiler.h"
|
||||
#include "servers/rendering/shader_language.h"
|
||||
#include "storage/canvas_texture_storage.h"
|
||||
#include "storage/config.h"
|
||||
#include "storage/render_target_storage.h"
|
||||
#include "storage/texture_storage.h"
|
||||
|
||||
#include "shaders/copy.glsl.gen.h"
|
||||
|
||||
|
|
@ -47,66 +51,13 @@ class RasterizerCanvasGLES3;
|
|||
class RasterizerSceneGLES3;
|
||||
|
||||
class RasterizerStorageGLES3 : public RendererStorage {
|
||||
friend class RasterizerGLES3;
|
||||
|
||||
Thread::ID _main_thread_id = 0;
|
||||
bool _is_main_thread();
|
||||
|
||||
public:
|
||||
RasterizerCanvasGLES3 *canvas;
|
||||
RasterizerSceneGLES3 *scene;
|
||||
|
||||
static GLuint system_fbo;
|
||||
|
||||
struct Config {
|
||||
bool shrink_textures_x2;
|
||||
bool use_fast_texture_filter;
|
||||
bool use_skeleton_software;
|
||||
|
||||
int max_vertex_texture_image_units;
|
||||
int max_texture_image_units;
|
||||
int max_texture_size;
|
||||
|
||||
// TODO implement wireframe in OpenGL
|
||||
// bool generate_wireframes;
|
||||
|
||||
Set<String> extensions;
|
||||
|
||||
bool float_texture_supported;
|
||||
bool s3tc_supported;
|
||||
bool latc_supported;
|
||||
bool rgtc_supported;
|
||||
bool bptc_supported;
|
||||
bool etc_supported;
|
||||
bool etc2_supported;
|
||||
bool srgb_decode_supported;
|
||||
|
||||
bool keep_original_textures;
|
||||
|
||||
bool force_vertex_shading;
|
||||
|
||||
bool use_rgba_2d_shadows;
|
||||
bool use_rgba_3d_shadows;
|
||||
|
||||
bool support_32_bits_indices;
|
||||
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;
|
||||
|
||||
GLuint depth_internalformat;
|
||||
GLuint depth_type;
|
||||
GLuint depth_buffer_internalformat;
|
||||
|
||||
// in some cases the legacy render didn't orphan. We will mark these
|
||||
// so the user can switch orphaning off for them.
|
||||
bool should_orphan;
|
||||
} config;
|
||||
GLES3::Config *config;
|
||||
|
||||
struct Resources {
|
||||
GLuint white_tex;
|
||||
|
|
@ -180,334 +131,7 @@ public:
|
|||
//////////////////////////////////API////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool can_create_resources_async() const override;
|
||||
|
||||
// TEXTURE API
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
/* CANVAS TEXTURE API (2D) */
|
||||
|
||||
struct CanvasTexture {
|
||||
RID diffuse;
|
||||
RID normal_map;
|
||||
RID specular;
|
||||
Color specular_color = Color(1, 1, 1, 1);
|
||||
float shininess = 1.0;
|
||||
|
||||
RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
|
||||
RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
|
||||
|
||||
Size2i size_cache = Size2i(1, 1);
|
||||
bool use_normal_cache = false;
|
||||
bool use_specular_cache = false;
|
||||
bool cleared_cache = true;
|
||||
};
|
||||
|
||||
RID_Owner<CanvasTexture, true> canvas_texture_owner;
|
||||
|
||||
struct RenderTarget;
|
||||
|
||||
struct Texture {
|
||||
RID self;
|
||||
|
||||
Texture *proxy;
|
||||
Set<Texture *> proxy_owners;
|
||||
|
||||
String path;
|
||||
uint32_t flags;
|
||||
int width, height, depth;
|
||||
int alloc_width, alloc_height;
|
||||
Image::Format format;
|
||||
RenderingDevice::TextureType type;
|
||||
|
||||
GLenum target;
|
||||
GLenum gl_format_cache;
|
||||
GLenum gl_internal_format_cache;
|
||||
GLenum gl_type_cache;
|
||||
|
||||
int data_size;
|
||||
int total_data_size;
|
||||
bool ignore_mipmaps;
|
||||
|
||||
bool compressed;
|
||||
|
||||
bool srgb;
|
||||
|
||||
int mipmaps;
|
||||
|
||||
bool resize_to_po2;
|
||||
|
||||
bool active;
|
||||
GLenum tex_id;
|
||||
|
||||
uint16_t stored_cube_sides;
|
||||
|
||||
RenderTarget *render_target;
|
||||
|
||||
Vector<Ref<Image>> images;
|
||||
|
||||
bool redraw_if_visible;
|
||||
|
||||
RS::TextureDetectCallback detect_3d;
|
||||
void *detect_3d_ud;
|
||||
|
||||
RS::TextureDetectCallback detect_srgb;
|
||||
void *detect_srgb_ud;
|
||||
|
||||
RS::TextureDetectCallback detect_normal;
|
||||
void *detect_normal_ud;
|
||||
|
||||
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;
|
||||
width = o.width;
|
||||
height = o.height;
|
||||
alloc_width = o.alloc_width;
|
||||
alloc_height = o.alloc_height;
|
||||
format = o.format;
|
||||
type = o.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;
|
||||
active = o.active;
|
||||
tex_id = o.tex_id;
|
||||
stored_cube_sides = o.stored_cube_sides;
|
||||
render_target = o.render_target;
|
||||
redraw_if_visible = o.redraw_if_visible;
|
||||
detect_3d = o.detect_3d;
|
||||
detect_3d_ud = o.detect_3d_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);
|
||||
}
|
||||
}
|
||||
|
||||
// texture state
|
||||
void GLSetFilter(GLenum p_target, RS::CanvasItemTextureFilter p_filter) {
|
||||
if (p_filter == state_filter) {
|
||||
return;
|
||||
}
|
||||
state_filter = p_filter;
|
||||
GLint pmin = GL_LINEAR; // param min
|
||||
GLint pmag = GL_LINEAR; // param mag
|
||||
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;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: {
|
||||
pmin = GL_NEAREST_MIPMAP_NEAREST;
|
||||
pmag = GL_NEAREST;
|
||||
} break;
|
||||
}
|
||||
glTexParameteri(p_target, GL_TEXTURE_MIN_FILTER, pmin);
|
||||
glTexParameteri(p_target, GL_TEXTURE_MAG_FILTER, pmag);
|
||||
}
|
||||
void GLSetRepeat(GLenum p_target, RS::CanvasItemTextureRepeat p_repeat) {
|
||||
if (p_repeat == state_repeat) {
|
||||
return;
|
||||
}
|
||||
state_repeat = p_repeat;
|
||||
GLint 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;
|
||||
}
|
||||
glTexParameteri(p_target, GL_TEXTURE_WRAP_S, prep);
|
||||
glTexParameteri(p_target, GL_TEXTURE_WRAP_T, prep);
|
||||
}
|
||||
|
||||
private:
|
||||
RS::CanvasItemTextureFilter state_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
|
||||
RS::CanvasItemTextureRepeat state_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
|
||||
};
|
||||
|
||||
mutable RID_PtrOwner<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);
|
||||
|
||||
// new
|
||||
RID texture_allocate() override;
|
||||
void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override;
|
||||
void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override;
|
||||
void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override;
|
||||
void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent
|
||||
|
||||
void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override;
|
||||
void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override {}
|
||||
void texture_proxy_update(RID p_proxy, RID p_base) override {}
|
||||
|
||||
void texture_2d_placeholder_initialize(RID p_texture) override;
|
||||
void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override;
|
||||
void texture_3d_placeholder_initialize(RID p_texture) override;
|
||||
|
||||
Ref<Image> texture_2d_get(RID p_texture) const override;
|
||||
Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); }
|
||||
Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); }
|
||||
|
||||
void texture_replace(RID p_texture, RID p_by_texture) override;
|
||||
//void texture_set_size_override(RID p_texture, int p_width, int p_height) override {}
|
||||
|
||||
void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}
|
||||
void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}
|
||||
|
||||
// old
|
||||
uint32_t texture_get_width(RID p_texture) const;
|
||||
uint32_t texture_get_height(RID p_texture) const;
|
||||
|
||||
private:
|
||||
RID texture_create();
|
||||
|
||||
//void texture_allocate(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);
|
||||
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);
|
||||
|
||||
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;
|
||||
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_depth(RID p_texture) const;
|
||||
void texture_set_size_override(RID p_texture, int p_width, int p_height) override;
|
||||
|
||||
void texture_bind(RID p_texture, uint32_t p_texture_no);
|
||||
|
||||
void texture_set_path(RID p_texture, const String &p_path) override;
|
||||
String texture_get_path(RID p_texture) const override;
|
||||
|
||||
void texture_set_shrink_all_x2_on_set_data(bool p_enable);
|
||||
|
||||
void texture_debug_usage(List<RS::TextureInfo> *r_info) override;
|
||||
|
||||
RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const;
|
||||
|
||||
void textures_keep_original(bool p_enable);
|
||||
|
||||
void texture_set_proxy(RID p_texture, RID p_proxy);
|
||||
Size2 texture_size_with_proxy(RID p_texture) override;
|
||||
|
||||
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);
|
||||
void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;
|
||||
void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override {}
|
||||
|
||||
void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override;
|
||||
|
||||
public:
|
||||
RID canvas_texture_allocate() override;
|
||||
void canvas_texture_initialize(RID p_rid) override;
|
||||
|
||||
void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override;
|
||||
void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_specular_color, float p_shininess) override;
|
||||
|
||||
void canvas_texture_set_texture_filter(RID p_canvas_texture, RS::CanvasItemTextureFilter p_filter) override;
|
||||
void canvas_texture_set_texture_repeat(RID p_canvas_texture, RS::CanvasItemTextureRepeat p_repeat) override;
|
||||
|
||||
/* SKY API */
|
||||
// not sure if used in godot 4?
|
||||
struct Sky {
|
||||
|
|
@ -971,6 +595,9 @@ public:
|
|||
|
||||
AABB decal_get_aabb(RID p_decal) const override;
|
||||
|
||||
void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}
|
||||
void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
||||
RID voxel_gi_allocate() override;
|
||||
|
|
@ -1151,85 +778,10 @@ public:
|
|||
|
||||
// RENDER TARGET
|
||||
|
||||
struct RenderTarget {
|
||||
RID self;
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
GLuint depth = 0;
|
||||
mutable RID_PtrOwner<GLES3::RenderTarget> render_target_owner;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Vector<Size> sizes;
|
||||
GLuint color = 0;
|
||||
int levels = 0;
|
||||
};
|
||||
|
||||
MipMaps mip_maps[2];
|
||||
|
||||
struct External {
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
GLuint depth = 0;
|
||||
RID texture;
|
||||
} external;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
bool flags[RENDER_TARGET_FLAG_MAX] = {};
|
||||
|
||||
// instead of allocating sized render targets immediately,
|
||||
// defer this for faster startup
|
||||
bool allocate_is_dirty = false;
|
||||
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;
|
||||
|
||||
RenderTarget() {
|
||||
for (int i = 0; i < RENDER_TARGET_FLAG_MAX; ++i) {
|
||||
flags[i] = false;
|
||||
}
|
||||
external.fbo = 0;
|
||||
}
|
||||
};
|
||||
|
||||
mutable RID_PtrOwner<RenderTarget> render_target_owner;
|
||||
|
||||
void _render_target_clear(RenderTarget *rt);
|
||||
void _render_target_allocate(RenderTarget *rt);
|
||||
void _render_target_clear(GLES3::RenderTarget *rt);
|
||||
void _render_target_allocate(GLES3::RenderTarget *rt);
|
||||
void _set_current_render_target(RID p_render_target);
|
||||
|
||||
RID render_target_create() override;
|
||||
|
|
@ -1262,7 +814,7 @@ public:
|
|||
void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override;
|
||||
|
||||
// access from canvas
|
||||
// RenderTarget * render_target_get(RID p_render_target);
|
||||
// GLES3::RenderTarget * render_target_get(RID p_render_target);
|
||||
|
||||
/* CANVAS SHADOW */
|
||||
|
||||
|
|
@ -1301,7 +853,7 @@ public:
|
|||
bool free(RID p_rid) override;
|
||||
|
||||
struct Frame {
|
||||
RenderTarget *current_rt;
|
||||
GLES3::RenderTarget *current_rt;
|
||||
|
||||
// these 2 may have been superseded by the equivalents in the render target.
|
||||
// these may be able to be removed.
|
||||
|
|
@ -1408,7 +960,7 @@ inline bool RasterizerStorageGLES3::safe_buffer_sub_data(unsigned int p_total_bu
|
|||
inline void RasterizerStorageGLES3::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, GLenum p_usage, bool p_optional_orphan) const {
|
||||
// Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData
|
||||
// Was previously #ifndef GLES_OVER_GL however this causes stalls on desktop mac also (and possibly other)
|
||||
if (!p_optional_orphan || (config.should_orphan)) {
|
||||
if (!p_optional_orphan || (config->should_orphan)) {
|
||||
glBufferData(p_target, p_buffer_size, nullptr, p_usage);
|
||||
#ifdef RASTERIZER_EXTRA_CHECKS
|
||||
// fill with garbage off the end of the array
|
||||
|
|
|
|||
5
drivers/gles3/storage/SCsub
Normal file
5
drivers/gles3/storage/SCsub
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.drivers_sources, "*.cpp")
|
||||
96
drivers/gles3/storage/canvas_texture_storage.cpp
Normal file
96
drivers/gles3/storage/canvas_texture_storage.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*************************************************************************/
|
||||
/* canvas_texture_storage.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "canvas_texture_storage.h"
|
||||
|
||||
using namespace GLES3;
|
||||
|
||||
CanvasTextureStorage *CanvasTextureStorage::singleton = nullptr;
|
||||
|
||||
CanvasTextureStorage *CanvasTextureStorage::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
CanvasTextureStorage::CanvasTextureStorage() {
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
CanvasTextureStorage::~CanvasTextureStorage() {
|
||||
singleton = nullptr;
|
||||
}
|
||||
|
||||
RID CanvasTextureStorage::canvas_texture_allocate() {
|
||||
return canvas_texture_owner.allocate_rid();
|
||||
}
|
||||
|
||||
void CanvasTextureStorage::canvas_texture_initialize(RID p_rid) {
|
||||
canvas_texture_owner.initialize_rid(p_rid);
|
||||
}
|
||||
|
||||
void CanvasTextureStorage::canvas_texture_free(RID p_rid) {
|
||||
canvas_texture_owner.free(p_rid);
|
||||
}
|
||||
|
||||
void CanvasTextureStorage::canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) {
|
||||
CanvasTexture *ct = canvas_texture_owner.get_or_null(p_canvas_texture);
|
||||
switch (p_channel) {
|
||||
case RS::CANVAS_TEXTURE_CHANNEL_DIFFUSE: {
|
||||
ct->diffuse = p_texture;
|
||||
} break;
|
||||
case RS::CANVAS_TEXTURE_CHANNEL_NORMAL: {
|
||||
ct->normal_map = p_texture;
|
||||
} break;
|
||||
case RS::CANVAS_TEXTURE_CHANNEL_SPECULAR: {
|
||||
ct->specular = p_texture;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasTextureStorage::canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_specular_color, float p_shininess) {
|
||||
CanvasTexture *ct = canvas_texture_owner.get_or_null(p_canvas_texture);
|
||||
ct->specular_color.r = p_specular_color.r;
|
||||
ct->specular_color.g = p_specular_color.g;
|
||||
ct->specular_color.b = p_specular_color.b;
|
||||
ct->specular_color.a = p_shininess;
|
||||
}
|
||||
|
||||
void CanvasTextureStorage::canvas_texture_set_texture_filter(RID p_canvas_texture, RS::CanvasItemTextureFilter p_filter) {
|
||||
CanvasTexture *ct = canvas_texture_owner.get_or_null(p_canvas_texture);
|
||||
ct->texture_filter = p_filter;
|
||||
}
|
||||
|
||||
void CanvasTextureStorage::canvas_texture_set_texture_repeat(RID p_canvas_texture, RS::CanvasItemTextureRepeat p_repeat) {
|
||||
CanvasTexture *ct = canvas_texture_owner.get_or_null(p_canvas_texture);
|
||||
ct->texture_repeat = p_repeat;
|
||||
}
|
||||
|
||||
#endif // !GLES3_ENABLED
|
||||
87
drivers/gles3/storage/canvas_texture_storage.h
Normal file
87
drivers/gles3/storage/canvas_texture_storage.h
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*************************************************************************/
|
||||
/* canvas_texture_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef CANVAS_TEXTURE_STORAGE_GLES3_H
|
||||
#define CANVAS_TEXTURE_STORAGE_GLES3_H
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/storage/canvas_texture_storage.h"
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
struct CanvasTexture {
|
||||
RID diffuse;
|
||||
RID normal_map;
|
||||
RID specular;
|
||||
Color specular_color = Color(1, 1, 1, 1);
|
||||
float shininess = 1.0;
|
||||
|
||||
RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;
|
||||
RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;
|
||||
|
||||
Size2i size_cache = Size2i(1, 1);
|
||||
bool use_normal_cache = false;
|
||||
bool use_specular_cache = false;
|
||||
bool cleared_cache = true;
|
||||
};
|
||||
|
||||
class CanvasTextureStorage : public RendererCanvasTextureStorage {
|
||||
private:
|
||||
static CanvasTextureStorage *singleton;
|
||||
|
||||
RID_Owner<CanvasTexture, true> canvas_texture_owner;
|
||||
|
||||
public:
|
||||
static CanvasTextureStorage *get_singleton();
|
||||
|
||||
CanvasTextureStorage();
|
||||
virtual ~CanvasTextureStorage();
|
||||
|
||||
CanvasTexture *get_canvas_texture(RID p_rid) { return canvas_texture_owner.get_or_null(p_rid); };
|
||||
bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); };
|
||||
|
||||
virtual RID canvas_texture_allocate() override;
|
||||
virtual void canvas_texture_initialize(RID p_rid) override;
|
||||
virtual void canvas_texture_free(RID p_rid) override;
|
||||
|
||||
virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override;
|
||||
virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override;
|
||||
|
||||
virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override;
|
||||
virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override;
|
||||
};
|
||||
|
||||
} // namespace GLES3
|
||||
|
||||
#endif // !GLES3_ENABLED
|
||||
|
||||
#endif // !CANVAS_TEXTURE_STORAGE_GLES3_H
|
||||
156
drivers/gles3/storage/config.cpp
Normal file
156
drivers/gles3/storage/config.cpp
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
/*************************************************************************/
|
||||
/* config.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "config.h"
|
||||
#include "core/templates/vector.h"
|
||||
|
||||
using namespace GLES3;
|
||||
|
||||
Config *Config::singleton = nullptr;
|
||||
|
||||
Config::Config() {
|
||||
singleton = this;
|
||||
should_orphan = true;
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
singleton = nullptr;
|
||||
}
|
||||
|
||||
void Config::initialize() {
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
keep_original_textures = true; // false
|
||||
shrink_textures_x2 = false;
|
||||
depth_internalformat = GL_DEPTH_COMPONENT;
|
||||
depth_type = GL_UNSIGNED_INT;
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
float_texture_supported = true;
|
||||
s3tc_supported = true;
|
||||
etc_supported = false;
|
||||
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");
|
||||
support_npot_repeat_mipmap = extensions.has("GL_OES_texture_npot");
|
||||
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
// RenderBuffer internal format must be 16 bits in WebGL,
|
||||
// but depth_texture should default to 32 always
|
||||
// if the implementation doesn't support 32, it should just quietly use 16 instead
|
||||
// https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/
|
||||
depth_buffer_internalformat = GL_DEPTH_COMPONENT16;
|
||||
depth_type = GL_UNSIGNED_INT;
|
||||
#else
|
||||
// on mobile check for 24 bit depth support for RenderBufferStorage
|
||||
if (extensions.has("GL_OES_depth24")) {
|
||||
depth_buffer_internalformat = _DEPTH_COMPONENT24_OES;
|
||||
depth_type = GL_UNSIGNED_INT;
|
||||
} else {
|
||||
depth_buffer_internalformat = GL_DEPTH_COMPONENT16;
|
||||
depth_type = GL_UNSIGNED_SHORT;
|
||||
}
|
||||
#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;
|
||||
support_depth_cubemaps = extensions.has("GL_OES_depth_texture_cube_map");
|
||||
#endif
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
support_32_bits_indices = true;
|
||||
#else
|
||||
support_32_bits_indices = extensions.has("GL_OES_element_index_uint");
|
||||
#endif
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
support_write_depth = true;
|
||||
#elif defined(JAVASCRIPT_ENABLED)
|
||||
support_write_depth = false;
|
||||
#else
|
||||
support_write_depth = extensions.has("GL_EXT_frag_depth");
|
||||
#endif
|
||||
|
||||
support_half_float_vertices = true;
|
||||
//every platform should support this except web, iOS has issues with their support, so add option to disable
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
support_half_float_vertices = false;
|
||||
#endif
|
||||
bool disable_half_float = false; //GLOBAL_GET("rendering/opengl/compatibility/disable_half_float");
|
||||
if (disable_half_float) {
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
#endif // GLES3_ENABLED
|
||||
113
drivers/gles3/storage/config.h
Normal file
113
drivers/gles3/storage/config.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*************************************************************************/
|
||||
/* config.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef CONFIG_GLES3_H
|
||||
#define CONFIG_GLES3_H
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/set.h"
|
||||
|
||||
// This must come first to avoid windows.h mess
|
||||
#include "platform_config.h"
|
||||
#ifndef OPENGL_INCLUDE_H
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include OPENGL_INCLUDE_H
|
||||
#endif
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
class Config {
|
||||
private:
|
||||
static Config *singleton;
|
||||
|
||||
public:
|
||||
bool shrink_textures_x2;
|
||||
bool use_fast_texture_filter;
|
||||
bool use_skeleton_software;
|
||||
|
||||
int max_vertex_texture_image_units;
|
||||
int max_texture_image_units;
|
||||
int max_texture_size;
|
||||
|
||||
// TODO implement wireframe in OpenGL
|
||||
// bool generate_wireframes;
|
||||
|
||||
Set<String> extensions;
|
||||
|
||||
bool float_texture_supported;
|
||||
bool s3tc_supported;
|
||||
bool latc_supported;
|
||||
bool rgtc_supported;
|
||||
bool bptc_supported;
|
||||
bool etc_supported;
|
||||
bool etc2_supported;
|
||||
bool srgb_decode_supported;
|
||||
|
||||
bool keep_original_textures;
|
||||
|
||||
bool force_vertex_shading;
|
||||
|
||||
bool use_rgba_2d_shadows;
|
||||
bool use_rgba_3d_shadows;
|
||||
|
||||
bool support_32_bits_indices;
|
||||
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;
|
||||
|
||||
GLuint depth_internalformat;
|
||||
GLuint depth_type;
|
||||
GLuint depth_buffer_internalformat;
|
||||
|
||||
// in some cases the legacy render didn't orphan. We will mark these
|
||||
// so the user can switch orphaning off for them.
|
||||
bool should_orphan = true;
|
||||
|
||||
static Config *get_singleton() { return singleton; };
|
||||
|
||||
Config();
|
||||
~Config();
|
||||
void initialize();
|
||||
};
|
||||
|
||||
} // namespace GLES3
|
||||
|
||||
#endif // GLES3_ENABLED
|
||||
|
||||
#endif // !CONFIG_GLES3_H
|
||||
132
drivers/gles3/storage/render_target_storage.h
Normal file
132
drivers/gles3/storage/render_target_storage.h
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/*************************************************************************/
|
||||
/* render_target_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RENDER_TARGET_STORAGE_GLES3_H
|
||||
#define RENDER_TARGET_STORAGE_GLES3_H
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "servers/rendering/renderer_storage.h" // included until we move stuff into storage/render_target_storage.h
|
||||
// #include "servers/rendering/storage/render_target_storage.h"
|
||||
|
||||
// This must come first to avoid windows.h mess
|
||||
#include "platform_config.h"
|
||||
#ifndef OPENGL_INCLUDE_H
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include OPENGL_INCLUDE_H
|
||||
#endif
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
// NOTE, this class currently is just a container for the the RenderTarget struct and is not yet implemented further, we'll do that next after we finish with TextureStorage
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Vector<Size> sizes;
|
||||
GLuint color = 0;
|
||||
int levels = 0;
|
||||
};
|
||||
|
||||
MipMaps mip_maps[2];
|
||||
|
||||
struct External {
|
||||
GLuint fbo = 0;
|
||||
GLuint color = 0;
|
||||
GLuint depth = 0;
|
||||
RID texture;
|
||||
} external;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
bool flags[RendererStorage::RENDER_TARGET_FLAG_MAX] = {};
|
||||
|
||||
// instead of allocating sized render targets immediately,
|
||||
// defer this for faster startup
|
||||
bool allocate_is_dirty = false;
|
||||
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;
|
||||
|
||||
RenderTarget() {
|
||||
for (int i = 0; i < RendererStorage::RENDER_TARGET_FLAG_MAX; ++i) {
|
||||
flags[i] = false;
|
||||
}
|
||||
external.fbo = 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace GLES3
|
||||
|
||||
#endif // !GLES3_ENABLED
|
||||
|
||||
#endif // !RENDER_TARGET_STORAGE_GLES3_H
|
||||
1211
drivers/gles3/storage/texture_storage.cpp
Normal file
1211
drivers/gles3/storage/texture_storage.cpp
Normal file
File diff suppressed because it is too large
Load diff
389
drivers/gles3/storage/texture_storage.h
Normal file
389
drivers/gles3/storage/texture_storage.h
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
/*************************************************************************/
|
||||
/* texture_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef TEXTURE_STORAGE_GLES3_H
|
||||
#define TEXTURE_STORAGE_GLES3_H
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "canvas_texture_storage.h"
|
||||
#include "config.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "render_target_storage.h"
|
||||
#include "servers/rendering/storage/texture_storage.h"
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
#define _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#define _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
|
||||
#define _EXT_COMPRESSED_RED_RGTC1_EXT 0x8DBB
|
||||
#define _EXT_COMPRESSED_RED_RGTC1 0x8DBB
|
||||
#define _EXT_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC
|
||||
#define _EXT_COMPRESSED_RG_RGTC2 0x8DBD
|
||||
#define _EXT_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE
|
||||
#define _EXT_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
|
||||
#define _EXT_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
|
||||
#define _EXT_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
|
||||
#define _EXT_ETC1_RGB8_OES 0x8D64
|
||||
|
||||
#define _EXT_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C
|
||||
#define _EXT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D
|
||||
#define _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E
|
||||
#define _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F
|
||||
|
||||
#define _GL_TEXTURE_EXTERNAL_OES 0x8D65
|
||||
|
||||
#ifdef GLES_OVER_GL
|
||||
#define _GL_HALF_FLOAT_OES 0x140B
|
||||
#else
|
||||
#define _GL_HALF_FLOAT_OES 0x8D61
|
||||
#endif
|
||||
|
||||
#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
|
||||
|
||||
#define _RED_OES 0x1903
|
||||
|
||||
#define _DEPTH_COMPONENT24_OES 0x81A6
|
||||
|
||||
#ifndef GLES_OVER_GL
|
||||
#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
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
RID self;
|
||||
|
||||
Texture *proxy;
|
||||
Set<Texture *> proxy_owners;
|
||||
|
||||
String path;
|
||||
uint32_t flags;
|
||||
int width, height, depth;
|
||||
int alloc_width, alloc_height;
|
||||
Image::Format format;
|
||||
RenderingDevice::TextureType type;
|
||||
|
||||
GLenum target;
|
||||
GLenum gl_format_cache;
|
||||
GLenum gl_internal_format_cache;
|
||||
GLenum gl_type_cache;
|
||||
|
||||
int data_size;
|
||||
int total_data_size;
|
||||
bool ignore_mipmaps;
|
||||
|
||||
bool compressed;
|
||||
|
||||
bool srgb;
|
||||
|
||||
int mipmaps;
|
||||
|
||||
bool resize_to_po2;
|
||||
|
||||
bool active;
|
||||
GLenum tex_id;
|
||||
|
||||
uint16_t stored_cube_sides;
|
||||
|
||||
RenderTarget *render_target;
|
||||
|
||||
Vector<Ref<Image>> images;
|
||||
|
||||
bool redraw_if_visible;
|
||||
|
||||
RS::TextureDetectCallback detect_3d;
|
||||
void *detect_3d_ud;
|
||||
|
||||
RS::TextureDetectCallback detect_srgb;
|
||||
void *detect_srgb_ud;
|
||||
|
||||
RS::TextureDetectCallback detect_normal;
|
||||
void *detect_normal_ud;
|
||||
|
||||
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;
|
||||
width = o.width;
|
||||
height = o.height;
|
||||
alloc_width = o.alloc_width;
|
||||
alloc_height = o.alloc_height;
|
||||
format = o.format;
|
||||
type = o.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;
|
||||
active = o.active;
|
||||
tex_id = o.tex_id;
|
||||
stored_cube_sides = o.stored_cube_sides;
|
||||
render_target = o.render_target;
|
||||
redraw_if_visible = o.redraw_if_visible;
|
||||
detect_3d = o.detect_3d;
|
||||
detect_3d_ud = o.detect_3d_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);
|
||||
}
|
||||
}
|
||||
|
||||
// texture state
|
||||
void GLSetFilter(GLenum p_target, RS::CanvasItemTextureFilter p_filter) {
|
||||
if (p_filter == state_filter) {
|
||||
return;
|
||||
}
|
||||
state_filter = p_filter;
|
||||
GLint pmin = GL_LINEAR; // param min
|
||||
GLint pmag = GL_LINEAR; // param mag
|
||||
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;
|
||||
} break;
|
||||
case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: {
|
||||
pmin = GL_NEAREST_MIPMAP_NEAREST;
|
||||
pmag = GL_NEAREST;
|
||||
} break;
|
||||
}
|
||||
glTexParameteri(p_target, GL_TEXTURE_MIN_FILTER, pmin);
|
||||
glTexParameteri(p_target, GL_TEXTURE_MAG_FILTER, pmag);
|
||||
}
|
||||
void GLSetRepeat(GLenum p_target, RS::CanvasItemTextureRepeat p_repeat) {
|
||||
if (p_repeat == state_repeat) {
|
||||
return;
|
||||
}
|
||||
state_repeat = p_repeat;
|
||||
GLint 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;
|
||||
}
|
||||
glTexParameteri(p_target, GL_TEXTURE_WRAP_S, prep);
|
||||
glTexParameteri(p_target, GL_TEXTURE_WRAP_T, prep);
|
||||
}
|
||||
|
||||
private:
|
||||
RS::CanvasItemTextureFilter state_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
|
||||
RS::CanvasItemTextureRepeat state_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
|
||||
};
|
||||
|
||||
class TextureStorage : public RendererTextureStorage {
|
||||
private:
|
||||
static TextureStorage *singleton;
|
||||
|
||||
Thread::ID _main_thread_id = 0;
|
||||
bool _is_main_thread();
|
||||
|
||||
mutable RID_PtrOwner<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);
|
||||
|
||||
public:
|
||||
static TextureStorage *get_singleton();
|
||||
|
||||
TextureStorage();
|
||||
virtual ~TextureStorage();
|
||||
|
||||
Texture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); };
|
||||
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;
|
||||
|
||||
virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override;
|
||||
virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override;
|
||||
virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override;
|
||||
virtual void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent
|
||||
|
||||
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{};
|
||||
|
||||
//these two APIs can be used together or in combination with the others.
|
||||
virtual void texture_2d_placeholder_initialize(RID p_texture) override;
|
||||
virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override;
|
||||
virtual void texture_3d_placeholder_initialize(RID p_texture) override;
|
||||
|
||||
virtual Ref<Image> texture_2d_get(RID p_texture) const override;
|
||||
virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); };
|
||||
virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); };
|
||||
|
||||
virtual void texture_replace(RID p_texture, RID p_by_texture) override;
|
||||
virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override;
|
||||
|
||||
virtual void texture_set_path(RID p_texture, const String &p_path) override;
|
||||
virtual String texture_get_path(RID p_texture) const override;
|
||||
|
||||
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_debug_usage(List<RS::TextureInfo> *r_info) override;
|
||||
|
||||
virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override;
|
||||
|
||||
virtual Size2 texture_size_with_proxy(RID p_proxy) override;
|
||||
|
||||
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;
|
||||
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);
|
||||
};
|
||||
|
||||
} // namespace GLES3
|
||||
|
||||
#endif // !GLES3_ENABLED
|
||||
|
||||
#endif // !TEXTURE_STORAGE_GLES3_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue