The Great Colorspace Reworking of '09, part 1 of ???: remove all traces of the YV12->RGB32 OpenGL shader program, as it was very broken and nobody ever used it. Updates #926.

Originally committed to SVN as r3180.
This commit is contained in:
Karl Blomster 2009-07-20 01:32:01 +00:00
parent 17abf6965e
commit eae6fea9d9
9 changed files with 2 additions and 251 deletions

View file

@ -409,9 +409,6 @@ DialogOptions::DialogOptions(wxWindow *parent)
//control = new wxCheckBox(videoPage,-1,_("Threaded video")); //control = new wxCheckBox(videoPage,-1,_("Threaded video"));
//Bind(control,_T("Threaded video")); //Bind(control,_T("Threaded video"));
//videoSizer4->Add(control,1,wxEXPAND); //videoSizer4->Add(control,1,wxEXPAND);
//control = new wxCheckBox(videoPage,-1,_("Use pixel shaders if available"));
//Bind(control,_T("Video use pixel shaders"));
//videoSizer4->Add(control,1,wxEXPAND);
control = new wxCheckBox(videoPage,-1,_("Allow pre-2.56a Avisynth")); control = new wxCheckBox(videoPage,-1,_("Allow pre-2.56a Avisynth"));
Bind(control,_T("Allow Ancient Avisynth")); Bind(control,_T("Allow Ancient Avisynth"));
videoSizer4->Add(control,1,wxEXPAND); videoSizer4->Add(control,1,wxEXPAND);

View file

@ -61,22 +61,6 @@ void* glGetProc(const char *str) { return wglGetProcAddress(str); }
#endif #endif
//////////////////////////////////////
// OpenGL extension function pointers
#ifndef __APPLE__
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
/////////////// ///////////////
// Constructor // Constructor
@ -306,27 +290,6 @@ void OpenGLWrapper::SetModeFill() {
} }
//////////////////////////
// Are shaders available?
bool OpenGLWrapper::ShadersAvailable() {
static bool first = true;
static bool available = false;
if (first) {
first = false;
available = IsExtensionSupported("GL_ARB_vertex_shader") && IsExtensionSupported("GL_ARB_fragment_shader");
if (!available) wxMessageBox(_T("Warning, OpenGL shaders are not available on this machine. YV12 video will be on greyscale."),_T("GL Shaders Error"));
}
return available;
}
////////////////
// Use shaders?
bool OpenGLWrapper::UseShaders() {
return Options.AsBool(_T("Video Use Pixel Shaders")) && ShadersAvailable();
}
/////////////////////////// ///////////////////////////
// Is extension supported? // Is extension supported?
bool OpenGLWrapper::IsExtensionSupported(const char *ext) { bool OpenGLWrapper::IsExtensionSupported(const char *ext) {
@ -336,177 +299,6 @@ bool OpenGLWrapper::IsExtensionSupported(const char *ext) {
} }
///////////////////
// Initialize GLEW
void OpenGLWrapper::Initialize() {
static bool initialized = false;
if (!initialized) {
initialized = true;
#ifndef __WXMAC_OSX__
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) glGetProc("glUseProgramObjectARB");
if (!glUseProgramObjectARB) throw _T("OpenGL shader support not available.");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) glGetProc("glDeleteObjectARB");
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) glGetProc("glCreateProgramObjectARB");
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) glGetProc("glAttachObjectARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) glGetProc("glLinkProgramARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) glGetProc("glCreateShaderObjectARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) glGetProc("glShaderSourceARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) glGetProc("glCompileShaderARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) glGetProc("glGetUniformLocationARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC) glGetProc("glUniform1iARB");
glUniform2fARB = (PFNGLUNIFORM2FARBPROC) glGetProc("glUniform2fARB");
#endif
}
}
//////////////////////
// Set current shader
void OpenGLWrapper::SetShader(GLhandleARB i) {
if (UseShaders()) {
Initialize();
glUseProgramObjectARB(i);
if (glGetError()) throw _T("Could not set shader program.");
}
}
//////////////////////////
// Destroy shader program
void OpenGLWrapper::DestroyShaderProgram(GLhandleARB i) {
if (UseShaders()) {
Initialize();
SetShader(0);
glDeleteObjectARB(i);
if (glGetError()) throw _T("Error removing shader program.");
}
}
////////////////////////////////////////////////////////
// Create shader program from vertex and pixel shaders
GLhandleARB OpenGLWrapper::CreateShaderProgram(GLhandleARB vertex,GLhandleARB pixel) {
// Create instance
Initialize();
GLhandleARB program = glCreateProgramObjectARB();
if (glGetError()) throw _T("Error creating shader program.");
// Attach shaders
glAttachObjectARB(program,vertex);
if (glGetError()) throw _T("Error attaching vertex shader to shader program.");
glAttachObjectARB(program,pixel);
if (glGetError()) throw _T("Error attaching pixel shader to shader program.");
// Link
glLinkProgramARB(program);
if (glGetError()) throw _T("Error attaching linking shader program.");
// Return
return program;
}
/////////////////////////////////
// Create standard Vertex shader
GLhandleARB OpenGLWrapper::CreateStandardVertexShader() {
// Create instance
Initialize();
GLhandleARB shader = glCreateShaderObjectARB(GL_VERTEX_SHADER);
if (glGetError()) throw _T("Error generating vertex shader.");
// Read source
char source[] =
"void main() {\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_Position = ftransform();\n"
"}";
// Compile
const GLchar *src = source;
glShaderSourceARB(shader,1,&src,NULL);
if (glGetError()) throw _T("Error acquiring source for vertex shader.");
glCompileShaderARB(shader);
if (glGetError()) throw _T("Error compiling vertex shader.");
// Return
return shader;
}
///////////////////////////////////
// Create YV12->RGB32 Pixel Shader
GLhandleARB OpenGLWrapper::CreateYV12PixelShader() {
// Create instance
Initialize();
GLhandleARB shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
if (glGetError()) throw _T("Error generating pixel shader.");
// Read source
char source[] =
"uniform sampler2D tex;\n"
"uniform vec2 off1;\n"
"uniform vec2 off2;\n"
"\n"
"void main() {\n"
" vec2 pos = gl_TexCoord[0].st;\n"
" vec4 y_bias = vec4(-0.063,-0.063,-0.063,0.0);\n"
" vec4 y_mult = vec4(1.164,1.164,1.164,1.0);\n"
" vec4 color_y = (texture2D(tex,pos) + y_bias) * y_mult;\n"
" pos *= 0.5;\n"
" vec4 uv_bias = vec4(-0.5,-0.5,-0.5,0.0);\n"
" vec4 uv_mult = vec4(0.0,-0.391,2.018,1.0);\n"
//" vec4 uv_mult = vec4(0.0,-0.344,1.770,1.0);\n"
" vec4 color_u = (texture2D(tex,pos + off1) + uv_bias) * uv_mult;\n"
" uv_mult = vec4(1.596,-0.813,0.0,1.0);\n"
//" uv_mult = vec4(1.403,-0.714,0.0,1.0);\n"
" vec4 color_v = (texture2D(tex,pos + off2) + uv_bias) * uv_mult;\n"
" gl_FragColor = color_y + color_u + color_v;\n"
"}";
// Compile
const GLchar *src = source;
glShaderSourceARB(shader,1,&src,NULL);
if (glGetError()) throw _T("Error acquiring source for vertex shader.");
glCompileShaderARB(shader);
if (glGetError()) throw _T("Error compiling vertex shader.");
// Return
return shader;
}
/////////////////////////////////////
// Create YV12->RGB32 Shader Program
GLhandleARB OpenGLWrapper::CreateYV12Shader(float tw,float th,float tws) {
// Create vertex shader
GLhandleARB ver = OpenGLWrapper::CreateStandardVertexShader();
if (glGetError() != 0) throw _T("Error creating generic vertex shader");
// Create pixel shader
GLhandleARB pix = OpenGLWrapper::CreateYV12PixelShader();
if (glGetError() != 0) throw _T("Error creating YV12 pixel shader");
// Create program
GLhandleARB program = OpenGLWrapper::CreateShaderProgram(ver,pix);
if (glGetError() != 0) throw _T("Error creating shader program");
// Set shader
OpenGLWrapper::SetShader(program);
if (glGetError() != 0) throw _T("Error setting shader");
// Set uniform variables
GLuint address = glGetUniformLocationARB(program,"tex");
glUniform1iARB(address, 0);
address = glGetUniformLocationARB(program,"off1");
glUniform2fARB(address, 0.0f, th);
address = glGetUniformLocationARB(program,"off2");
glUniform2fARB(address, tws, th);
// Return shader
return program;
}
///////// /////////
// Mutex // Mutex

View file

@ -55,11 +55,6 @@ private:
float r2,g2,b2,a2; float r2,g2,b2,a2;
int lw; int lw;
static void Initialize();
static GLhandleARB CreateStandardVertexShader();
static GLhandleARB CreateYV12PixelShader();
static GLhandleARB CreateShaderProgram(GLhandleARB vertex,GLhandleARB pixel);
public: public:
OpenGLWrapper(); OpenGLWrapper();
@ -77,10 +72,5 @@ public:
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);
void DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3); void DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3);
static bool UseShaders();
static bool IsExtensionSupported(const char *ext); static bool IsExtensionSupported(const char *ext);
static bool ShadersAvailable();
static void SetShader(GLhandleARB i);
static void DestroyShaderProgram(GLhandleARB i);
static GLhandleARB CreateYV12Shader(float tw,float th,float tws);
}; };

View file

@ -173,7 +173,6 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) {
#else #else
SetText(_T("Subtitles Provider"),_T(DEFAULT_PROVIDER_SUBTITLE)); SetText(_T("Subtitles Provider"),_T(DEFAULT_PROVIDER_SUBTITLE));
#endif #endif
SetBool(_T("Video Use Pixel Shaders"),false,1700);
SetInt(_T("FFmpegSource max cache size"),42); SetInt(_T("FFmpegSource max cache size"),42);
SetInt(_T("FFmpegSource max cache files"),20); SetInt(_T("FFmpegSource max cache files"),20);
SetInt(_T("FFmpegSource always index all tracks"), true); SetInt(_T("FFmpegSource always index all tracks"), true);

View file

@ -100,7 +100,6 @@ VideoContext::VideoContext() {
ownGlContext = false; ownGlContext = false;
lastTex = 0; lastTex = 0;
lastFrame = -1; lastFrame = -1;
yv12shader = 0;
// Set options // Set options
audio = NULL; audio = NULL;
@ -162,12 +161,6 @@ void VideoContext::Reset() {
// Reset ?video path // Reset ?video path
StandardPaths::SetPathValue(_T("?video"),_T("")); StandardPaths::SetPathValue(_T("?video"),_T(""));
// Reset shader
if (yv12shader) {
OpenGLWrapper::DestroyShaderProgram(yv12shader);
yv12shader = 0;
}
// Clear keyframes // Clear keyframes
KeyFrames.Clear(); KeyFrames.Clear();
keyFramesLoaded = false; keyFramesLoaded = false;
@ -501,7 +494,6 @@ AegiVideoFrame VideoContext::GetFrame(int n,bool raw) {
// Get available formats // Get available formats
int formats = FORMAT_RGB32; int formats = FORMAT_RGB32;
if (yv12shader != 0 || OpenGLWrapper::UseShaders()) formats |= FORMAT_YV12;
// Get frame // Get frame
AegiVideoFrame frame = provider->GetFrame(n,formats); AegiVideoFrame frame = provider->GetFrame(n,formats);
@ -597,11 +589,6 @@ GLuint VideoContext::GetFrameAsTexture(int n) {
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
//if (glGetError() != 0) throw _T("Error setting hinting."); //if (glGetError() != 0) throw _T("Error setting hinting.");
// Create shader
if (frame.format == FORMAT_YV12 && yv12shader == 0 && OpenGLWrapper::UseShaders()) {
yv12shader = OpenGLWrapper::CreateYV12Shader(texW,texH,float(frame.pitch[1])/float(tw));
}
// Set priority // Set priority
float priority = 1.0f; float priority = 1.0f;
glPrioritizeTextures(1,&lastTex,&priority); glPrioritizeTextures(1,&lastTex,&priority);
@ -880,13 +867,6 @@ void VideoContext::SetAspectRatio(int _type, double value) {
} }
////////////////////////////
// Enable or disable shader
void VideoContext::SetShader(bool enabled) {
OpenGLWrapper::SetShader(enabled ? yv12shader : 0);
}
////////////////////// //////////////////////
// Thread constructor // Thread constructor
VideoContextThread::VideoContextThread(VideoContext *par) VideoContextThread::VideoContextThread(VideoContext *par)

View file

@ -83,7 +83,6 @@ private:
std::list<VideoDisplay*> displayList; std::list<VideoDisplay*> displayList;
GLuint lastTex; GLuint lastTex;
GLhandleARB yv12shader;
int lastFrame; int lastFrame;
bool ownGlContext; bool ownGlContext;
wxGLContext *glContext; wxGLContext *glContext;
@ -154,7 +153,6 @@ public:
float GetTexW() { return texW; } float GetTexW() { return texW; }
float GetTexH() { return texH; } float GetTexH() { return texH; }
VideoFrameFormat GetFormat() { return vidFormat; } VideoFrameFormat GetFormat() { return vidFormat; }
void SetShader(bool enabled);
bool IsLoaded() { return loaded; } bool IsLoaded() { return loaded; }
bool IsPlaying() { return isPlaying; } bool IsPlaying() { return isPlaying; }

View file

@ -278,7 +278,6 @@ try {
// Draw frame // Draw frame
glDisable(GL_BLEND); glDisable(GL_BLEND);
if (glGetError()) throw _T("Error disabling blending."); if (glGetError()) throw _T("Error disabling blending.");
context->SetShader(true);
glBindTexture(GL_TEXTURE_2D, VideoContext::Get()->GetFrameAsTexture(-1)); glBindTexture(GL_TEXTURE_2D, VideoContext::Get()->GetFrameAsTexture(-1));
if (glGetError()) throw _T("Error binding texture."); if (glGetError()) throw _T("Error binding texture.");
glColor4f(1.0f,1.0f,1.0f,1.0f); glColor4f(1.0f,1.0f,1.0f,1.0f);
@ -296,7 +295,6 @@ try {
glTexCoord2f(right,top); glTexCoord2f(right,top);
glVertex2f(sw,0); glVertex2f(sw,0);
glEnd(); glEnd();
context->SetShader(false);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
// TV effects // TV effects

View file

@ -330,10 +330,8 @@ PClip AvisynthVideoProvider::OpenVideo(Aegisub::String _filename, bool mpeg2dec3
} }
// Convert to RGB32 // Convert to RGB32
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"));
}
// Cache // Cache
AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Finished opening video, AVS mutex will be released now")); AVSTRACE(_T("AvisynthVideoProvider::OpenVideo: Finished opening video, AVS mutex will be released now"));

View file

@ -219,7 +219,6 @@ HRESULT DirectShowVideoProvider::OpenVideo(wxString _filename) {
// Set allowed types for sink // Set allowed types for sink
unsigned int types = IVS_RGB24 | IVS_RGB32; unsigned int types = IVS_RGB24 | IVS_RGB32;
if (OpenGLWrapper::UseShaders()) types = types | IVS_YV12;
sink->SetAllowedTypes(types); sink->SetAllowedTypes(types);
// Pass the event to sink, so it gets set when a frame is available // Pass the event to sink, so it gets set when a frame is available