cogl/matrix-stack: Move GL code to GL

This commit is contained in:
Georges Basile Stavracas Neto 2019-02-27 15:51:23 -03:00
parent 97206476ac
commit 88be11f6e2
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385
3 changed files with 120 additions and 133 deletions

View File

@ -170,13 +170,6 @@ typedef enum
COGL_MATRIX_TEXTURE COGL_MATRIX_TEXTURE
} CoglMatrixMode; } CoglMatrixMode;
void
_cogl_matrix_entry_flush_to_gl_builtins (CoglContext *ctx,
CoglMatrixEntry *entry,
CoglMatrixMode mode,
CoglFramebuffer *framebuffer,
gboolean disable_flip);
void void
_cogl_matrix_entry_cache_init (CoglMatrixEntryCache *cache); _cogl_matrix_entry_cache_init (CoglMatrixEntryCache *cache);

View File

@ -801,127 +801,6 @@ cogl_matrix_entry_is_identity (CoglMatrixEntry *entry)
return entry ? entry->op == COGL_MATRIX_OP_LOAD_IDENTITY : FALSE; return entry ? entry->op == COGL_MATRIX_OP_LOAD_IDENTITY : FALSE;
} }
static void
_cogl_matrix_flush_to_gl_builtin (CoglContext *ctx,
gboolean is_identity,
CoglMatrix *matrix,
CoglMatrixMode mode)
{
g_assert (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED));
#ifdef HAVE_COGL_GL
if (ctx->flushed_matrix_mode != mode)
{
GLenum gl_mode = 0;
switch (mode)
{
case COGL_MATRIX_MODELVIEW:
gl_mode = GL_MODELVIEW;
break;
case COGL_MATRIX_PROJECTION:
gl_mode = GL_PROJECTION;
break;
case COGL_MATRIX_TEXTURE:
gl_mode = GL_TEXTURE;
break;
}
GE (ctx, glMatrixMode (gl_mode));
ctx->flushed_matrix_mode = mode;
}
if (is_identity)
GE (ctx, glLoadIdentity ());
else
GE (ctx, glLoadMatrixf (cogl_matrix_get_array (matrix)));
#endif
}
void
_cogl_matrix_entry_flush_to_gl_builtins (CoglContext *ctx,
CoglMatrixEntry *entry,
CoglMatrixMode mode,
CoglFramebuffer *framebuffer,
gboolean disable_flip)
{
g_assert (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED));
#ifdef HAVE_COGL_GL
{
gboolean needs_flip;
CoglMatrixEntryCache *cache;
if (mode == COGL_MATRIX_PROJECTION)
{
/* Because Cogl defines texture coordinates to have a top left
* origin and because offscreen framebuffers may be used for
* rendering to textures we always render upside down to
* offscreen buffers. Also for some backends we need to render
* onscreen buffers upside-down too.
*/
if (disable_flip)
needs_flip = FALSE;
else
needs_flip = cogl_is_offscreen (framebuffer);
cache = &ctx->builtin_flushed_projection;
}
else
{
needs_flip = FALSE;
if (mode == COGL_MATRIX_MODELVIEW)
cache = &ctx->builtin_flushed_modelview;
else
cache = NULL;
}
/* We don't need to do anything if the state is the same */
if (!cache ||
_cogl_matrix_entry_cache_maybe_update (cache, entry, needs_flip))
{
gboolean is_identity;
CoglMatrix matrix;
if (entry->op == COGL_MATRIX_OP_LOAD_IDENTITY)
is_identity = TRUE;
else
{
is_identity = FALSE;
cogl_matrix_entry_get (entry, &matrix);
}
if (needs_flip)
{
CoglMatrix flipped_matrix;
cogl_matrix_multiply (&flipped_matrix,
&ctx->y_flip_matrix,
is_identity ?
&ctx->identity_matrix :
&matrix);
_cogl_matrix_flush_to_gl_builtin (ctx,
/* not identity */
FALSE,
&flipped_matrix,
mode);
}
else
{
_cogl_matrix_flush_to_gl_builtin (ctx,
is_identity,
&matrix,
mode);
}
}
}
#endif
}
gboolean gboolean
cogl_matrix_entry_equal (CoglMatrixEntry *entry0, cogl_matrix_entry_equal (CoglMatrixEntry *entry0,
CoglMatrixEntry *entry1) CoglMatrixEntry *entry1)

View File

@ -50,6 +50,121 @@
#define GL_CLIP_PLANE5 0x3005 #define GL_CLIP_PLANE5 0x3005
#endif #endif
static void
flush_matrix_to_gl_builtin (CoglContext *ctx,
gboolean is_identity,
CoglMatrix *matrix,
CoglMatrixMode mode)
{
g_assert (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED));
#ifdef HAVE_COGL_GL
if (ctx->flushed_matrix_mode != mode)
{
GLenum gl_mode = 0;
switch (mode)
{
case COGL_MATRIX_MODELVIEW:
gl_mode = GL_MODELVIEW;
break;
case COGL_MATRIX_PROJECTION:
gl_mode = GL_PROJECTION;
break;
case COGL_MATRIX_TEXTURE:
gl_mode = GL_TEXTURE;
break;
}
GE (ctx, glMatrixMode (gl_mode));
ctx->flushed_matrix_mode = mode;
}
if (is_identity)
GE (ctx, glLoadIdentity ());
else
GE (ctx, glLoadMatrixf (cogl_matrix_get_array (matrix)));
#endif
}
static void
flush_matrix_entry_to_gl_builtins (CoglContext *ctx,
CoglMatrixEntry *entry,
CoglMatrixMode mode,
CoglFramebuffer *framebuffer,
gboolean disable_flip)
{
g_assert (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_GL_FIXED));
#ifdef HAVE_COGL_GL
{
gboolean needs_flip;
CoglMatrixEntryCache *cache;
if (mode == COGL_MATRIX_PROJECTION)
{
/* Because Cogl defines texture coordinates to have a top left
* origin and because offscreen framebuffers may be used for
* rendering to textures we always render upside down to
* offscreen buffers. Also for some backends we need to render
* onscreen buffers upside-down too.
*/
if (disable_flip)
needs_flip = FALSE;
else
needs_flip = cogl_is_offscreen (framebuffer);
cache = &ctx->builtin_flushed_projection;
}
else
{
needs_flip = FALSE;
if (mode == COGL_MATRIX_MODELVIEW)
cache = &ctx->builtin_flushed_modelview;
else
cache = NULL;
}
/* We don't need to do anything if the state is the same */
if (!cache ||
_cogl_matrix_entry_cache_maybe_update (cache, entry, needs_flip))
{
gboolean is_identity;
CoglMatrix matrix;
if (entry->op == COGL_MATRIX_OP_LOAD_IDENTITY)
is_identity = TRUE;
else
{
is_identity = FALSE;
cogl_matrix_entry_get (entry, &matrix);
}
if (needs_flip)
{
CoglMatrix flipped_matrix;
cogl_matrix_multiply (&flipped_matrix,
&ctx->y_flip_matrix,
is_identity ?
&ctx->identity_matrix :
&matrix);
flush_matrix_to_gl_builtin (ctx, FALSE, &flipped_matrix, mode);
}
else
{
flush_matrix_to_gl_builtin (ctx, is_identity, &matrix, mode);
}
}
}
#endif
}
static void static void
project_vertex (const CoglMatrix *modelview_projection, project_vertex (const CoglMatrix *modelview_projection,
float *vertex) float *vertex)
@ -106,7 +221,7 @@ set_clip_plane (CoglFramebuffer *framebuffer,
/* Clip planes can only be used when a fixed function backend is in /* Clip planes can only be used when a fixed function backend is in
use so we know we can directly push this matrix to the builtin use so we know we can directly push this matrix to the builtin
state */ state */
_cogl_matrix_entry_flush_to_gl_builtins (ctx, flush_matrix_entry_to_gl_builtins (ctx,
modelview_stack->last_entry, modelview_stack->last_entry,
COGL_MATRIX_MODELVIEW, COGL_MATRIX_MODELVIEW,
framebuffer, framebuffer,