cogl-buffer: make sure the code compiles on GL ES

OpenGL ES has no PBO extension, so we fallback to using a malloc'ed
buffer. Make sure the OpenGL-only defines don't leak into the OpenGL ES
compilation.
This commit is contained in:
Damien Lespiau 2010-02-02 16:44:16 +00:00
parent ca80e8802b
commit 273fd23742
3 changed files with 39 additions and 1 deletions

View File

@ -105,6 +105,15 @@ _cogl_buffer_fini (CoglBuffer *buffer)
cogl_buffer_unmap (buffer);
}
/* 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)
{
@ -115,7 +124,25 @@ _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)
GLenum
_cogl_buffer_hint_to_gl_enum (CoglBufferHint usage_hint)
{
switch (usage_hint)
{
case COGL_BUFFER_HINT_STATIC_DRAW:
return GL_STATIC_DRAW;
case COGL_BUFFER_HINT_DYNAMIC_DRAW:
case COGL_BUFFER_HINT_STREAM_DRAW:
return GL_DYNAMIC_DRAW;
default:
return GL_STATIC_DRAW;
}
}
#else
GLenum
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
CoglBufferUpdateHint update_hint)
@ -150,6 +177,7 @@ _cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
return GL_STATIC_DRAW;
}
#endif
void
_cogl_buffer_bind (CoglBuffer *buffer,

View File

@ -78,7 +78,9 @@
static void _cogl_pixel_buffer_free (CoglPixelBuffer *buffer);
#if !defined (COGL_HAS_GLES)
static const CoglBufferVtable cogl_pixel_buffer_vtable;
#endif
static const CoglBufferVtable cogl_malloc_pixel_buffer_vtable;
/* we don't want to use the stock COGL_HANDLE_DEFINE * for 2 reasons:
@ -149,6 +151,8 @@ cogl_pixel_buffer_new_EXP (guint size)
COGL_BUFFER_USAGE_HINT_DRAW,
COGL_BUFFER_UPDATE_HINT_STATIC);
/* malloc version only for GLES */
#if !defined (COGL_HAS_GLES)
if (cogl_features_available (COGL_FEATURE_PBOS))
{
/* PBOS */
@ -158,6 +162,7 @@ cogl_pixel_buffer_new_EXP (guint size)
COGL_BUFFER_SET_FLAG (buffer, BUFFER_OBJECT);
}
else
#endif
{
/* malloc fallback subclass */
buffer->vtable = &cogl_malloc_pixel_buffer_vtable;
@ -219,6 +224,7 @@ _cogl_pixel_buffer_free (CoglPixelBuffer *buffer)
g_slice_free (CoglPixelBuffer, buffer);
}
#if !defined (COGL_HAS_GLES)
static guchar *
_cogl_pixel_buffer_map (CoglBuffer *buffer,
CoglBufferAccess access)
@ -330,6 +336,7 @@ static const CoglBufferVtable cogl_pixel_buffer_vtable =
_cogl_pixel_buffer_unmap,
_cogl_pixel_buffer_set_data,
};
#endif
/*
* Fallback path, buffer->data points to a malloc'ed buffer.

View File

@ -465,7 +465,6 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
const guint offset)
{
CoglHandle texture;
CoglBitmap bitmap;
CoglBuffer *cogl_buffer;
CoglPixelBuffer *pixel_buffer;
@ -496,8 +495,11 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
return COGL_INVALID_HANDLE;
}
#if !defined (COGL_HAS_GLES)
if (cogl_features_available (COGL_FEATURE_PBOS))
{
CoglBitmap bitmap;
/* Wrap the data into a bitmap */
bitmap.width = width;
bitmap.height = height;
@ -510,6 +512,7 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
_cogl_buffer_bind (NULL, GL_PIXEL_UNPACK_BUFFER);
}
else
#endif
{
texture = cogl_texture_new_from_data (width,
height,