Commit b4fc0528 authored by Romain Vimont's avatar Romain Vimont
Browse files

opengl: extract sampler creation and destruction

Extract sampler creation and destruction to separate functions.
parent d32fcb11
......@@ -15,6 +15,7 @@ OPENGL_COMMONSOURCES = video_output/opengl/vout_helper.c \
video_output/opengl/interop.c video_output/opengl/interop_sw.c \
video_output/opengl/renderer.c \
video_output/opengl/renderer.h \
video_output/opengl/sampler.c \
video_output/opengl/sampler.h \
video_output/opengl/sub_renderer.c \
video_output/opengl/sub_renderer.h
......
......@@ -404,27 +404,17 @@ error:
void
vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
{
struct vlc_gl_interop *interop = renderer->interop;
struct vlc_gl_sampler *sampler = renderer->sampler;
const opengl_vtable_t *vt = renderer->vt;
vt->DeleteBuffers(1, &renderer->vertex_buffer_object);
vt->DeleteBuffers(1, &renderer->index_buffer_object);
vt->DeleteBuffers(1, &renderer->texture_buffer_object);
if (!interop->handle_texs_gen)
vt->DeleteTextures(interop->tex_count, sampler->textures);
vlc_gl_sampler_Delete(renderer->sampler);
if (renderer->program_id != 0)
vt->DeleteProgram(renderer->program_id);
#ifdef HAVE_LIBPLACEBO
FREENULL(sampler->uloc.pl_vars);
if (sampler->pl_ctx)
pl_context_destroy(&sampler->pl_ctx);
#endif
free(renderer->sampler);
free(renderer);
}
......@@ -437,12 +427,10 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
const opengl_vtable_t *vt = &api->vt;
const video_format_t *fmt = &interop->fmt;
struct vlc_gl_sampler *sampler = calloc(1, sizeof(*sampler));
struct vlc_gl_sampler *sampler = vlc_gl_sampler_New(interop);
if (!sampler)
return NULL;
sampler->interop = interop;
struct vlc_gl_renderer *renderer = calloc(1, sizeof(*renderer));
if (!renderer)
{
......@@ -465,20 +453,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
renderer->glsl_precision_header = "";
#endif
#ifdef HAVE_LIBPLACEBO
// Create the main libplacebo context
sampler->pl_ctx = vlc_placebo_Create(VLC_OBJECT(gl));
if (sampler->pl_ctx) {
# if PL_API_VER >= 20
sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL);
# elif PL_API_VER >= 6
sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0);
# else
sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0, 0);
# endif
}
#endif
int ret = opengl_link_program(renderer);
if (ret != VLC_SUCCESS)
{
......@@ -494,33 +468,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
renderer->fmt = *fmt;
/* Texture size */
for (unsigned j = 0; j < interop->tex_count; j++) {
const GLsizei w = renderer->fmt.i_visible_width * interop->texs[j].w.num
/ interop->texs[j].w.den;
const GLsizei h = renderer->fmt.i_visible_height * interop->texs[j].h.num
/ interop->texs[j].h.den;
if (api->supports_npot) {
sampler->tex_width[j] = w;
sampler->tex_height[j] = h;
} else {
sampler->tex_width[j] = vlc_align_pot(w);
sampler->tex_height[j] = vlc_align_pot(h);
}
}
if (!interop->handle_texs_gen)
{
ret = vlc_gl_interop_GenerateTextures(interop, sampler->tex_width,
sampler->tex_height,
sampler->textures);
if (ret != VLC_SUCCESS)
{
vlc_gl_renderer_Delete(renderer);
return NULL;
}
}
/* */
vt->Disable(GL_BLEND);
vt->Disable(GL_DEPTH_TEST);
......
/*****************************************************************************
* sampler.c
*****************************************************************************
* Copyright (C) 2020 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sampler.h"
#include <vlc_common.h>
#include <vlc_es.h>
#include <vlc_opengl.h>
#ifdef HAVE_LIBPLACEBO
#include <libplacebo/shaders.h>
#include <libplacebo/shaders/colorspace.h>
#include "../placebo_utils.h"
#endif
#include "gl_api.h"
#include "gl_common.h"
#include "gl_util.h"
#include "interop.h"
struct vlc_gl_sampler *
vlc_gl_sampler_New(struct vlc_gl_interop *interop)
{
struct vlc_gl_sampler *sampler = calloc(1, sizeof(*sampler));
if (!sampler)
return NULL;
sampler->interop = interop;
#ifdef HAVE_LIBPLACEBO
// Create the main libplacebo context
sampler->pl_ctx = vlc_placebo_Create(VLC_OBJECT(interop->gl));
if (sampler->pl_ctx) {
# if PL_API_VER >= 20
sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL);
# elif PL_API_VER >= 6
sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0);
# else
sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0, 0);
# endif
}
#endif
/* Texture size */
for (unsigned j = 0; j < interop->tex_count; j++) {
const GLsizei w = interop->fmt.i_visible_width * interop->texs[j].w.num
/ interop->texs[j].w.den;
const GLsizei h = interop->fmt.i_visible_height * interop->texs[j].h.num
/ interop->texs[j].h.den;
if (interop->api->supports_npot) {
sampler->tex_width[j] = w;
sampler->tex_height[j] = h;
} else {
sampler->tex_width[j] = vlc_align_pot(w);
sampler->tex_height[j] = vlc_align_pot(h);
}
}
if (!interop->handle_texs_gen)
{
int ret = vlc_gl_interop_GenerateTextures(interop, sampler->tex_width,
sampler->tex_height,
sampler->textures);
if (ret != VLC_SUCCESS)
{
free(sampler);
return NULL;
}
}
return sampler;
}
void
vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler)
{
struct vlc_gl_interop *interop = sampler->interop;
const opengl_vtable_t *vt = interop->vt;
if (!interop->handle_texs_gen)
vt->DeleteTextures(interop->tex_count, sampler->textures);
#ifdef HAVE_LIBPLACEBO
FREENULL(sampler->uloc.pl_vars);
if (sampler->pl_ctx)
pl_context_destroy(&sampler->pl_ctx);
#endif
free(sampler);
}
......@@ -89,4 +89,20 @@ struct vlc_gl_sampler {
struct vlc_gl_interop *interop;
};
/**
* Create a new sampler
*
* \param interop the interop
*/
struct vlc_gl_sampler *
vlc_gl_sampler_New(struct vlc_gl_interop *interop);
/**
* Delete a sampler
*
* \param sampler the sampler
*/
void
vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment