MythTV  master
mythrender_opengl2es.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythrender_opengl2es.h"
3 
4 #define LOC QString("OpenGL2ES: ")
5 
6 MythRenderOpenGL2ES::MythRenderOpenGL2ES(const MythRenderFormat& format, QPaintDevice* device)
7  : MythRenderOpenGL2(format, device, kRenderOpenGL2ES)
8 {
9 }
10 
13 {
14 }
15 
17 {
18  // GLSL version
19  m_GLSLVersion = "#version 100\n";
20  // GLSL ES precision qualifiers
21  m_qualifiers = "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
22  "precision highp float;\n"
23  "#else\n"
24  "precision mediump float;\n"
25  "#endif\n";
26 
27  // Default OpenGL ES 2.0
29  GetProcAddress("glCreateShader");
31  GetProcAddress("glShaderSource");
33  GetProcAddress("glCompileShader");
35  GetProcAddress("glAttachShader");
37  GetProcAddress("glGetShaderiv");
39  GetProcAddress("glGetShaderInfoLog");
41  GetProcAddress("glDetachShader");
43  GetProcAddress("glDeleteShader");
44 
46  GetProcAddress("glDeleteProgram");
48  GetProcAddress("glCreateProgram");
50  GetProcAddress("glLinkProgram");
52  GetProcAddress("glUseProgram");
54  GetProcAddress("glGetProgramInfoLog");
56  GetProcAddress("glGetProgramiv");
57 
59  GetProcAddress("glGetUniformLocation");
61  GetProcAddress("glUniform1i");
63  GetProcAddress("glUniformMatrix4fv");
65  GetProcAddress("glVertexAttribPointer");
66 
69  GetProcAddress("glEnableVertexAttribArray");
72  GetProcAddress("glDisableVertexAttribArray");
74  GetProcAddress("glBindAttribLocation");
76  GetProcAddress("glVertexAttrib4f");
77 
79  GetProcAddress("glGenBuffers");
81  GetProcAddress("glBindBuffer");
83  GetProcAddress("glDeleteBuffers");
85  GetProcAddress("glBufferData");
86 
88  GetProcAddress("glActiveTexture");
89 
90  // GL_OES_framebuffer_object - should be core?
92  GetProcAddress("glGenFramebuffers");
94  GetProcAddress("glBindFramebuffer");
96  GetProcAddress("glFramebufferTexture2D");
98  GetProcAddress("glCheckFramebufferStatus");
100  GetProcAddress("glDeleteFramebuffers");
101  // GL_OES_mapbuffer
104 }
105 
107 {
109 
110  GLint maxtexsz = 0;
111  GLint maxunits = 0;
112  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsz);
113  glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxunits);
114  m_max_units = maxunits;
115  m_max_tex_size = (maxtexsz) ? maxtexsz : 512;
116 
127  {
128  LOG(VB_GENERAL, LOG_ERR,
129  "OpenGL2ES Error: Failed to find basic functionality.");
130  return false;
131  }
132 
133  LOG(VB_GENERAL, LOG_INFO, "OpenGL2ES: Found default functionality.");
134 
135  static bool glslshaders = !getenv("OPENGL_NOGLSL");
136  GLboolean b;
137  glGetBooleanv(GL_SHADER_COMPILER, &b);
138  if (!b)
139  {
140  LOG(VB_GENERAL, LOG_INFO, "OpenGL2ES: GLSL not supported.");
141  glslshaders = false;
142  }
143  else if (!glslshaders)
144  LOG(VB_GENERAL, LOG_NOTICE, "OpenGL2ES: Disabling GLSL.");
145 
146  static bool framebuffers = !getenv("OPENGL_NOFBO");
147  if (!framebuffers)
148  LOG(VB_GENERAL, LOG_NOTICE, "OpenGL2ES: Disabling FrameBuffer Objects.");
149 
150  static bool vertexbuffers = !getenv("OPENGL_NOVBO");
151  if (!vertexbuffers)
152  LOG(VB_GENERAL, LOG_NOTICE, "OpenGL2ES: Disabling VertexBuffer Objects.");
153 
154  m_extensions = (const char*) glGetString(GL_EXTENSIONS);
155  LOG(VB_GENERAL, LOG_DEBUG, QString("OpenGL2ES: len=%1: extensions: %2")
156  .arg(m_extensions.length())
157  .arg(m_extensions));
158 
159  m_exts_supported += (glslshaders ? kGLSL : 0) |
160  (vertexbuffers ? kGLExtVBO : 0) | kGLVertexArray |
161  kGLMultiTex;
162  m_default_texture_type = GL_TEXTURE_2D;
163 
164  // GL_OES_framebuffer_object
167  m_glDeleteFramebuffers && framebuffers)
168  {
170  LOG(VB_GENERAL, LOG_INFO,
171  "OpenGL2ES: Framebuffer Objects available.");
172  }
173 
174  bool pixelbuffers = !getenv("OPENGL_NOPBO");
175  bool buffer_procs = m_glMapBuffer && m_glBindBuffer &&
178  if(m_extensions.contains("GL_ARB_pixel_buffer_object")
179  && buffer_procs && pixelbuffers)
180  {
182  LOG(VB_GENERAL, LOG_INFO,
183  "OpenGL2ES: Pixelbuffer Objects available.");
184  }
185 
186  // GL_OES_mapbuffer
187  if (m_extensions.contains("GL_OES_mapbuffer") &&
189  {
190  // NB these functions don't support GL_PIXEL_UNPACK_BUFFER
191  // so kGLExtPBufObj is not enabled
192  LOG(VB_GENERAL, LOG_INFO, "OpenGL2ES: OES mapbuffer available.");
193  }
194 
195  // GL_EXT_texture_norm16 for GL_RGBA16 support
196  if (m_extensions.contains("GL_EXT_texture_norm16"))
197  {
198  static bool rgba16 = !getenv("OPENGL_NORGBA16");
199  if (rgba16)
201  else
202  LOG(VB_GENERAL, LOG_INFO, "OpenGL2ES: Disabling RGBA16 textures");
203  }
204 
206 
207  static bool debugged = false;
208  if (!debugged)
209  {
210  debugged = true;
211  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Vendor : %1")
212  .arg((const char*) glGetString(GL_VENDOR)));
213  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Renderer: %1")
214  .arg((const char*) glGetString(GL_RENDERER)));
215  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Version : %1")
216  .arg((const char*) glGetString(GL_VERSION)));
217  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Max texture size: %1 x %2")
218  .arg(m_max_tex_size).arg(m_max_tex_size));
219  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Max texture units: %1")
220  .arg(m_max_units));
221  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Direct rendering: %1")
222  .arg(IsDirectRendering() ? "Yes" : "No"));
223  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Extensions Supported: %1")
224  .arg(m_exts_supported, 0, 16));
225  }
226 
227  if (m_exts_supported & kGLSL)
228  {
231  }
232 
233  return true;
234 }
MYTH_GLGETPROGRAMIVPROC m_glGetProgramiv
MYTH_GLVERTEXATTRIB4FPROC m_glVertexAttrib4f
void(APIENTRY * MYTH_GLBUFFERDATAPROC)(GLenum target, MYTH_GLsizeiptr size, const GLvoid *data, GLenum usage)
void(* MYTH_GLUSEPROGRAMPROC)(GLuint program)
void(* MYTH_GLDISABLEVERTEXATTRIBARRAYPROC)(GLuint index)
MYTH_GLDELETEFRAMEBUFFERSPROC m_glDeleteFramebuffers
MYTH_GLGETSHADERIVPROC m_glGetShaderiv
GLvoid *(APIENTRY * MYTH_GLMAPBUFFERPROC)(GLenum target, GLenum access)
MYTH_GLATTACHSHADERPROC m_glAttachShader
MYTH_GLDISABLEVERTEXATTRIBARRAYPROC m_glDisableVertexAttribArray
void(* MYTH_GLBINDATTRIBLOCATIONPROC)(GLuint program, GLuint index, const GLcharARB *name)
void(* MYTH_GLSHADERSOURCEPROC)(GLuint shader, int numOfStrings, const char **strings, const int *lenOfStrings)
MYTH_GLCREATESHADERPROC m_glCreateShader
void InitProcs(void) override
MYTH_GLUNIFORMMATRIX4FVPROC m_glUniformMatrix4fv
MYTH_GLBUFFERDATAPROC m_glBufferData
MYTH_GLMAPBUFFERPROC m_glMapBuffer
MYTH_GLUSEPROGRAMPROC m_glUseProgram
MYTH_GLGENFRAMEBUFFERSPROC m_glGenFramebuffers
MYTH_GLBINDBUFFERPROC m_glBindBuffer
MYTH_GLDELETEBUFFERSPROC m_glDeleteBuffers
GLenum(APIENTRY * MYTH_GLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target)
void(APIENTRY * MYTH_GLGENFRAMEBUFFERSPROC)(GLsizei n, GLuint *framebuffers)
#define LOC
void(* MYTH_GLVERTEXATTRIBPOINTERPROC)(GLuint index, GLint size, GLenum type, GLboolean normalize, GLsizei stride, const GLvoid *ptr)
MythRenderOpenGL2ES(const MythRenderFormat &format, QPaintDevice *device)
MYTH_GLGETUNIFORMLOCATIONPROC m_glGetUniformLocation
void(* MYTH_GLVERTEXATTRIB4FPROC)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
GLboolean(APIENTRY * MYTH_GLUNMAPBUFFERPROC)(GLenum target)
void(* MYTH_GLLINKPROGRAMPROC)(GLuint program)
bool InitFeatures(void) override
unsigned char b
Definition: ParseText.cpp:329
bool IsDirectRendering() const
void * GetProcAddress(const QString &proc) const
GLuint(* MYTH_GLCREATESHADERPROC)(GLenum shaderType)
void(APIENTRY * MYTH_GLFRAMEBUFFERTEXTURE2DPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
MYTH_GLCREATEPROGRAMPROC m_glCreateProgram
void(* MYTH_GLGETSHADERINFOLOGPROC)(GLuint shader, GLint maxlength, GLint *length, GLchar *infolog)
MYTH_GLFRAMEBUFFERTEXTURE2DPROC m_glFramebufferTexture2D
MYTH_GLUNMAPBUFFERPROC m_glUnmapBuffer
void(* MYTH_GLDELETESHADERPROC)(GLuint id)
void(* MYTH_GLGETSHADERIVPROC)(GLuint shader, GLenum pname, GLint *params)
void(APIENTRY * MYTH_GLACTIVETEXTUREPROC)(GLenum texture)
MYTH_GLCHECKFRAMEBUFFERSTATUSPROC m_glCheckFramebufferStatus
class QGLFormat MythRenderFormat
MYTH_GLUNIFORM1IPROC m_glUniform1i
GLint(* MYTH_GLGETUNIFORMLOCATIONPROC)(GLuint program, const char *name)
MYTH_GLLINKPROGRAMPROC m_glLinkProgram
MYTH_GLCOMPILESHADERPROC m_glCompileShader
MYTH_GLDELETESHADERPROC m_glDeleteShader
MYTH_GLDELETEPROGRAMPROC m_glDeleteProgram
void(* MYTH_GLATTACHSHADERPROC)(GLuint program, GLuint shader)
MYTH_GLENABLEVERTEXATTRIBARRAYPROC m_glEnableVertexAttribArray
MYTH_GLGETSHADERINFOLOGPROC m_glGetShaderInfoLog
void(* MYTH_GLENABLEVERTEXATTRIBARRAYPROC)(GLuint index)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
GLuint(* MYTH_GLCREATEPROGRAMPROC)(void)
MYTH_GLGETPROGRAMINFOLOGPROC m_glGetProgramInfoLog
void(* MYTH_GLGETPROGRAMINFOLOGPROC)(GLuint object, int maxLen, int *len, char *log)
void(* MYTH_GLCOMPILESHADERPROC)(GLuint shader)
MYTH_GLGENBUFFERSPROC m_glGenBuffers
void(* MYTH_GLUNIFORM1IPROC)(GLint location, GLint)
void(* MYTH_GLDETACHSHADERPROC)(GLuint program, GLuint shader)
void(APIENTRY * MYTH_GLBINDBUFFERPROC)(GLenum target, GLuint buffer)
MYTH_GLDETACHSHADERPROC m_glDetachShader
MYTH_GLACTIVETEXTUREPROC m_glActiveTexture
MYTH_GLBINDATTRIBLOCATIONPROC m_glBindAttribLocation
void(* MYTH_GLUNIFORMMATRIX4FVPROC)(GLint location, GLint size, GLboolean transpose, const GLfloat *values)
void(APIENTRY * MYTH_GLDELETEFRAMEBUFFERSPROC)(GLsizei n, const GLuint *framebuffers)
MYTH_GLBINDFRAMEBUFFERPROC m_glBindFramebuffer
void(* MYTH_GLDELETEPROGRAMPROC)(GLuint shader)
void(APIENTRY * MYTH_GLGENBUFFERSPROC)(GLsizei n, GLuint *buffers)
MYTH_GLSHADERSOURCEPROC m_glShaderSource
MYTH_GLVERTEXATTRIBPOINTERPROC m_glVertexAttribPointer
void(APIENTRY * MYTH_GLDELETEBUFFERSPROC)(GLsizei n, const GLuint *buffers)
void(* MYTH_GLGETPROGRAMIVPROC)(GLuint object, GLenum type, int *param)
void(APIENTRY * MYTH_GLBINDFRAMEBUFFERPROC)(GLenum target, GLuint framebuffer)