diff options
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 8 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 67 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 8 |
4 files changed, 43 insertions, 42 deletions
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index db814ec721..aa4150cbe4 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -271,9 +271,9 @@ void RasterizerGLES3::clear_render_target(const Color &p_color) { storage->frame.clear_request_color = p_color; } -void RasterizerGLES3::set_boot_image(const Image &p_image, const Color &p_color, bool p_scale) { +void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) { - if (p_image.empty()) + if (p_image.is_null() || p_image->empty()) return; begin_frame(); @@ -290,10 +290,10 @@ void RasterizerGLES3::set_boot_image(const Image &p_image, const Color &p_color, canvas->canvas_begin(); RID texture = storage->texture_create(); - storage->texture_allocate(texture, p_image.get_width(), p_image.get_height(), p_image.get_format(), VS::TEXTURE_FLAG_FILTER); + storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), p_image->get_format(), VS::TEXTURE_FLAG_FILTER); storage->texture_set_data(texture, p_image); - Rect2 imgrect(0, 0, p_image.get_width(), p_image.get_height()); + Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); Rect2 screenrect; if (p_scale) { diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h index 12014cd814..ce18d6b6c1 100644 --- a/drivers/gles3/rasterizer_gles3.h +++ b/drivers/gles3/rasterizer_gles3.h @@ -48,7 +48,7 @@ public: virtual RasterizerCanvas *get_canvas(); virtual RasterizerScene *get_scene(); - virtual void set_boot_image(const Image &p_image, const Color &p_color, bool p_scale); + virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale); virtual void initialize(); virtual void begin_frame(); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 1025acceb4..7db2f23d47 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -101,11 +101,11 @@ GLuint RasterizerStorageGLES3::system_fbo = 0; -Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) { +Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) { r_compressed = false; r_gl_format = 0; - Image image = p_image; + Ref<Image> image = p_image; srgb = false; bool need_decompress = false; @@ -538,16 +538,17 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image &p_image, Ima } break; default: { - ERR_FAIL_V(Image()); + ERR_FAIL_V(Ref<Image>()); } } if (need_decompress) { - if (!image.empty()) { - image.decompress(); - ERR_FAIL_COND_V(image.is_compressed(), image); - image.convert(Image::FORMAT_RGBA8); + if (!image.is_null()) { + image = image->duplicate(); + image->decompress(); + ERR_FAIL_COND_V(image->is_compressed(), image); + image->convert(Image::FORMAT_RGBA8); } r_gl_format = GL_RGBA; @@ -607,7 +608,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ texture->stored_cube_sides = 0; texture->target = (p_flags & VS::TEXTURE_FLAG_CUBEMAP) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; - _get_gl_image_and_format(Image(), texture->format, texture->flags, format, internal_format, type, compressed, srgb); + _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, format, internal_format, type, compressed, srgb); texture->alloc_width = texture->width; texture->alloc_height = texture->height; @@ -631,15 +632,15 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ texture->active = true; } -void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side) { +void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p_image, VS::CubeMapSide p_cube_side) { Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(!texture->active); ERR_FAIL_COND(texture->render_target); - ERR_FAIL_COND(texture->format != p_image.get_format()); - ERR_FAIL_COND(p_image.empty()); + ERR_FAIL_COND(texture->format != p_image->get_format()); + ERR_FAIL_COND(p_image.is_null()); GLenum type; GLenum format; @@ -651,31 +652,31 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_imag texture->images[p_cube_side] = p_image; } - Image img = _get_gl_image_and_format(p_image, p_image.get_format(), texture->flags, format, internal_format, type, compressed, srgb); + Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, format, internal_format, type, compressed, srgb); - if (config.shrink_textures_x2 && (p_image.has_mipmaps() || !p_image.is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { + if (config.shrink_textures_x2 && (p_image->has_mipmaps() || !p_image->is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { texture->alloc_height = MAX(1, texture->alloc_height / 2); texture->alloc_width = MAX(1, texture->alloc_width / 2); - if (texture->alloc_width == img.get_width() / 2 && texture->alloc_height == img.get_height() / 2) { + if (texture->alloc_width == img->get_width() / 2 && texture->alloc_height == img->get_height() / 2) { - img.shrink_x2(); - } else if (img.get_format() <= Image::FORMAT_RGB565) { + img->shrink_x2(); + } else if (img->get_format() <= Image::FORMAT_RGB565) { - img.resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR); + img->resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR); } }; GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP) ? _cube_side_enum[p_cube_side] : GL_TEXTURE_2D; - texture->data_size = img.get_data().size(); - PoolVector<uint8_t>::Read read = img.get_data().read(); + texture->data_size = img->get_data().size(); + PoolVector<uint8_t>::Read read = img->get_data().read(); glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target, texture->tex_id); - texture->ignore_mipmaps = compressed && !img.has_mipmaps(); + texture->ignore_mipmaps = compressed && !img->has_mipmaps(); if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); @@ -761,16 +762,16 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_imag } } - int mipmaps = (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && img.has_mipmaps()) ? img.get_mipmap_count() + 1 : 1; + int mipmaps = (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && img->has_mipmaps()) ? img->get_mipmap_count() + 1 : 1; - int w = img.get_width(); - int h = img.get_height(); + int w = img->get_width(); + int h = img->get_height(); int tsize = 0; for (int i = 0; i < mipmaps; i++) { int size, ofs; - img.get_mipmap_offset_and_size(i, ofs, size); + img->get_mipmap_offset_and_size(i, ofs, size); //print_line("mipmap: "+itos(i)+" size: "+itos(size)+" w: "+itos(mm_w)+", h: "+itos(mm_h)); @@ -813,16 +814,16 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_imag //texture_set_flags(p_texture,texture->flags); } -Image RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const { +Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const { Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture, Image()); - ERR_FAIL_COND_V(!texture->active, Image()); - ERR_FAIL_COND_V(texture->data_size == 0, Image()); - ERR_FAIL_COND_V(texture->render_target, Image()); + ERR_FAIL_COND_V(!texture, Ref<Image>()); + ERR_FAIL_COND_V(!texture->active, Ref<Image>()); + ERR_FAIL_COND_V(texture->data_size == 0, Ref<Image>()); + ERR_FAIL_COND_V(texture->render_target, Ref<Image>()); - if (!texture->images[p_cube_side].empty()) { + if (!texture->images[p_cube_side].is_null()) { return texture->images[p_cube_side]; } @@ -867,13 +868,13 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_ data.resize(data_size); - Image img(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data); + Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data)); - return img; + return Ref<Image>(img); #else ERR_EXPLAIN("Sorry, It's not posible to obtain images back in OpenGL ES"); - return Image(); + return Ref<Image>(); #endif } diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index bb4a7e23a1..c700b7cb1c 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -240,7 +240,7 @@ public: RenderTarget *render_target; - Image images[6]; + Ref<Image> images[6]; VisualServer::TextureDetectCallback detect_3d; void *detect_3d_ud; @@ -280,12 +280,12 @@ public: mutable RID_Owner<Texture> texture_owner; - Image _get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb); + Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb); virtual RID texture_create(); virtual void texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT); - virtual void texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT); - virtual Image texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) const; + virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT); + virtual Ref<Image> texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) const; virtual void texture_set_flags(RID p_texture, uint32_t p_flags); virtual uint32_t texture_get_flags(RID p_texture) const; virtual Image::Format texture_get_format(RID p_texture) const; |