mirror of https://github.com/odrling/Aegisub
Shaders no longer need glew
Originally committed to SVN as r900.
This commit is contained in:
parent
3b9afa126e
commit
5d6282aee5
File diff suppressed because it is too large
Load Diff
|
@ -36,16 +36,35 @@
|
||||||
|
|
||||||
///////////
|
///////////
|
||||||
// Headers
|
// Headers
|
||||||
#include <GL/glew.h>
|
#include <wx/wxprec.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#include "gl/glext.h"
|
||||||
#include "gl_wrap.h"
|
#include "gl_wrap.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////
|
||||||
|
// OpenGL extension function pointers
|
||||||
|
#ifdef __WIN32__
|
||||||
|
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
|
||||||
|
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL;
|
||||||
|
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
|
||||||
|
PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
|
||||||
|
PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
|
||||||
|
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
|
||||||
|
PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
|
||||||
|
PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
|
||||||
|
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
|
||||||
|
PFNGLUNIFORM1IARBPROC glUniform1iARB = NULL;
|
||||||
|
PFNGLUNIFORM2FARBPROC glUniform2fARB = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// GLEW library
|
// GLEW library
|
||||||
#if __VISUALC__ >= 1200
|
//#if __VISUALC__ >= 1200
|
||||||
#pragma comment(lib,"glew32.lib")
|
//#pragma comment(lib,"glew32.lib")
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
/////////////
|
/////////////
|
||||||
|
@ -235,18 +254,47 @@ void OpenGLWrapper::SetModeFill() {
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// Are shaders available?
|
// Are shaders available?
|
||||||
bool OpenGLWrapper::ShadersAvailable() {
|
bool OpenGLWrapper::ShadersAvailable() {
|
||||||
if (GLEW_VERSION_2_0) return true;
|
return IsExtensionSupported("GL_ARB_vertex_shader") && IsExtensionSupported("GL_ARB_fragment_shader");
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////
|
||||||
|
// Use shaders?
|
||||||
|
bool OpenGLWrapper::UseShaders() {
|
||||||
|
return Options.AsBool(_T("Video Use Pixel Shaders")) && ShadersAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////
|
||||||
|
// Is extension supported?
|
||||||
|
bool OpenGLWrapper::IsExtensionSupported(const char *ext) {
|
||||||
|
char *extList = (char*) glGetString(GL_EXTENSIONS);
|
||||||
|
if (!extList) return false;
|
||||||
|
return strstr(extList, ext) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// Initialize GLEW
|
// Initialize GLEW
|
||||||
void OpenGLWrapper::InitializeGLEW() {
|
void OpenGLWrapper::Initialize() {
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
glewInit();
|
//glewInit();
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress("glUseProgramObjectARB");
|
||||||
|
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) wglGetProcAddress("glDeleteObjectARB");
|
||||||
|
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress("glCreateProgramObjectARB");
|
||||||
|
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress("glAttachObjectARB");
|
||||||
|
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress("glLinkProgramARB");
|
||||||
|
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress("glCreateShaderObjectARB");
|
||||||
|
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) wglGetProcAddress("glShaderSourceARB");
|
||||||
|
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) wglGetProcAddress("glCompileShaderARB");
|
||||||
|
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) wglGetProcAddress("glGetUniformLocationARB");
|
||||||
|
glUniform1iARB = (PFNGLUNIFORM1IARBPROC) wglGetProcAddress("glUniform1iARB");
|
||||||
|
glUniform2fARB = (PFNGLUNIFORM2FARBPROC) wglGetProcAddress("glUniform2fARB");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,17 +302,17 @@ void OpenGLWrapper::InitializeGLEW() {
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Set current shader
|
// Set current shader
|
||||||
void OpenGLWrapper::SetShader(GLuint i) {
|
void OpenGLWrapper::SetShader(GLuint i) {
|
||||||
InitializeGLEW();
|
Initialize();
|
||||||
glUseProgram(i);
|
glUseProgramObjectARB(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// Destroy shader program
|
// Destroy shader program
|
||||||
void OpenGLWrapper::DestroyShaderProgram(GLuint i) {
|
void OpenGLWrapper::DestroyShaderProgram(GLuint i) {
|
||||||
InitializeGLEW();
|
Initialize();
|
||||||
SetShader(0);
|
SetShader(0);
|
||||||
glDeleteProgram(i);
|
glDeleteObjectARB(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,15 +320,15 @@ void OpenGLWrapper::DestroyShaderProgram(GLuint i) {
|
||||||
// Create shader program from vertex and pixel shaders
|
// Create shader program from vertex and pixel shaders
|
||||||
GLuint OpenGLWrapper::CreateShaderProgram(GLuint vertex,GLuint pixel) {
|
GLuint OpenGLWrapper::CreateShaderProgram(GLuint vertex,GLuint pixel) {
|
||||||
// Create instance
|
// Create instance
|
||||||
InitializeGLEW();
|
Initialize();
|
||||||
GLuint program = glCreateProgram();
|
GLuint program = glCreateProgramObjectARB();
|
||||||
|
|
||||||
// Attach shaders
|
// Attach shaders
|
||||||
glAttachShader(program,vertex);
|
glAttachObjectARB(program,vertex);
|
||||||
glAttachShader(program,pixel);
|
glAttachObjectARB(program,pixel);
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
glLinkProgram(program);
|
glLinkProgramARB(program);
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
return program;
|
return program;
|
||||||
|
@ -291,8 +339,8 @@ GLuint OpenGLWrapper::CreateShaderProgram(GLuint vertex,GLuint pixel) {
|
||||||
// Create standard Vertex shader
|
// Create standard Vertex shader
|
||||||
GLuint OpenGLWrapper::CreateStandardVertexShader() {
|
GLuint OpenGLWrapper::CreateStandardVertexShader() {
|
||||||
// Create instance
|
// Create instance
|
||||||
InitializeGLEW();
|
Initialize();
|
||||||
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
|
GLuint shader = glCreateShaderObjectARB(GL_VERTEX_SHADER);
|
||||||
|
|
||||||
// Read source
|
// Read source
|
||||||
char source[] =
|
char source[] =
|
||||||
|
@ -300,11 +348,11 @@ GLuint OpenGLWrapper::CreateStandardVertexShader() {
|
||||||
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
||||||
" gl_Position = ftransform();\n"
|
" gl_Position = ftransform();\n"
|
||||||
"}";
|
"}";
|
||||||
const GLchar *src = source;
|
|
||||||
glShaderSource(shader,1,&src,NULL);
|
|
||||||
|
|
||||||
// Compile
|
// Compile
|
||||||
glCompileShader(shader);
|
const GLchar *src = source;
|
||||||
|
glShaderSourceARB(shader,1,&src,NULL);
|
||||||
|
glCompileShaderARB(shader);
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
return shader;
|
return shader;
|
||||||
|
@ -315,8 +363,8 @@ GLuint OpenGLWrapper::CreateStandardVertexShader() {
|
||||||
// Create YV12->RGB32 Pixel Shader
|
// Create YV12->RGB32 Pixel Shader
|
||||||
GLuint OpenGLWrapper::CreateYV12PixelShader() {
|
GLuint OpenGLWrapper::CreateYV12PixelShader() {
|
||||||
// Create instance
|
// Create instance
|
||||||
InitializeGLEW();
|
Initialize();
|
||||||
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
|
GLuint shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
// Read source
|
// Read source
|
||||||
char source[] =
|
char source[] =
|
||||||
|
@ -339,11 +387,11 @@ GLuint OpenGLWrapper::CreateYV12PixelShader() {
|
||||||
" vec4 color_v = (texture2D(tex,pos + off2) + uv_bias) * uv_mult;\n"
|
" vec4 color_v = (texture2D(tex,pos + off2) + uv_bias) * uv_mult;\n"
|
||||||
" gl_FragColor = color_y + color_u + color_v;\n"
|
" gl_FragColor = color_y + color_u + color_v;\n"
|
||||||
"}";
|
"}";
|
||||||
const GLchar *src = source;
|
|
||||||
glShaderSource(shader,1,&src,NULL);
|
|
||||||
|
|
||||||
// Compile
|
// Compile
|
||||||
glCompileShader(shader);
|
const GLchar *src = source;
|
||||||
|
glShaderSourceARB(shader,1,&src,NULL);
|
||||||
|
glCompileShaderARB(shader);
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
return shader;
|
return shader;
|
||||||
|
@ -370,12 +418,12 @@ GLuint OpenGLWrapper::CreateYV12Shader(float tw,float th) {
|
||||||
if (glGetError() != 0) throw _T("Error setting shader");
|
if (glGetError() != 0) throw _T("Error setting shader");
|
||||||
|
|
||||||
// Set uniform variables
|
// Set uniform variables
|
||||||
GLuint address = glGetUniformLocation(program,"tex");
|
GLuint address = glGetUniformLocationARB(program,"tex");
|
||||||
glUniform1i(address, 0);
|
glUniform1iARB(address, 0);
|
||||||
address = glGetUniformLocation(program,"off1");
|
address = glGetUniformLocationARB(program,"off1");
|
||||||
glUniform2f(address, 0.0f, th);
|
glUniform2fARB(address, 0.0f, th);
|
||||||
address = glGetUniformLocation(program,"off2");
|
address = glGetUniformLocationARB(program,"off2");
|
||||||
glUniform2f(address, tw*0.5f, th);
|
glUniform2fARB(address, tw*0.5f, th);
|
||||||
|
|
||||||
// Return shader
|
// Return shader
|
||||||
return program;
|
return program;
|
||||||
|
|
|
@ -45,7 +45,7 @@ private:
|
||||||
float r2,g2,b2,a2;
|
float r2,g2,b2,a2;
|
||||||
int lw;
|
int lw;
|
||||||
|
|
||||||
static void InitializeGLEW();
|
static void Initialize();
|
||||||
static GLuint CreateStandardVertexShader();
|
static GLuint CreateStandardVertexShader();
|
||||||
static GLuint CreateYV12PixelShader();
|
static GLuint CreateYV12PixelShader();
|
||||||
static GLuint CreateShaderProgram(GLuint vertex,GLuint pixel);
|
static GLuint CreateShaderProgram(GLuint vertex,GLuint pixel);
|
||||||
|
@ -61,6 +61,8 @@ public:
|
||||||
void DrawRectangle(float x1,float y1,float x2,float y2);
|
void DrawRectangle(float x1,float y1,float x2,float y2);
|
||||||
void DrawRing(float x,float y,float r1,float r2,float ar=1.0f,float arcStart=0.0f,float arcEnd=0.0f);
|
void DrawRing(float x,float y,float r1,float r2,float ar=1.0f,float arcStart=0.0f,float arcEnd=0.0f);
|
||||||
|
|
||||||
|
static bool UseShaders();
|
||||||
|
static bool IsExtensionSupported(const char *ext);
|
||||||
static bool ShadersAvailable();
|
static bool ShadersAvailable();
|
||||||
static void SetShader(GLuint i);
|
static void SetShader(GLuint i);
|
||||||
static void DestroyShaderProgram(GLuint i);
|
static void DestroyShaderProgram(GLuint i);
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
#include <wx/wxscintilla.h>
|
#include <wx/wxscintilla.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#include <GL/glew.h>
|
//#include <GL/glew.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <wx/glcanvas.h>
|
#include <wx/glcanvas.h>
|
||||||
|
|
|
@ -257,6 +257,9 @@ void VideoContext::SetVideo(const wxString &filename) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Set GL context
|
||||||
|
GetGLContext(displayList.front())->SetCurrent(*displayList.front());
|
||||||
|
|
||||||
// Choose a provider
|
// Choose a provider
|
||||||
provider = VideoProviderFactory::GetProvider(filename,overFps);
|
provider = VideoProviderFactory::GetProvider(filename,overFps);
|
||||||
loaded = provider != NULL;
|
loaded = provider != NULL;
|
||||||
|
|
|
@ -294,7 +294,7 @@ PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool mpeg2dec3_priori
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to RGB32
|
// Convert to RGB32
|
||||||
if (OpenGLWrapper::ShadersAvailable() && !Options.AsBool(_T("Video Use Pixel Shaders"))) {
|
if (!OpenGLWrapper::UseShaders()) {
|
||||||
script = env->Invoke("ConvertToRGB32", script);
|
script = env->Invoke("ConvertToRGB32", script);
|
||||||
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Converted to RGB32"));
|
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Converted to RGB32"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue