cogl-buffer: Support mapping buffers for write on GLES

GLES has an extension called GL_OES_mapbuffer to support mapping
buffer objects but only for writing. Cogl now has two new feature
flags to advertise whether mapping for reading and writing is
supported. Under OpenGL, these features are always set if the VBO
extension is advertised and under GLES only the write flag is set if
the GL_OES_mapbuffer extension is advertised.
This commit is contained in:
Neil Roberts 2011-01-13 15:54:50 +00:00
parent 7e73f0d423
commit 88fe56d175
4 changed files with 42 additions and 26 deletions

View File

@ -57,11 +57,13 @@
#define glBufferSubData ctx->drv.pf_glBufferSubData
#define glGetBufferSubData ctx->drv.pf_glGetBufferSubData
#define glDeleteBuffers ctx->drv.pf_glDeleteBuffers
#define glMapBuffer ctx->drv.pf_glMapBuffer
#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
#endif
/* These two are always accessed through an extension, even on GLES */
#define glMapBuffer ctx->drv.pf_glMapBuffer
#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
#ifndef GL_PIXEL_PACK_BUFFER
#define GL_PIXEL_PACK_BUFFER 0x88EB
#endif
@ -74,6 +76,15 @@
#ifndef GL_ELEMENT_ARRAY_BUFFER
#define GL_ARRAY_BUFFER 0x8893
#endif
#ifndef GL_READ_ONLY
#define GL_READ_ONLY 0x88B8
#endif
#ifndef GL_WRITE_ONLY
#define GL_WRITE_ONLY 0x88B9
#endif
#ifndef GL_READ_WRITE
#define GL_READ_WRITE 0x88BA
#endif
/* XXX:
* The CoglHandle macros don't support any form of inheritance, so for
@ -131,13 +142,19 @@ bo_map (CoglBuffer *buffer,
CoglBufferAccess access,
CoglBufferMapHint hints)
{
#ifndef COGL_HAS_GLES
guint8 *data;
CoglBufferBindTarget target;
GLenum gl_target;
_COGL_GET_CONTEXT (ctx, NULL);
if ((access & COGL_BUFFER_ACCESS_READ) &&
!cogl_features_available (COGL_FEATURE_MAP_BUFFER_FOR_READ))
return NULL;
if ((access & COGL_BUFFER_ACCESS_WRITE) &&
!cogl_features_available (COGL_FEATURE_MAP_BUFFER_FOR_WRITE))
return NULL;
target = buffer->last_target;
_cogl_buffer_bind (buffer, target);
@ -164,18 +181,11 @@ bo_map (CoglBuffer *buffer,
_cogl_buffer_unbind (buffer);
return data;
#else /* COGL_HAS_GLES */
return NULL;
#endif /* COGL_HAS_GLES */
}
static void
bo_unmap (CoglBuffer *buffer)
{
#ifndef COGL_HAS_GLES
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
_cogl_buffer_bind (buffer, buffer->last_target);
@ -184,9 +194,6 @@ bo_unmap (CoglBuffer *buffer)
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
_cogl_buffer_unbind (buffer);
#else
g_return_if_reached ();
#endif
}
static gboolean
@ -306,16 +313,6 @@ _cogl_buffer_fini (CoglBuffer *buffer)
g_free (buffer->data);
}
/* OpenGL ES 1.1 and 2 have a GL_OES_mapbuffer extension that is able to map
* VBOs for write only, we don't support that in CoglBuffer */
#if defined (COGL_HAS_GLES)
GLenum
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
{
return 0;
}
#else
GLenum
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
{
@ -326,7 +323,6 @@ _cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
else
return GL_READ_ONLY;
}
#endif
/* OpenGL ES 1.1 and 2 only know about STATIC_DRAW and DYNAMIC_DRAW */
#if defined (COGL_HAS_GLES)

View File

@ -252,6 +252,10 @@ typedef enum { /*< prefix=COGL_PIXEL_FORMAT >*/
* @COGL_FEATURE_POINT_SPRITE: Whether
* cogl_material_set_layer_point_sprite_coords_enabled() is supported.
* @COGL_FEATURE_TEXTURE_3D: 3D texture support
* @COGL_FEATURE_MAP_BUFFER_FOR_READ: Whether cogl_buffer_map() is
* supported with CoglBufferAccess including read support.
* @COGL_FEATURE_MAP_BUFFER_FOR_WRITE: Whether cogl_buffer_map() is
* supported with CoglBufferAccess including write support.
*
* Flags for the supported features.
*
@ -278,7 +282,9 @@ typedef enum
COGL_FEATURE_TEXTURE_NPOT_REPEAT = (1 << 17),
COGL_FEATURE_POINT_SPRITE = (1 << 18),
COGL_FEATURE_TEXTURE_3D = (1 << 19),
COGL_FEATURE_SHADERS_ARBFP = (1 << 20)
COGL_FEATURE_SHADERS_ARBFP = (1 << 20),
COGL_FEATURE_MAP_BUFFER_FOR_READ = (1 << 21),
COGL_FEATURE_MAP_BUFFER_FOR_WRITE = (1 << 22)
} CoglFeatureFlags;
/**

View File

@ -295,7 +295,9 @@ COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (vbos, 1, 5,
"ARB\0",
"vertex_buffer_object\0",
COGL_FEATURE_VBOS,
COGL_FEATURE_VBOS |
COGL_FEATURE_MAP_BUFFER_FOR_READ |
COGL_FEATURE_MAP_BUFFER_FOR_WRITE,
0)
COGL_FEATURE_FUNCTION (void, glGenBuffers,
(GLuint n,

View File

@ -109,3 +109,15 @@ COGL_FEATURE_FUNCTION (void, glTexSubImage3D,
GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, const GLvoid* pixels))
COGL_FEATURE_END ()
COGL_FEATURE_BEGIN (map_buffer, 255, 255,
"OES\0",
"mapbuffer\0",
COGL_FEATURE_MAP_BUFFER_FOR_WRITE,
0)
COGL_FEATURE_FUNCTION (void *, glMapBuffer,
(GLenum target,
GLenum access))
COGL_FEATURE_FUNCTION (GLboolean, glUnmapBuffer,
(GLenum target))
COGL_FEATURE_END ()