1 /****************************************************************************** 2 QtAV: Media play library based on Qt and FFmpeg 3 Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com> 4 5 * This file is part of QtAV (from 2016) 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 ******************************************************************************/ 21 #ifndef QTAV_GL_API_H 22 #define QTAV_GL_API_H 23 24 #ifndef QT_NO_OPENGL 25 #include <qglobal.h> 26 # if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 27 #include <QtGui/QOpenGLBuffer> 28 #include <QtGui/QOpenGLContext> 29 #include <QtGui/QOpenGLFunctions> 30 #include <QtGui/QOpenGLShaderProgram> 31 # elif defined(QT_OPENGL_LIB) 32 # if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) 33 #include <QtOpenGL/QGLFunctions> 34 # endif //4.8 35 #include <QtOpenGL/QGLBuffer> 36 #include <QtOpenGL/QGLContext> 37 #include <QtOpenGL/QGLShaderProgram> 38 #define QOpenGLShaderProgram QGLShaderProgram 39 typedef QGLBuffer QOpenGLBuffer; 40 #define QOpenGLContext QGLContext 41 #define QOpenGLShaderProgram QGLShaderProgram 42 #define QOpenGLShader QGLShader 43 #define QOpenGLFunctions QGLFunctions 44 #define initializeOpenGLFunctions() initializeGLFunctions() 45 #include <qgl.h> 46 # else //used by vaapi even qtopengl module is disabled 47 # if defined(QT_OPENGL_ES_2) 48 # if defined(Q_OS_MAC) // iOS 49 #include <OpenGLES/ES2/gl.h> 50 #include <OpenGLES/ES2/glext.h> 51 # else // "uncontrolled" ES2 platforms 52 #include <GLES2/gl2.h> 53 # endif // Q_OS_MAC 54 # else // non-ES2 platforms 55 # if defined(Q_OS_MAC) 56 #include <OpenGL/gl.h> 57 # if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 58 #include <OpenGL/gl3.h> 59 # endif 60 #include <OpenGL/glext.h> 61 # else 62 #include <GL/gl.h> 63 # endif // Q_OS_MAC 64 # endif // QT_OPENGL_ES_2 65 # endif 66 67 #ifndef GL_APIENTRY 68 #ifdef Q_OS_WIN 69 #define GL_APIENTRY __stdcall 70 #else 71 #define GL_APIENTRY 72 #endif 73 #endif 74 75 #ifndef GL_TEXTURE_RECTANGLE 76 #define GL_TEXTURE_RECTANGLE 0x84F5 77 #endif 78 79 //GL_BGRA is available in OpenGL >= 1.2 80 #ifndef GL_BGRA 81 #define GL_BGRA 0x80E1 82 #endif 83 #ifndef GL_BGR 84 #define GL_BGR 0x80E0 85 #endif 86 #ifndef GL_RED 87 #define GL_RED 0x1903 88 #endif 89 #ifndef GL_RG 90 #define GL_RG 0x8227 91 #endif 92 #ifndef GL_R8 93 #define GL_R8 0x8229 94 #endif 95 #ifndef GL_R16 96 #define GL_R16 0x822A 97 #endif 98 #ifndef GL_RG8 99 #define GL_RG8 0x822B 100 #endif 101 #ifndef GL_RG16 102 #define GL_RG16 0x822C 103 #endif 104 #ifndef GL_RGB8 105 #define GL_RGB8 0x8051 106 #endif 107 #ifndef GL_RGB16 108 #define GL_RGB16 0x8054 109 #endif 110 #ifndef GL_RGBA8 111 #define GL_RGBA8 0x8058 112 #endif 113 #ifndef GL_RGBA16 114 #define GL_RGBA16 0x805B 115 #endif 116 117 namespace QtAV { 118 typedef char GLchar; // for qt4 mingw 119 struct api; 120 api& gl(); 121 struct api { 122 void resolve(); 123 // TODO: static, so gl::GetString 124 const GLubyte *(GL_APIENTRY *GetString)(GLenum); 125 GLenum (GL_APIENTRY *GetError)(void); 126 void (GL_APIENTRY *ActiveTexture)(GLenum); 127 void (GL_APIENTRY *BindFramebuffer)(GLenum target, GLuint framebuffer); 128 GLint (GL_APIENTRY *GetUniformLocation)(GLuint, const GLchar *); 129 void (GL_APIENTRY *Uniform1f)(GLint, GLfloat); 130 void (GL_APIENTRY *Uniform2f)(GLint, GLfloat, GLfloat); 131 void (GL_APIENTRY *Uniform3f)(GLint, GLfloat, GLfloat, GLfloat); 132 void (GL_APIENTRY *Uniform4f)(GLint, GLfloat, GLfloat, GLfloat, GLfloat); 133 void (GL_APIENTRY *Uniform1fv)(GLint location, GLsizei count, const GLfloat *value); 134 void (GL_APIENTRY *Uniform2fv)(GLint location, GLsizei count, const GLfloat *value); 135 void (GL_APIENTRY *Uniform3fv)(GLint location, GLsizei count, const GLfloat *value); 136 void (GL_APIENTRY *Uniform4fv)(GLint location, GLsizei count, const GLfloat *value); 137 void (GL_APIENTRY *Uniform1iv)(GLint location, GLsizei count, const GLint *value); 138 void (GL_APIENTRY *Uniform2iv)(GLint location, GLsizei count, const GLint *value); 139 void (GL_APIENTRY *Uniform3iv)(GLint location, GLsizei count, const GLint *value); 140 void (GL_APIENTRY *Uniform4iv)(GLint location, GLsizei count, const GLint *value); 141 void (GL_APIENTRY *UniformMatrix2fv)(GLint, GLsizei, GLboolean, const GLfloat *); 142 void (GL_APIENTRY *UniformMatrix3fv)(GLint, GLsizei, GLboolean, const GLfloat *); 143 void (GL_APIENTRY *UniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); 144 void (GL_APIENTRY *BlendFuncSeparate)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); 145 146 // Before using the following members, check null ptr first because they are not valid everywhere 147 // ES3.1 148 void (GL_APIENTRY *GetTexLevelParameteriv)(GLenum, GLint, GLenum, GLint *); 149 150 #if defined(Q_OS_WIN32) 151 //#include <GL/wglext.h> //not found in vs2013 152 //https://www.opengl.org/registry/specs/NV/DX_interop.txt 153 #ifndef WGL_ACCESS_READ_ONLY_NV 154 #define WGL_ACCESS_READ_ONLY_NV 0x00000000 155 #define WGL_ACCESS_READ_WRITE_NV 0x00000001 156 #define WGL_ACCESS_WRITE_DISCARD_NV 0x00000002 157 #endif 158 BOOL (WINAPI* DXSetResourceShareHandleNV)(void *dxObject, HANDLE shareHandle); 159 HANDLE (WINAPI* DXOpenDeviceNV)(void *dxDevice); 160 BOOL (WINAPI* DXCloseDeviceNV)(HANDLE hDevice); 161 HANDLE (WINAPI* DXRegisterObjectNV)(HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access); 162 BOOL (WINAPI* DXUnregisterObjectNV)(HANDLE hDevice, HANDLE hObject); 163 BOOL (WINAPI* DXObjectAccessNV)(HANDLE hObject, GLenum access); 164 BOOL (WINAPI* DXLockObjectsNV)(HANDLE hDevice, GLint count, HANDLE *hObjects); 165 BOOL (WINAPI* DXUnlockObjectsNV)(HANDLE hDevice, GLint count, HANDLE *hObjects); 166 #endif 167 }; 168 } //namespace QtAV 169 #endif //QT_NO_OPENGL 170 #endif //QTAV_GL_API_H 171