-Remove harcoded opengl extension testing from OS, ask rasterizer instead.

-Fixed a bug where etc textures were imported broken
This commit is contained in:
Juan Linietsky 2019-02-26 11:58:47 -03:00
parent 3299045988
commit 5eeb06ffd1
14 changed files with 41 additions and 18 deletions

View file

@ -569,6 +569,11 @@ int OS::get_power_percent_left() {
return -1;
}
void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
has_server_feature_callback = p_callback;
}
bool OS::has_feature(const String &p_feature) {
if (p_feature == get_name())
@ -625,6 +630,10 @@ bool OS::has_feature(const String &p_feature) {
if (_check_internal_feature_support(p_feature))
return true;
if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
return true;
}
if (ProjectSettings::get_singleton()->has_custom_feature(p_feature))
return true;
@ -729,6 +738,8 @@ OS::OS() {
_logger = NULL;
has_server_feature_callback = NULL;
Vector<Logger *> loggers;
loggers.push_back(memnew(StdLogger));
_set_logger(memnew(CompositeLogger(loggers)));

View file

@ -77,6 +77,7 @@ protected:
public:
typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection);
typedef bool (*HasServerFeatureCallback)(const String &p_feature);
enum PowerState {
POWERSTATE_UNKNOWN, /**< cannot determine power status */
@ -121,6 +122,7 @@ public:
protected:
friend class Main;
HasServerFeatureCallback has_server_feature_callback;
RenderThreadMode _render_thread_mode;
// functions used by main to initialize/deinitialize the OS
@ -507,6 +509,8 @@ public:
virtual void force_process_input(){};
bool has_feature(const String &p_feature);
void set_has_server_feature_callback(HasServerFeatureCallback p_callback);
bool is_layered_allowed() const { return _allow_layered; }
bool is_hidpi_allowed() const { return _allow_hidpi; }

View file

@ -4922,6 +4922,9 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
bool RasterizerStorageGLES2::has_os_feature(const String &p_feature) const {
if (p_feature == "pvrtc")
return config.pvrtc_supported;
if (p_feature == "s3tc")
return config.s3tc_supported;
@ -4971,12 +4974,14 @@ void RasterizerStorageGLES2::initialize() {
#ifdef GLES_OVER_GL
config.float_texture_supported = true;
config.s3tc_supported = true;
config.pvrtc_supported = false;
config.etc1_supported = false;
config.support_npot_repeat_mipmap = true;
#else
config.float_texture_supported = config.extensions.has("GL_ARB_texture_float") || config.extensions.has("GL_OES_texture_float");
config.s3tc_supported = config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc");
config.etc1_supported = config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture") || config.extensions.has("WEBGL_compressed_texture_etc1");
config.pvrtc_supported = config.extensions.has("IMG_texture_compression_pvrtc");
config.support_npot_repeat_mipmap = config.extensions.has("GL_OES_texture_npot");
#endif

View file

@ -72,6 +72,7 @@ public:
bool float_texture_supported;
bool s3tc_supported;
bool etc1_supported;
bool pvrtc_supported;
bool keep_original_textures;

View file

@ -235,7 +235,6 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
f->store_16(p_image->get_width());
f->store_16(next_power_of_2(p_image->get_height()));
f->store_16(p_image->get_height());
f->store_16(0);
} else {
f->store_16(p_image->get_width());
f->store_16(0);

View file

@ -706,7 +706,7 @@ String OS_Android::get_joy_guid(int p_device) const {
}
bool OS_Android::_check_internal_feature_support(const String &p_feature) {
if (p_feature == "mobile" || p_feature == "etc" || p_feature == "etc2") {
if (p_feature == "mobile") {
//TODO support etc2 only if GLES3 driver is selected
return true;
}

View file

@ -322,7 +322,7 @@ String OS_Haiku::get_executable_path() const {
bool OS_Haiku::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc" || p_feature == "s3tc";
return p_feature == "pc";
}
String OS_Haiku::get_config_path() const {

View file

@ -587,7 +587,7 @@ void OSIPhone::native_video_stop() {
bool OSIPhone::_check_internal_feature_support(const String &p_feature) {
return p_feature == "mobile" || p_feature == "etc" || p_feature == "pvrtc" || p_feature == "etc2";
return p_feature == "mobile";
}
// Initialization order between compilation units is not guaranteed,

View file

@ -1071,16 +1071,6 @@ bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
return true;
#endif
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();
// All extensions are already automatically enabled, this function allows
// checking WebGL extension support without inline JavaScript
if (p_feature == "s3tc")
return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_s3tc_srgb");
if (p_feature == "etc")
return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc1");
if (p_feature == "etc2")
return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc");
return false;
}

View file

@ -2812,7 +2812,7 @@ OS_OSX::OS_OSX() {
}
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc" || p_feature == "s3tc";
return p_feature == "pc";
}
void OS_OSX::disable_crash_handler() {

View file

@ -889,7 +889,7 @@ String OS_UWP::get_user_data_dir() const {
}
bool OS_UWP::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc" || p_feature == "s3tc";
return p_feature == "pc";
}
OS::PowerState OS_UWP::get_power_state() {

View file

@ -2976,7 +2976,7 @@ int OS_Windows::get_power_percent_left() {
bool OS_Windows::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc" || p_feature == "s3tc" || p_feature == "bptc";
return p_feature == "pc";
}
void OS_Windows::disable_crash_handler() {

View file

@ -2593,7 +2593,7 @@ Error OS_X11::shell_open(String p_uri) {
bool OS_X11::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc" || p_feature == "s3tc" || p_feature == "bptc";
return p_feature == "pc";
}
String OS_X11::get_config_path() const {

View file

@ -88,8 +88,21 @@ Physics2DServer *_createGodotPhysics2DCallback() {
return Physics2DServerWrapMT::init_server<Physics2DServerSW>();
}
static bool has_server_feature_callback(const String &p_feature) {
if (VisualServer::get_singleton()) {
if (VisualServer::get_singleton()->has_os_feature(p_feature)) {
return true;
}
}
return false;
}
void register_server_types() {
OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback);
ClassDB::register_virtual_class<VisualServer>();
ClassDB::register_class<AudioServer>();
ClassDB::register_virtual_class<PhysicsServer>();