diff options
Diffstat (limited to 'drivers/gles2')
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.cpp | 242 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.h | 2 |
2 files changed, 226 insertions, 18 deletions
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 3ab9dfc5e7..d5965bba4f 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -44,8 +44,31 @@ GLuint RasterizerStorageGLES2::system_fbo = 0; #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_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 + +#define _EXT_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54 +#define _EXT_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55 +#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56 +#define _EXT_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57 + +#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 + #ifdef GLES_OVER_GL #define _GL_HALF_FLOAT_OES 0x140B #else @@ -231,41 +254,130 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ } break; case Image::FORMAT_RGTC_R: { - need_decompress = true; + if (config.rgtc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RED_RGTC1_EXT; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + + } else { + + need_decompress = true; + } } break; case Image::FORMAT_RGTC_RG: { - need_decompress = true; + if (config.rgtc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RED_GREEN_RGTC2_EXT; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + } else { + + need_decompress = true; + } } break; case Image::FORMAT_BPTC_RGBA: { - need_decompress = true; + if (config.bptc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RGBA_BPTC_UNORM; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + + } else { + + need_decompress = true; + } } break; case Image::FORMAT_BPTC_RGBF: { - need_decompress = true; + if (config.bptc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT; + r_gl_format = GL_RGB; + r_gl_type = GL_FLOAT; + r_compressed = true; + } else { + + need_decompress = true; + } } break; case Image::FORMAT_BPTC_RGBFU: { + if (config.bptc_supported) { - need_decompress = true; + r_gl_internal_format = _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT; + r_gl_format = GL_RGB; + r_gl_type = GL_FLOAT; + r_compressed = true; + } else { + + need_decompress = true; + } } break; case Image::FORMAT_PVRTC2: { - need_decompress = true; + if (config.pvrtc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + + } else { + + need_decompress = true; + } } break; case Image::FORMAT_PVRTC2A: { - need_decompress = true; + if (config.pvrtc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + + } else { + + need_decompress = true; + } + } break; case Image::FORMAT_PVRTC4: { - need_decompress = true; + if (config.pvrtc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + + } else { + + need_decompress = true; + } + } break; case Image::FORMAT_PVRTC4A: { - need_decompress = true; + if (config.pvrtc_supported) { + + r_gl_internal_format = _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + r_gl_format = GL_RGBA; + r_gl_type = GL_UNSIGNED_BYTE; + r_compressed = true; + + } else { + + need_decompress = true; + } + } break; case Image::FORMAT_ETC: { @@ -1223,8 +1335,6 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { switch (p_shader->mode) { - // TODO - case VS::SHADER_CANVAS_ITEM: { p_shader->canvas_item.light_mode = Shader::CanvasItem::LIGHT_MODE_NORMAL; @@ -2542,16 +2652,110 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { if (mesh->custom_aabb != AABB()) return mesh->custom_aabb; - // TODO handle skeletons + Skeleton *sk = NULL; + if (p_skeleton.is_valid()) { + sk = skeleton_owner.get(p_skeleton); + } AABB aabb; - if (mesh->surfaces.size() >= 1) { - aabb = mesh->surfaces[0]->aabb; - } + if (sk && sk->size != 0) { + + for (int i = 0; i < mesh->surfaces.size(); i++) { + + AABB laabb; + if ((mesh->surfaces[i]->format & VS::ARRAY_FORMAT_BONES) && mesh->surfaces[i]->skeleton_bone_aabb.size()) { + + int bs = mesh->surfaces[i]->skeleton_bone_aabb.size(); + const AABB *skbones = mesh->surfaces[i]->skeleton_bone_aabb.ptr(); + const bool *skused = mesh->surfaces[i]->skeleton_bone_used.ptr(); + + int sbs = sk->size; + ERR_CONTINUE(bs > sbs); + const float *texture = sk->bone_data.ptr(); - for (int i = 0; i < mesh->surfaces.size(); i++) { - aabb.merge_with(mesh->surfaces[i]->aabb); + bool first = true; + if (sk->use_2d) { + for (int j = 0; j < bs; j++) { + + if (!skused[j]) + continue; + + int base_ofs = j * 2 * 4; + + Transform mtx; + + mtx.basis[0].x = texture[base_ofs + 0]; + mtx.basis[0].y = texture[base_ofs + 1]; + mtx.origin.x = texture[base_ofs + 3]; + base_ofs += 256 * 4; + mtx.basis[1].x = texture[base_ofs + 0]; + mtx.basis[1].y = texture[base_ofs + 1]; + mtx.origin.y = texture[base_ofs + 3]; + + AABB baabb = mtx.xform(skbones[j]); + + if (first) { + laabb = baabb; + first = false; + } else { + laabb.merge_with(baabb); + } + } + } else { + for (int j = 0; j < bs; j++) { + + if (!skused[j]) + continue; + + int base_ofs = j * 3 * 4; + + Transform mtx; + + mtx.basis[0].x = texture[base_ofs + 0]; + mtx.basis[0].y = texture[base_ofs + 1]; + mtx.basis[0].z = texture[base_ofs + 2]; + mtx.origin.x = texture[base_ofs + 3]; + base_ofs += 256 * 4; + mtx.basis[1].x = texture[base_ofs + 0]; + mtx.basis[1].y = texture[base_ofs + 1]; + mtx.basis[1].z = texture[base_ofs + 2]; + mtx.origin.y = texture[base_ofs + 3]; + base_ofs += 256 * 4; + mtx.basis[2].x = texture[base_ofs + 0]; + mtx.basis[2].y = texture[base_ofs + 1]; + mtx.basis[2].z = texture[base_ofs + 2]; + mtx.origin.z = texture[base_ofs + 3]; + + AABB baabb = mtx.xform(skbones[j]); + if (first) { + laabb = baabb; + first = false; + } else { + laabb.merge_with(baabb); + } + } + } + + } else { + + laabb = mesh->surfaces[i]->aabb; + } + + if (i == 0) + aabb = laabb; + else + aabb.merge_with(laabb); + } + } else { + + for (int i = 0; i < mesh->surfaces.size(); i++) { + + if (i == 0) + aabb = mesh->surfaces[i]->aabb; + else + aabb.merge_with(mesh->surfaces[i]->aabb); + } } return aabb; @@ -3245,7 +3449,6 @@ void RasterizerStorageGLES2::skeleton_allocate(RID p_skeleton, int p_bones, bool skeleton->size = p_bones; skeleton->use_2d = p_2d_skeleton; - // TODO use float texture for vertex shader if (config.float_texture_supported) { glGenTextures(1, &skeleton->tex_id); @@ -5048,6 +5251,9 @@ void RasterizerStorageGLES2::initialize() { config.support_half_float_vertices = true; #endif + config.rgtc_supported = config.extensions.has("GL_EXT_texture_compression_rgtc") || config.extensions.has("GL_ARB_texture_compression_rgtc") || config.extensions.has("EXT_texture_compression_rgtc"); + config.bptc_supported = config.extensions.has("GL_ARB_texture_compression_bptc"); + //determine formats for depth textures (or renderbuffers) if (config.support_depth_texture) { // Will use texture for depth diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index cad3af200e..e6c23716a5 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -73,6 +73,8 @@ public: bool s3tc_supported; bool etc1_supported; bool pvrtc_supported; + bool rgtc_supported; + bool bptc_supported; bool keep_original_textures; |