Support OpenGL 3 (#13321)

This commit is contained in:
Vitaliy 2024-01-16 23:09:18 +03:00 committed by GitHub
parent 9cca12ff0b
commit 8093044f07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 26 additions and 22 deletions

View File

@ -312,7 +312,7 @@ local function check_requirements(name, requires)
end
local video_driver = core.get_active_driver()
local shaders_support = video_driver == "opengl" or video_driver == "ogles2"
local shaders_support = video_driver == "opengl" or video_driver == "opengl3" or video_driver == "ogles2"
local special = {
android = PLATFORM == "Android",
desktop = PLATFORM ~= "Android",

View File

@ -440,7 +440,6 @@ enable_raytraced_culling (Enable Raytraced Culling) bool true
# Shaders allow advanced visual effects and may increase performance on some video
# cards.
# This only works with the OpenGL video backend.
#
# Requires: shaders_support
enable_shaders (Shaders) bool true
@ -1798,8 +1797,8 @@ shader_path (Shader path) path
# The rendering back-end.
# Note: A restart is required after changing this!
# OpenGL is the default for desktop, and OGLES2 for Android.
# Shaders are supported by OpenGL and OGLES2 (experimental).
video_driver (Video driver) enum ,opengl,ogles1,ogles2
# Shaders are supported by everything but OGLES1.
video_driver (Video driver) enum ,opengl,opengl3,ogles1,ogles2
# Distance in nodes at which transparency depth sorting is enabled
# Use this to limit the performance impact of transparency depth sorting

View File

@ -14,7 +14,7 @@ centroid varying vec2 varTexCoord;
// smoothstep - squared
float smstsq(float f)
{
f = f * f * (3 - 2 * f);
f = f * f * (3. - 2. * f);
return f;
}

View File

@ -14,7 +14,7 @@ centroid varying vec2 varTexCoord;
// smoothstep - squared
float smstsq(float f)
{
f = f * f * (3 - 2 * f);
f = f * f * (3. - 2. * f);
return f;
}

View File

@ -161,7 +161,7 @@ float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDist
float depth_to_blur = f_shadowfar / SOFTSHADOWRADIUS / xyPerspectiveBias0;
if (depth > 0.0 && f_normal_length > 0.0)
// 5 is empirical factor that controls how fast shadow loses sharpness
sharpness_factor = clamp(5 * depth * depth_to_blur, 0.0, 1.0);
sharpness_factor = clamp(5.0 * depth * depth_to_blur, 0.0, 1.0);
depth = 0.0;
float world_to_texture = xyPerspectiveBias1 / perspective_factor / perspective_factor

View File

@ -242,7 +242,7 @@ void main(void)
if (f_normal_length > 0.0) {
nNormal = normalize(vNormal);
cosLight = max(1e-5, dot(nNormal, -v_LightDirection));
float sinLight = pow(1 - pow(cosLight, 2.0), 0.5);
float sinLight = pow(1.0 - pow(cosLight, 2.0), 0.5);
normalOffsetScale = 2.0 * pFactor * pFactor * sinLight * min(f_shadowfar, 500.0) /
xyPerspectiveBias1 / f_textureresolution;
z_bias = 1.0 * sinLight / cosLight;
@ -250,7 +250,7 @@ void main(void)
else {
nNormal = vec3(0.0);
cosLight = clamp(dot(v_LightDirection, normalize(vec3(v_LightDirection.x, 0.0, v_LightDirection.z))), 1e-2, 1.0);
float sinLight = pow(1 - pow(cosLight, 2.0), 0.5);
float sinLight = pow(1.0 - pow(cosLight, 2.0), 0.5);
normalOffsetScale = 0.0;
z_bias = 3.6e3 * sinLight / cosLight;
}

View File

@ -147,7 +147,7 @@ void main(void)
if (f_normal_length > 0.0) {
nNormal = normalize(vNormal);
cosLight = max(1e-5, dot(nNormal, -v_LightDirection));
float sinLight = pow(1 - pow(cosLight, 2.0), 0.5);
float sinLight = pow(1.0 - pow(cosLight, 2.0), 0.5);
normalOffsetScale = 0.1 * pFactor * pFactor * sinLight * min(f_shadowfar, 500.0) /
xyPerspectiveBias1 / f_textureresolution;
z_bias = 1e3 * sinLight / cosLight * (0.5 + f_textureresolution / 1024.0);
@ -155,7 +155,7 @@ void main(void)
else {
nNormal = vec3(0.0);
cosLight = clamp(dot(v_LightDirection, normalize(vec3(v_LightDirection.x, 0.0, v_LightDirection.z))), 1e-2, 1.0);
float sinLight = pow(1 - pow(cosLight, 2.0), 0.5);
float sinLight = pow(1.0 - pow(cosLight, 2.0), 0.5);
normalOffsetScale = 0.0;
z_bias = 3.6e3 * sinLight / cosLight;
}

View File

@ -215,7 +215,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
m_rendering_engine->get_raw_device()->
setWindowCaption((utf8_to_wide(PROJECT_NAME_C) +
L" " + utf8_to_wide(g_version_hash) +
L" [" + wstrgettext("Main Menu") + L"]").c_str());
L" [" + wstrgettext("Main Menu") + L"]" +
L" [" + m_rendering_engine->getVideoDriver()->getName() + L"]" ).c_str());
try { // This is used for catching disconnects

View File

@ -292,15 +292,16 @@ std::vector<video::E_DRIVER_TYPE> RenderingEngine::getSupportedVideoDrivers()
// Order by preference (best first)
static const video::E_DRIVER_TYPE glDrivers[] = {
video::EDT_OPENGL,
video::EDT_OPENGL3,
video::EDT_OGLES2,
video::EDT_OGLES1,
video::EDT_NULL,
};
std::vector<video::E_DRIVER_TYPE> drivers;
for (u32 i = 0; i < ARRLEN(glDrivers); i++) {
if (IrrlichtDevice::isDriverSupported(glDrivers[i]))
drivers.push_back(glDrivers[i]);
for (video::E_DRIVER_TYPE driver: glDrivers) {
if (IrrlichtDevice::isDriverSupported(driver))
drivers.push_back(driver);
}
return drivers;
@ -328,6 +329,7 @@ const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_
static const std::unordered_map<int, VideoDriverInfo> driver_info_map = {
{(int)video::EDT_NULL, {"null", "NULL Driver"}},
{(int)video::EDT_OPENGL, {"opengl", "OpenGL"}},
{(int)video::EDT_OPENGL3, {"opengl3", "OpenGL 3+"}},
{(int)video::EDT_OGLES1, {"ogles1", "OpenGL ES1"}},
{(int)video::EDT_OGLES2, {"ogles2", "OpenGL ES2"}},
};

View File

@ -261,7 +261,7 @@ public:
worldViewProj *= worldView;
m_world_view_proj.set(*reinterpret_cast<float(*)[16]>(worldViewProj.pointer()), services);
if (driver->getDriverType() == video::EDT_OGLES2) {
if (driver->getDriverType() == video::EDT_OGLES2 || driver->getDriverType() == video::EDT_OPENGL3) {
core::matrix4 texture = driver->getTransform(video::ETS_TEXTURE_0);
m_world_view.set(*reinterpret_cast<float(*)[16]>(worldView.pointer()), services);
m_texture.set(*reinterpret_cast<float(*)[16]>(texture.pointer()), services);
@ -594,17 +594,19 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices();
// Create shaders header
bool use_gles = driver->getDriverType() == video::EDT_OGLES2;
bool fully_programmable = driver->getDriverType() == video::EDT_OGLES2 || driver->getDriverType() == video::EDT_OPENGL3;
std::stringstream shaders_header;
shaders_header
<< std::noboolalpha
<< std::showpoint // for GLSL ES
;
std::string vertex_header, fragment_header, geometry_header;
if (use_gles) {
shaders_header << R"(
#version 100
)";
if (fully_programmable) {
if (driver->getDriverType() == video::EDT_OPENGL3) {
shaders_header << "#version 150\n";
} else {
shaders_header << "#version 100\n";
}
vertex_header = R"(
precision mediump float;
@ -658,7 +660,7 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
abort();
}
bool use_discard = use_gles;
bool use_discard = fully_programmable;
// For renderers that should use discard instead of GL_ALPHA_TEST
const char *renderer = reinterpret_cast<const char*>(GL.GetString(GL.RENDERER));
if (strstr(renderer, "GC7000"))