Fix working using OpenGLES / ANGLE.

This commit is contained in:
John Preston 2021-06-14 12:13:33 +04:00
parent b600b6a3b3
commit 27e9e349bf
2 changed files with 25 additions and 9 deletions

View file

@ -76,8 +76,12 @@ Capabilities CheckCapabilities(QWidget *widget) {
const auto supported = context->format(); const auto supported = context->format();
switch (supported.profile()) { switch (supported.profile()) {
case QSurfaceFormat::NoProfile: { case QSurfaceFormat::NoProfile: {
LOG_ONCE(("OpenGL Profile: None.")); if (supported.renderableType() == QSurfaceFormat::OpenGLES) {
return {}; LOG_ONCE(("OpenGL Profile: OpenGLES."));
} else {
LOG_ONCE(("OpenGL Profile: None."));
return {};
}
} break; } break;
case QSurfaceFormat::CoreProfile: { case QSurfaceFormat::CoreProfile: {
LOG_ONCE(("OpenGL Profile: Core.")); LOG_ONCE(("OpenGL Profile: Core."));

View file

@ -8,14 +8,25 @@
#include "base/debug_log.h" #include "base/debug_log.h"
#include <QtGui/QOpenGLContext>
namespace Ui::GL { namespace Ui::GL {
[[nodiscard]] bool IsOpenGLES() {
const auto current = QOpenGLContext::currentContext();
Assert(current != nullptr);
return (current->format().renderableType() == QSurfaceFormat::OpenGLES);
}
QString VertexShader(const std::vector<ShaderPart> &parts) { QString VertexShader(const std::vector<ShaderPart> &parts) {
const auto version = IsOpenGLES()
? QString("#version 100\nprecision highp float;\n")
: QString("#version 120\n");
const auto accumulate = [&](auto proj) { const auto accumulate = [&](auto proj) {
return ranges::accumulate(parts, QString(), std::plus<>(), proj); return ranges::accumulate(parts, QString(), std::plus<>(), proj);
}; };
return R"( return version + R"(
#version 120
attribute vec2 position; attribute vec2 position;
)" + accumulate(&ShaderPart::header) + R"( )" + accumulate(&ShaderPart::header) + R"(
void main() { void main() {
@ -27,12 +38,13 @@ void main() {
} }
QString FragmentShader(const std::vector<ShaderPart> &parts) { QString FragmentShader(const std::vector<ShaderPart> &parts) {
const auto version = IsOpenGLES()
? QString("#version 100\nprecision highp float;\n")
: QString("#version 120\n");
const auto accumulate = [&](auto proj) { const auto accumulate = [&](auto proj) {
return ranges::accumulate(parts, QString(), std::plus<>(), proj); return ranges::accumulate(parts, QString(), std::plus<>(), proj);
}; };
return R"( return version + accumulate(&ShaderPart::header) + R"(
#version 120
)" + accumulate(&ShaderPart::header) + R"(
void main() { void main() {
vec4 result = vec4(0., 0., 0., 0.); vec4 result = vec4(0., 0., 0., 0.);
)" + accumulate(&ShaderPart::body) + R"( )" + accumulate(&ShaderPart::body) + R"(
@ -103,7 +115,7 @@ ShaderPart VertexViewportTransform() {
uniform vec2 viewport; uniform vec2 viewport;
vec4 transform(vec4 position) { vec4 transform(vec4 position) {
return vec4( return vec4(
vec2(-1, -1) + 2 * position.xy / viewport, vec2(-1, -1) + 2. * position.xy / viewport,
position.z, position.z,
position.w); position.w);
} }
@ -122,7 +134,7 @@ uniform vec2 radiusOutline;
uniform vec4 roundBg; uniform vec4 roundBg;
uniform vec4 outlineFg; uniform vec4 outlineFg;
vec2 roundedCorner() { vec2 roundedCorner() {
vec2 rectHalf = roundRect.zw / 2; vec2 rectHalf = roundRect.zw / 2.;
vec2 rectCenter = roundRect.xy + rectHalf; vec2 rectCenter = roundRect.xy + rectHalf;
vec2 fromRectCenter = abs(gl_FragCoord.xy - rectCenter); vec2 fromRectCenter = abs(gl_FragCoord.xy - rectCenter);
vec2 vectorRadius = radiusOutline.xx + vec2(0.5, 0.5); vec2 vectorRadius = radiusOutline.xx + vec2(0.5, 0.5);