gtk/gsk/gl/gskglattachmentstateprivate.h
Benjamin Otte b5345b7f25 glrenderer: Handle filters differently
Instead of uploading a texture once per filter, ensure textures are
uploaded as little as possible and use samplers instead to switch
different filters.

Sometimes we have to reupload a texture unfortunately, when it is an
external one and we want to create mipmaps.
2023-03-18 21:33:17 -04:00

100 lines
3.1 KiB
C

/* gskglattachmentstateprivate.h
*
* Copyright 2020 Christian Hergert <chergert@redhat.com>
*
* This file 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 file 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 General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef __GSK_GL_ATTACHMENT_STATE_PRIVATE_H__
#define __GSK_GL_ATTACHMENT_STATE_PRIVATE_H__
#include "gskgltypesprivate.h"
G_BEGIN_DECLS
typedef struct _GskGLAttachmentState GskGLAttachmentState;
typedef struct _GskGLBindFramebuffer GskGLBindFramebuffer;
typedef struct _GskGLBindTexture GskGLBindTexture;
#define GSK_GL_N_FILTERS 3
static inline guint
filter_index (GLint filter)
{
switch (filter)
{
case GL_LINEAR:
return 0;
case GL_NEAREST:
return 1;
case GL_LINEAR_MIPMAP_LINEAR:
return 2;
default:
g_assert_not_reached ();
}
}
static inline guint
sampler_index (GLint min_filter,
GLint mag_filter)
{
return filter_index (min_filter) * GSK_GL_N_FILTERS + filter_index (mag_filter);
}
struct _GskGLBindTexture
{
guint changed : 1;
guint initial : 1;
GLenum target : 26;
guint sampler : 4;
GLenum texture;
guint id;
};
G_STATIC_ASSERT (sizeof (GskGLBindTexture) == 12);
struct _GskGLBindFramebuffer
{
guint changed : 1;
guint id : 31;
};
G_STATIC_ASSERT (sizeof (GskGLBindFramebuffer) == 4);
struct _GskGLAttachmentState
{
GskGLBindFramebuffer fbo;
/* Increase if shaders add more textures */
GskGLBindTexture textures[4];
guint n_changed;
};
GskGLAttachmentState *gsk_gl_attachment_state_new (void);
GskGLAttachmentState *gsk_gl_attachment_state_ref (GskGLAttachmentState *self);
void gsk_gl_attachment_state_unref (GskGLAttachmentState *self);
void gsk_gl_attachment_state_bind_texture (GskGLAttachmentState *self,
GLenum target,
GLenum texture,
guint id,
GLint min_filter,
GLint mag_filter);
void gsk_gl_attachment_state_bind_framebuffer (GskGLAttachmentState *self,
guint id);
G_END_DECLS
#endif /* __GSK_GL_ATTACHMENT_STATE_PRIVATE_H__ */