Shaders no longer need glew

Originally committed to SVN as r900.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-27 07:13:29 +00:00
parent 3b9afa126e
commit 5d6282aee5
6 changed files with 6800 additions and 36 deletions

6711
aegisub/gl/glext.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -36,16 +36,35 @@
///////////
// Headers
#include <GL/glew.h>
#include <wx/wxprec.h>
#include <GL/gl.h>
#include "gl/glext.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
#if __VISUALC__ >= 1200
#pragma comment(lib,"glew32.lib")
#endif
//#if __VISUALC__ >= 1200
//#pragma comment(lib,"glew32.lib")
//#endif
/////////////
@ -235,18 +254,47 @@ void OpenGLWrapper::SetModeFill() {
//////////////////////////
// Are shaders available?
bool OpenGLWrapper::ShadersAvailable() {
if (GLEW_VERSION_2_0) return true;
return false;
return IsExtensionSupported("GL_ARB_vertex_shader") && IsExtensionSupported("GL_ARB_fragment_shader");
}
////////////////
// 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
void OpenGLWrapper::InitializeGLEW() {
void OpenGLWrapper::Initialize() {
static bool initialized = false;
if (!initialized) {
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
void OpenGLWrapper::SetShader(GLuint i) {
InitializeGLEW();
glUseProgram(i);
Initialize();
glUseProgramObjectARB(i);
}
//////////////////////////
// Destroy shader program
void OpenGLWrapper::DestroyShaderProgram(GLuint i) {
InitializeGLEW();
Initialize();
SetShader(0);
glDeleteProgram(i);
glDeleteObjectARB(i);
}
@ -272,15 +320,15 @@ void OpenGLWrapper::DestroyShaderProgram(GLuint i) {
// Create shader program from vertex and pixel shaders
GLuint OpenGLWrapper::CreateShaderProgram(GLuint vertex,GLuint pixel) {
// Create instance
InitializeGLEW();
GLuint program = glCreateProgram();
Initialize();
GLuint program = glCreateProgramObjectARB();
// Attach shaders
glAttachShader(program,vertex);
glAttachShader(program,pixel);
glAttachObjectARB(program,vertex);
glAttachObjectARB(program,pixel);
// Link
glLinkProgram(program);
glLinkProgramARB(program);
// Return
return program;
@ -291,8 +339,8 @@ GLuint OpenGLWrapper::CreateShaderProgram(GLuint vertex,GLuint pixel) {
// Create standard Vertex shader
GLuint OpenGLWrapper::CreateStandardVertexShader() {
// Create instance
InitializeGLEW();
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
Initialize();
GLuint shader = glCreateShaderObjectARB(GL_VERTEX_SHADER);
// Read source
char source[] =
@ -300,11 +348,11 @@ GLuint OpenGLWrapper::CreateStandardVertexShader() {
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_Position = ftransform();\n"
"}";
const GLchar *src = source;
glShaderSource(shader,1,&src,NULL);
// Compile
glCompileShader(shader);
const GLchar *src = source;
glShaderSourceARB(shader,1,&src,NULL);
glCompileShaderARB(shader);
// Return
return shader;
@ -315,8 +363,8 @@ GLuint OpenGLWrapper::CreateStandardVertexShader() {
// Create YV12->RGB32 Pixel Shader
GLuint OpenGLWrapper::CreateYV12PixelShader() {
// Create instance
InitializeGLEW();
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
Initialize();
GLuint shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
// Read source
char source[] =
@ -339,11 +387,11 @@ GLuint OpenGLWrapper::CreateYV12PixelShader() {
" vec4 color_v = (texture2D(tex,pos + off2) + uv_bias) * uv_mult;\n"
" gl_FragColor = color_y + color_u + color_v;\n"
"}";
const GLchar *src = source;
glShaderSource(shader,1,&src,NULL);
// Compile
glCompileShader(shader);
const GLchar *src = source;
glShaderSourceARB(shader,1,&src,NULL);
glCompileShaderARB(shader);
// Return
return shader;
@ -370,12 +418,12 @@ GLuint OpenGLWrapper::CreateYV12Shader(float tw,float th) {
if (glGetError() != 0) throw _T("Error setting shader");
// Set uniform variables
GLuint address = glGetUniformLocation(program,"tex");
glUniform1i(address, 0);
address = glGetUniformLocation(program,"off1");
glUniform2f(address, 0.0f, th);
address = glGetUniformLocation(program,"off2");
glUniform2f(address, tw*0.5f, th);
GLuint address = glGetUniformLocationARB(program,"tex");
glUniform1iARB(address, 0);
address = glGetUniformLocationARB(program,"off1");
glUniform2fARB(address, 0.0f, th);
address = glGetUniformLocationARB(program,"off2");
glUniform2fARB(address, tw*0.5f, th);
// Return shader
return program;

View file

@ -45,7 +45,7 @@ private:
float r2,g2,b2,a2;
int lw;
static void InitializeGLEW();
static void Initialize();
static GLuint CreateStandardVertexShader();
static GLuint CreateYV12PixelShader();
static GLuint CreateShaderProgram(GLuint vertex,GLuint pixel);
@ -61,6 +61,8 @@ public:
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);
static bool UseShaders();
static bool IsExtensionSupported(const char *ext);
static bool ShadersAvailable();
static void SetShader(GLuint i);
static void DestroyShaderProgram(GLuint i);

View file

@ -78,7 +78,7 @@
#include <wx/event.h>
#include <wx/wxscintilla.h>
#include <wx/string.h>
#include <GL/glew.h>
//#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <wx/glcanvas.h>

View file

@ -257,6 +257,9 @@ void VideoContext::SetVideo(const wxString &filename) {
}
#endif
// Set GL context
GetGLContext(displayList.front())->SetCurrent(*displayList.front());
// Choose a provider
provider = VideoProviderFactory::GetProvider(filename,overFps);
loaded = provider != NULL;

View file

@ -294,7 +294,7 @@ PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool mpeg2dec3_priori
}
// Convert to RGB32
if (OpenGLWrapper::ShadersAvailable() && !Options.AsBool(_T("Video Use Pixel Shaders"))) {
if (!OpenGLWrapper::UseShaders()) {
script = env->Invoke("ConvertToRGB32", script);
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Converted to RGB32"));
}