#include <stdlib.h>
#include <string>
-#include "glsl_manager.h"
+#include "filter_glsl_manager.h"
#include <movit/init.h>
#include <movit/util.h>
#include <movit/effect_chain.h>
#include <framework/mlt_factory.h>
}
+#if defined(__DARWIN__)
+#include <OpenGL/OpenGL.h>
+#elif defined(WIN32)
+#include <wingdi.h>
+#else
+#include <GL/glx.h>
+#endif
+
void deleteManager(GlslManager *p)
{
delete p;
{
mlt_log_debug(get_service(), "%s\n", __FUNCTION__);
cleanupContext();
+// XXX If there is still a frame holding a reference to a texture after this
+// destructor is called, then it will crash in release_texture().
+// while (texture_list.peek_back())
+// delete (glsl_texture) texture_list.pop_back();
delete initEvent;
delete closeEvent;
}
glsl_fbo GlslManager::get_fbo(int width, int height)
{
+#if defined(__DARWIN__)
+ CGLContextObj context = CGLGetCurrentContext();
+#elif defined(WIN32)
+ HGLRC context = wglGetCurrentContext();
+#else
+ GLXContext context = glXGetCurrentContext();
+#endif
+
lock();
for (int i = 0; i < fbo_list.count(); ++i) {
glsl_fbo fbo = (glsl_fbo) fbo_list.peek(i);
- if (!fbo->used && (fbo->width == width) && (fbo->height == height)) {
+ if (!fbo->used && (fbo->width == width) && (fbo->height == height) && (fbo->context == context)) {
fbo->used = 1;
unlock();
return fbo;
fbo->width = width;
fbo->height = height;
fbo->used = 1;
+ fbo->context = context;
lock();
fbo_list.push_back(fbo);
unlock();
return tex;
}
}
+
+ // Recycle a glsl_texture with deleted glTexture.
+ glsl_texture gtex = 0;
+ for (int i = 0; i < texture_list.count(); ++i) {
+ glsl_texture tex = (glsl_texture) texture_list.peek(i);
+ if (!tex->used && !tex->width && !tex->height) {
+ gtex = tex;
+ break;
+ }
+ }
unlock();
GLuint tex = 0;
glGenTextures(1, &tex);
- if (!tex)
+ if (!tex) {
+ glDeleteTextures(1, &tex);
return NULL;
+ }
- glsl_texture gtex = new glsl_texture_s;
if (!gtex) {
- glDeleteTextures(1, &tex);
- return NULL;
+ gtex = new glsl_texture_s;
+ if (!gtex)
+ return NULL;
}
+
glBindTexture( GL_TEXTURE_2D, tex );
glTexImage2D( GL_TEXTURE_2D, 0, internal_format, width, height, 0, internal_format, GL_UNSIGNED_BYTE, NULL );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glDeleteFramebuffers(1, &fbo->fbo);
delete fbo;
}
- while (texture_list.peek_back()) {
- glsl_texture texture = (glsl_texture) texture_list.pop_back();
+ for (int i = 0; i < texture_list.count(); ++i) {
+ glsl_texture texture = (glsl_texture) texture_list.peek(i);
glDeleteTextures(1, &texture->texture);
- delete texture;
+ texture->used = 0;
+ texture->width = 0;
+ texture->height = 0;
}
if (pbo) {
glDeleteBuffers(1, &pbo->pbo);