Skip to content

Commit

Permalink
MythRenderOpenGL: Initial core profile support
Browse files Browse the repository at this point in the history
- preparatory work for compute shader support
- no need to enable textures for GLSL (compatiblity or core profiles)
- add an environment var to force a core profile that should ensure
compute shader availability
- create a 'global' vertex array object that is a requirement for core
profiles. This should/will be extended to full VAO support at some point
but this ensures rendering works for now
  • Loading branch information
mark-kendall committed Jul 1, 2019
1 parent 5b752e4 commit d652f7b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/mythvideotexture.cpp
Expand Up @@ -619,7 +619,6 @@ MythVideoTexture* MythVideoTexture::CreateHelperTexture(MythRenderOpenGL *Contex
StoreBicubicWeights(0, buf);
StoreBicubicWeights(1, &buf[(width - 1) << 2]);

Context->EnableTextures();
texture->m_texture->bind();
texture->m_texture->setData(texture->m_pixelFormat, texture->m_pixelType, buf);
LOG(VB_PLAYBACK, LOG_INFO, LOC +
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/mythvtbinterop.cpp
Expand Up @@ -258,7 +258,6 @@ vector<MythVideoTexture*> MythVTBSurfaceInterop::Acquire(MythRenderOpenGL *Conte
if (!texture)
continue;
texture->m_allowGLSLDeint = true;
m_context->EnableTextures(QOpenGLTexture::TargetRectangle);
m_context->glBindTexture(texture->m_target, texture->m_textureId);

GLenum format = (plane == 0) ? QOpenGLTexture::Red : QOpenGLTexture::RG;;
Expand Down
74 changes: 45 additions & 29 deletions mythtv/libs/libmythui/mythrender_opengl.cpp
Expand Up @@ -8,6 +8,7 @@ using std::min;
#include <QWindow>
#include <QWidget>
#include <QGuiApplication>
#include <QOpenGLFunctions_3_2_Core>

// MythTV
#include "mythcorecontext.h"
Expand Down Expand Up @@ -91,10 +92,27 @@ MythRenderOpenGL* MythRenderOpenGL::Create(const QString&, QPaintDevice* Device)
return nullptr;
}

QSurfaceFormat format = QSurfaceFormat::defaultFormat();
// N.B the core profiles below are designed to target compute shader availability
bool opengles = !qgetenv("USE_OPENGLES").isEmpty();
bool core = !qgetenv("USE_OPENGLCORE").isEmpty();
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
if (core)
{
format.setProfile(QSurfaceFormat::CoreProfile);
format.setMajorVersion(4);
format.setMinorVersion(3);
}

if (opengles)
{
if (core)
{
format.setProfile(QSurfaceFormat::CoreProfile);
format.setMajorVersion(3);
format.setMinorVersion(1);
}
format.setRenderableType(QSurfaceFormat::OpenGLES);
}

if (VERBOSE_LEVEL_CHECK(VB_GPU, LOG_INFO))
format.setOption(QSurfaceFormat::DebugContext);
Expand Down Expand Up @@ -137,9 +155,9 @@ MythRenderOpenGL::MythRenderOpenGL(const QSurfaceFormat& Format, QPaintDevice* D
m_maxTextureSize(0),
m_maxTextureUnits(0),
m_colorDepth(0),
m_coreProfile(false),
m_viewport(),
m_activeTexture(0),
m_activeTextureTarget(0),
m_blend(false),
m_background(0x00000000),
m_fullRange(gCoreContext->GetBoolSetting("GUIRGBLevels", true)),
Expand All @@ -148,6 +166,7 @@ MythRenderOpenGL::MythRenderOpenGL(const QSurfaceFormat& Format, QPaintDevice* D
m_parameters(),
m_cachedMatrixUniforms(),
m_cachedUniformLocations(),
m_vao(0),
m_flushEnabled(true),
m_openglDebugger(nullptr),
m_window(nullptr)
Expand All @@ -170,6 +189,14 @@ MythRenderOpenGL::~MythRenderOpenGL()
LOG(VB_GENERAL, LOG_INFO, LOC + "MythRenderOpenGL closing");
if (!isValid())
return;

if (m_coreProfile && m_vao)
{
QOpenGLFunctions_3_2_Core* core = versionFunctions<QOpenGLFunctions_3_2_Core>();
if (core)
core->glDeleteVertexArrays(1, &m_vao);
}

disconnect(this, &QOpenGLContext::aboutToBeDestroyed, this, &MythRenderOpenGL::contextToBeDestroyed);
ReleaseResources();
}
Expand Down Expand Up @@ -295,6 +322,21 @@ bool MythRenderOpenGL::Init(void)
if (!isOpenGLES() || (isOpenGLES() && ((fmt.majorVersion() >= 3) || hasExtension("GL_EXT_unpack_subimage"))))
m_extraFeatures |= kGLExtSubimage;

// check for core profile
m_coreProfile = fmt.profile() == QSurfaceFormat::OpenGLContextProfile::CoreProfile;

// if we have a core profile then we need a VAO bound - this is just a
// workaround for the time being
if (m_coreProfile)
{
QOpenGLFunctions_3_2_Core* core = versionFunctions<QOpenGLFunctions_3_2_Core>();
if (core)
{
core->glGenVertexArrays(1, &m_vao);
core->glBindVertexArray(m_vao);
}
}

DebugFeatures();

m_extraFeaturesUsed = m_extraFeatures;
Expand Down Expand Up @@ -343,6 +385,7 @@ void MythRenderOpenGL::DebugFeatures(void)
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Buffer mapping : %1").arg(GLYesNo(m_extraFeatures & kGLBufferMap)));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Framebuffer objects : %1").arg(GLYesNo(m_features & Framebuffers)));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Unpack Subimage : %1").arg(GLYesNo(m_extraFeatures & kGLExtSubimage)));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Compute shaders : %1").arg(GLYesNo(QOpenGLShader::hasOpenGLShaders(QOpenGLShader::Compute))));

// warnings
if (m_maxTextureUnits < 3)
Expand Down Expand Up @@ -571,7 +614,6 @@ void MythRenderOpenGL::SetTextureFilters(MythGLTexture *Texture, QOpenGLTexture:
return;

makeCurrent();
EnableTextures(Texture->m_target);
if (Texture->m_texture)
{
Texture->m_texture->bind();
Expand Down Expand Up @@ -603,28 +645,6 @@ void MythRenderOpenGL::ActiveTexture(GLuint ActiveTex)
doneCurrent();
}

void MythRenderOpenGL::EnableTextures(GLenum Type)
{
if (isOpenGLES() || (m_activeTextureTarget == Type))
return;

makeCurrent();
glEnable(Type);
m_activeTextureTarget = Type;
doneCurrent();
}

void MythRenderOpenGL::DisableTextures(void)
{
if (isOpenGLES() || !m_activeTextureTarget)
return;

makeCurrent();
glDisable(m_activeTextureTarget);
m_activeTextureTarget = 0;
doneCurrent();
}

void MythRenderOpenGL::DeleteTexture(MythGLTexture *Texture)
{
if (!Texture)
Expand Down Expand Up @@ -731,7 +751,6 @@ void MythRenderOpenGL::DrawBitmap(MythGLTexture *Texture, QOpenGLFramebufferObje
SetShaderProgramParams(Program, m_transforms.top(), "u_transform");

GLenum textarget = Texture->m_target;
EnableTextures(textarget);
Program->setUniformValue("s_texture0", 0);
ActiveTexture(GL_TEXTURE0);
if (Texture->m_texture)
Expand Down Expand Up @@ -791,7 +810,6 @@ void MythRenderOpenGL::DrawBitmap(MythGLTexture **Textures, uint TextureCount,
SetShaderProgramParams(Program, m_transforms.top(), "u_transform");

GLenum textarget = first->m_target;
EnableTextures(textarget);
uint active_tex = 0;
for (uint i = 0; i < TextureCount; i++)
{
Expand Down Expand Up @@ -869,8 +887,6 @@ void MythRenderOpenGL::DrawRoundRect(QOpenGLFramebufferObject *Target,
QRect bl(r.left(), r.top() + r.height() - rad, rad, rad);
QRect br(r.left() + r.width() - rad, r.top() + r.height() - rad, rad, rad);

DisableTextures();

glEnableVertexAttribArray(VERTEX_INDEX);

if (FillBrush.style() != Qt::NoBrush)
Expand Down
5 changes: 2 additions & 3 deletions mythtv/libs/libmythui/mythrender_opengl.h
Expand Up @@ -126,8 +126,6 @@ class MUI_PUBLIC MythRenderOpenGL : public QOpenGLContext, public QOpenGLFunctio
void SetTextureFilters(MythGLTexture *Texture, QOpenGLTexture::Filter Filter,
QOpenGLTexture::WrapMode Wrap = QOpenGLTexture::ClampToEdge);
void ActiveTexture(GLuint ActiveTex);
void EnableTextures(GLenum Type = QOpenGLTexture::Target2D);
void DisableTextures(void);
void DeleteTexture(MythGLTexture *Texture);
int GetBufferSize(QSize Size, QOpenGLTexture::PixelFormat Format, QOpenGLTexture::PixelType Type);

Expand Down Expand Up @@ -207,11 +205,11 @@ class MUI_PUBLIC MythRenderOpenGL : public QOpenGLContext, public QOpenGLFunctio
int m_maxTextureSize;
int m_maxTextureUnits;
int m_colorDepth;
bool m_coreProfile;

// State
QRect m_viewport;
GLuint m_activeTexture;
GLenum m_activeTextureTarget;
bool m_blend;
int32_t m_background;
bool m_fullRange;
Expand All @@ -220,6 +218,7 @@ class MUI_PUBLIC MythRenderOpenGL : public QOpenGLContext, public QOpenGLFunctio
QMatrix4x4 m_parameters;
QHash<QString,QMatrix4x4> m_cachedMatrixUniforms;
QHash<QOpenGLShaderProgram*, QHash<QByteArray, GLint> > m_cachedUniformLocations;
GLuint m_vao; // core profile only

// For Performance improvement set false to disable glFlush.
// Needed for Raspberry pi
Expand Down

0 comments on commit d652f7b

Please sign in to comment.