aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/vbo
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/vbo')
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec.h1
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_api.c149
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_draw.c62
-rw-r--r--mesalib/src/mesa/vbo/vbo_noop.c519
-rw-r--r--mesalib/src/mesa/vbo/vbo_noop.h45
-rw-r--r--mesalib/src/mesa/vbo/vbo_save.h3
-rw-r--r--mesalib/src/mesa/vbo/vbo_save_api.c171
7 files changed, 896 insertions, 54 deletions
diff --git a/mesalib/src/mesa/vbo/vbo_exec.h b/mesalib/src/mesa/vbo/vbo_exec.h
index 0b72579a8..8d6b8f95a 100644
--- a/mesalib/src/mesa/vbo/vbo_exec.h
+++ b/mesalib/src/mesa/vbo/vbo_exec.h
@@ -82,6 +82,7 @@ struct vbo_exec_context
{
struct gl_context *ctx;
GLvertexformat vtxfmt;
+ GLvertexformat vtxfmt_noop;
struct {
struct gl_buffer_object *bufferobj;
diff --git a/mesalib/src/mesa/vbo/vbo_exec_api.c b/mesalib/src/mesa/vbo/vbo_exec_api.c
index 5f3ed9d5d..62e7d03f3 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_api.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_api.c
@@ -41,11 +41,12 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/state.h"
#include "main/light.h"
#include "main/api_arrayelt.h"
-#include "main/api_noop.h"
#include "main/api_validate.h"
#include "main/dispatch.h"
#include "vbo_context.h"
+#include "vbo_noop.h"
+
#ifdef ERROR
#undef ERROR
@@ -546,13 +547,146 @@ static void GLAPIENTRY vbo_exec_EvalPoint2( GLint i, GLint j )
vbo_exec_EvalCoord2f( u, v );
}
-/* use noop eval mesh */
-#define vbo_exec_EvalMesh1 _mesa_noop_EvalMesh1
-#define vbo_exec_EvalMesh2 _mesa_noop_EvalMesh2
+
+static void GLAPIENTRY
+vbo_exec_EvalMesh1(GLenum mode, GLint i1, GLint i2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLint i;
+ GLfloat u, du;
+ GLenum prim;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ switch (mode) {
+ case GL_POINT:
+ prim = GL_POINTS;
+ break;
+ case GL_LINE:
+ prim = GL_LINE_STRIP;
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh1(mode)" );
+ return;
+ }
+
+ /* No effect if vertex maps disabled.
+ */
+ if (!ctx->Eval.Map1Vertex4 &&
+ !ctx->Eval.Map1Vertex3 &&
+ !(ctx->VertexProgram._Enabled && ctx->Eval.Map1Attrib[VERT_ATTRIB_POS]))
+ return;
+
+ du = ctx->Eval.MapGrid1du;
+ u = ctx->Eval.MapGrid1u1 + i1 * du;
+
+ CALL_Begin(GET_DISPATCH(), (prim));
+ for (i=i1;i<=i2;i++,u+=du) {
+ CALL_EvalCoord1f(GET_DISPATCH(), (u));
+ }
+ CALL_End(GET_DISPATCH(), ());
+}
+
+
+static void GLAPIENTRY
+vbo_exec_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLfloat u, du, v, dv, v1, u1;
+ GLint i, j;
+
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ switch (mode) {
+ case GL_POINT:
+ case GL_LINE:
+ case GL_FILL:
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)" );
+ return;
+ }
+
+ /* No effect if vertex maps disabled.
+ */
+ if (!ctx->Eval.Map2Vertex4 &&
+ !ctx->Eval.Map2Vertex3 &&
+ !(ctx->VertexProgram._Enabled && ctx->Eval.Map2Attrib[VERT_ATTRIB_POS]))
+ return;
+
+ du = ctx->Eval.MapGrid2du;
+ dv = ctx->Eval.MapGrid2dv;
+ v1 = ctx->Eval.MapGrid2v1 + j1 * dv;
+ u1 = ctx->Eval.MapGrid2u1 + i1 * du;
+
+ switch (mode) {
+ case GL_POINT:
+ CALL_Begin(GET_DISPATCH(), (GL_POINTS));
+ for (v=v1,j=j1;j<=j2;j++,v+=dv) {
+ for (u=u1,i=i1;i<=i2;i++,u+=du) {
+ CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+ }
+ }
+ CALL_End(GET_DISPATCH(), ());
+ break;
+ case GL_LINE:
+ for (v=v1,j=j1;j<=j2;j++,v+=dv) {
+ CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP));
+ for (u=u1,i=i1;i<=i2;i++,u+=du) {
+ CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+ }
+ CALL_End(GET_DISPATCH(), ());
+ }
+ for (u=u1,i=i1;i<=i2;i++,u+=du) {
+ CALL_Begin(GET_DISPATCH(), (GL_LINE_STRIP));
+ for (v=v1,j=j1;j<=j2;j++,v+=dv) {
+ CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+ }
+ CALL_End(GET_DISPATCH(), ());
+ }
+ break;
+ case GL_FILL:
+ for (v=v1,j=j1;j<j2;j++,v+=dv) {
+ CALL_Begin(GET_DISPATCH(), (GL_TRIANGLE_STRIP));
+ for (u=u1,i=i1;i<=i2;i++,u+=du) {
+ CALL_EvalCoord2f(GET_DISPATCH(), (u, v));
+ CALL_EvalCoord2f(GET_DISPATCH(), (u, v+dv));
+ }
+ CALL_End(GET_DISPATCH(), ());
+ }
+ break;
+ default:
+ _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)" );
+ return;
+ }
+}
#endif /* FEATURE_evaluators */
+/**
+ * Execute a glRectf() function. This is not suitable for GL_COMPILE
+ * modes (as the test for outside begin/end is not compiled),
+ * but may be useful for drivers in circumstances which exclude
+ * display list interactions.
+ *
+ * (None of the functions in this file are suitable for GL_COMPILE
+ * modes).
+ */
+static void GLAPIENTRY
+vbo_exec_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ CALL_Begin(GET_DISPATCH(), (GL_QUADS));
+ CALL_Vertex2f(GET_DISPATCH(), (x1, y1));
+ CALL_Vertex2f(GET_DISPATCH(), (x2, y1));
+ CALL_Vertex2f(GET_DISPATCH(), (x2, y2));
+ CALL_Vertex2f(GET_DISPATCH(), (x1, y2));
+ CALL_End(GET_DISPATCH(), ());
+}
+
/**
* Called via glBegin.
@@ -673,7 +807,7 @@ static void vbo_exec_vtxfmt_init( struct vbo_exec_context *exec )
_MESA_INIT_DLIST_VTXFMT(vfmt, _mesa_);
_MESA_INIT_EVAL_VTXFMT(vfmt, vbo_exec_);
- vfmt->Rectf = _mesa_noop_Rectf;
+ vfmt->Rectf = vbo_exec_Rectf;
/* from attrib_tmp.h:
*/
@@ -896,7 +1030,9 @@ void vbo_use_buffer_objects(struct gl_context *ctx)
/* Allocate a real buffer object now */
_mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
- ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
+ if (!ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "VBO allocation");
+ }
}
@@ -933,6 +1069,7 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
vbo_exec_vtxfmt_init( exec );
+ _mesa_noop_vtxfmt_init(&exec->vtxfmt_noop);
/* Hook our functions into the dispatch table.
*/
diff --git a/mesalib/src/mesa/vbo/vbo_exec_draw.c b/mesalib/src/mesa/vbo/vbo_exec_draw.c
index 8ffaaaa48..efb6dd10a 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_draw.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_draw.c
@@ -28,11 +28,14 @@
#include "main/glheader.h"
#include "main/bufferobj.h"
#include "main/compiler.h"
+#include "main/context.h"
#include "main/enums.h"
#include "main/mfeatures.h"
#include "main/state.h"
+#include "main/vtxfmt.h"
#include "vbo_context.h"
+#include "vbo_noop.h"
#if FEATURE_beginend
@@ -308,32 +311,55 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
if (VBO_VERT_BUFFER_SIZE > exec->vtx.buffer_used + 1024) {
/* The VBO exists and there's room for more */
- exec->vtx.buffer_map =
- (GLfloat *)ctx->Driver.MapBufferRange(ctx,
- exec->vtx.buffer_used,
- (VBO_VERT_BUFFER_SIZE -
- exec->vtx.buffer_used),
- accessRange,
- exec->vtx.bufferobj);
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ if (exec->vtx.bufferobj->Size > 0) {
+ exec->vtx.buffer_map =
+ (GLfloat *)ctx->Driver.MapBufferRange(ctx,
+ exec->vtx.buffer_used,
+ (VBO_VERT_BUFFER_SIZE -
+ exec->vtx.buffer_used),
+ accessRange,
+ exec->vtx.bufferobj);
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ }
+ else {
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map = NULL;
+ }
}
if (!exec->vtx.buffer_map) {
/* Need to allocate a new VBO */
exec->vtx.buffer_used = 0;
- ctx->Driver.BufferData(ctx, GL_ARRAY_BUFFER_ARB,
- VBO_VERT_BUFFER_SIZE,
- NULL, usage, exec->vtx.bufferobj);
+ if (ctx->Driver.BufferData(ctx, GL_ARRAY_BUFFER_ARB,
+ VBO_VERT_BUFFER_SIZE,
+ NULL, usage, exec->vtx.bufferobj)) {
+ /* buffer allocation worked, now map the buffer */
+ exec->vtx.buffer_map =
+ (GLfloat *)ctx->Driver.MapBufferRange(ctx,
+ 0, VBO_VERT_BUFFER_SIZE,
+ accessRange,
+ exec->vtx.bufferobj);
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "VBO allocation");
+ exec->vtx.buffer_map = NULL;
+ }
+ }
+ exec->vtx.buffer_ptr = exec->vtx.buffer_map;
- exec->vtx.buffer_map =
- (GLfloat *)ctx->Driver.MapBufferRange(ctx,
- 0, VBO_VERT_BUFFER_SIZE,
- accessRange,
- exec->vtx.bufferobj);
- assert(exec->vtx.buffer_map);
- exec->vtx.buffer_ptr = exec->vtx.buffer_map;
+ if (!exec->vtx.buffer_map) {
+ /* out of memory */
+ _mesa_install_exec_vtxfmt( ctx, &exec->vtxfmt_noop );
+ }
+ else {
+ if (_mesa_using_noop_vtxfmt(ctx->Exec)) {
+ /* The no-op functions are installed so switch back to regular
+ * functions. We do this test just to avoid frequent and needless
+ * calls to _mesa_install_exec_vtxfmt().
+ */
+ _mesa_install_exec_vtxfmt(ctx, &exec->vtxfmt);
+ }
}
if (0)
diff --git a/mesalib/src/mesa/vbo/vbo_noop.c b/mesalib/src/mesa/vbo/vbo_noop.c
new file mode 100644
index 000000000..430011207
--- /dev/null
+++ b/mesalib/src/mesa/vbo/vbo_noop.c
@@ -0,0 +1,519 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2011 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * GLvertexformat no-op functions. Used in out-of-memory situations.
+ */
+
+
+#include "main/glheader.h"
+#include "main/api_arrayelt.h"
+#include "main/context.h"
+#include "main/dispatch.h"
+#include "main/dlist.h"
+#include "main/eval.h"
+#include "main/mfeatures.h"
+#include "vbo/vbo_noop.h"
+
+#if FEATURE_beginend
+
+
+static void GLAPIENTRY
+_mesa_noop_EdgeFlag(GLboolean b)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Indexf(GLfloat f)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Indexfv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_FogCoordfEXT(GLfloat a)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_FogCoordfvEXT(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Normal3f(GLfloat a, GLfloat b, GLfloat c)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Normal3fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Color4f(GLfloat a, GLfloat b, GLfloat c, GLfloat d)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Color4fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Color3f(GLfloat a, GLfloat b, GLfloat c)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Color3fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord1fARB(GLenum target, GLfloat a)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord1fvARB(GLenum target, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord2fARB(GLenum target, GLfloat a, GLfloat b)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord2fvARB(GLenum target, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord3fARB(GLenum target, GLfloat a, GLfloat b, GLfloat c)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord3fvARB(GLenum target, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord4fARB(GLenum target, GLfloat a, GLfloat b,
+ GLfloat c, GLfloat d)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiTexCoord4fvARB(GLenum target, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_SecondaryColor3fEXT(GLfloat a, GLfloat b, GLfloat c)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_SecondaryColor3fvEXT(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord1f(GLfloat a)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord1fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord2f(GLfloat a, GLfloat b)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord2fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord3f(GLfloat a, GLfloat b, GLfloat c)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord3fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord4f(GLfloat a, GLfloat b, GLfloat c, GLfloat d)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_TexCoord4fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib1fNV(GLuint index, GLfloat x)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib1fvNV(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib2fvNV(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib3fvNV(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib4fNV(GLuint index, GLfloat x,
+ GLfloat y, GLfloat z, GLfloat w)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib4fvNV(GLuint index, const GLfloat * v)
+{
+}
+
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib1fARB(GLuint index, GLfloat x)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib1fvARB(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib2fvARB(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib3fvARB(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib4fARB(GLuint index, GLfloat x,
+ GLfloat y, GLfloat z, GLfloat w)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_VertexAttrib4fvARB(GLuint index, const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Materialfv(GLenum face, GLenum pname, const GLfloat * params)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Vertex2fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Vertex3fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Vertex4fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Vertex2f(GLfloat a, GLfloat b)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Vertex3f(GLfloat a, GLfloat b, GLfloat c)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_Vertex4f(GLfloat a, GLfloat b, GLfloat c, GLfloat d)
+{
+}
+
+
+#if FEATURE_evaluators
+static void GLAPIENTRY
+_mesa_noop_EvalCoord1f(GLfloat a)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalCoord1fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalCoord2f(GLfloat a, GLfloat b)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalCoord2fv(const GLfloat * v)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalPoint1(GLint a)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalPoint2(GLint a, GLint b)
+{
+}
+#endif /* FEATURE_evaluators */
+
+
+static void GLAPIENTRY
+_mesa_noop_Begin(GLenum mode)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_End(void)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_PrimitiveRestartNV(void)
+{
+}
+
+
+static void GLAPIENTRY
+_mesa_noop_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+}
+
+
+static void GLAPIENTRY
+_mesa_noop_DrawArrays(GLenum mode, GLint start, GLsizei count)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_DrawElements(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid * indices)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
+ const GLvoid * indices, GLint basevertex)
+{
+}
+
+
+static void GLAPIENTRY
+_mesa_noop_DrawRangeElements(GLenum mode,
+ GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid * indices)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiDrawElements(GLenum mode, const GLsizei * count, GLenum type,
+ const GLvoid ** indices, GLsizei primcount)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_DrawRangeElementsBaseVertex(GLenum mode,
+ GLuint start, GLuint end,
+ GLsizei count, GLenum type,
+ const GLvoid * indices,
+ GLint basevertex)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei * count,
+ GLenum type,
+ const GLvoid ** indices,
+ GLsizei primcount,
+ const GLint * basevertex)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalMesh1(GLenum mode, GLint i1, GLint i2)
+{
+}
+
+static void GLAPIENTRY
+_mesa_noop_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2)
+{
+}
+
+
+/**
+ * Build a vertexformat of functions that are no-ops.
+ * These are used in out-of-memory situations when we have no VBO
+ * to put the vertex data into.
+ */
+void
+_mesa_noop_vtxfmt_init(GLvertexformat * vfmt)
+{
+ _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_);
+
+ vfmt->Begin = _mesa_noop_Begin;
+
+ _MESA_INIT_DLIST_VTXFMT(vfmt, _mesa_);
+
+ vfmt->Color3f = _mesa_noop_Color3f;
+ vfmt->Color3fv = _mesa_noop_Color3fv;
+ vfmt->Color4f = _mesa_noop_Color4f;
+ vfmt->Color4fv = _mesa_noop_Color4fv;
+ vfmt->EdgeFlag = _mesa_noop_EdgeFlag;
+ vfmt->End = _mesa_noop_End;
+
+ vfmt->PrimitiveRestartNV = _mesa_noop_PrimitiveRestartNV;
+
+ _MESA_INIT_EVAL_VTXFMT(vfmt, _mesa_noop_);
+
+ vfmt->FogCoordfEXT = _mesa_noop_FogCoordfEXT;
+ vfmt->FogCoordfvEXT = _mesa_noop_FogCoordfvEXT;
+ vfmt->Indexf = _mesa_noop_Indexf;
+ vfmt->Indexfv = _mesa_noop_Indexfv;
+ vfmt->Materialfv = _mesa_noop_Materialfv;
+ vfmt->MultiTexCoord1fARB = _mesa_noop_MultiTexCoord1fARB;
+ vfmt->MultiTexCoord1fvARB = _mesa_noop_MultiTexCoord1fvARB;
+ vfmt->MultiTexCoord2fARB = _mesa_noop_MultiTexCoord2fARB;
+ vfmt->MultiTexCoord2fvARB = _mesa_noop_MultiTexCoord2fvARB;
+ vfmt->MultiTexCoord3fARB = _mesa_noop_MultiTexCoord3fARB;
+ vfmt->MultiTexCoord3fvARB = _mesa_noop_MultiTexCoord3fvARB;
+ vfmt->MultiTexCoord4fARB = _mesa_noop_MultiTexCoord4fARB;
+ vfmt->MultiTexCoord4fvARB = _mesa_noop_MultiTexCoord4fvARB;
+ vfmt->Normal3f = _mesa_noop_Normal3f;
+ vfmt->Normal3fv = _mesa_noop_Normal3fv;
+ vfmt->SecondaryColor3fEXT = _mesa_noop_SecondaryColor3fEXT;
+ vfmt->SecondaryColor3fvEXT = _mesa_noop_SecondaryColor3fvEXT;
+ vfmt->TexCoord1f = _mesa_noop_TexCoord1f;
+ vfmt->TexCoord1fv = _mesa_noop_TexCoord1fv;
+ vfmt->TexCoord2f = _mesa_noop_TexCoord2f;
+ vfmt->TexCoord2fv = _mesa_noop_TexCoord2fv;
+ vfmt->TexCoord3f = _mesa_noop_TexCoord3f;
+ vfmt->TexCoord3fv = _mesa_noop_TexCoord3fv;
+ vfmt->TexCoord4f = _mesa_noop_TexCoord4f;
+ vfmt->TexCoord4fv = _mesa_noop_TexCoord4fv;
+ vfmt->Vertex2f = _mesa_noop_Vertex2f;
+ vfmt->Vertex2fv = _mesa_noop_Vertex2fv;
+ vfmt->Vertex3f = _mesa_noop_Vertex3f;
+ vfmt->Vertex3fv = _mesa_noop_Vertex3fv;
+ vfmt->Vertex4f = _mesa_noop_Vertex4f;
+ vfmt->Vertex4fv = _mesa_noop_Vertex4fv;
+ vfmt->VertexAttrib1fNV = _mesa_noop_VertexAttrib1fNV;
+ vfmt->VertexAttrib1fvNV = _mesa_noop_VertexAttrib1fvNV;
+ vfmt->VertexAttrib2fNV = _mesa_noop_VertexAttrib2fNV;
+ vfmt->VertexAttrib2fvNV = _mesa_noop_VertexAttrib2fvNV;
+ vfmt->VertexAttrib3fNV = _mesa_noop_VertexAttrib3fNV;
+ vfmt->VertexAttrib3fvNV = _mesa_noop_VertexAttrib3fvNV;
+ vfmt->VertexAttrib4fNV = _mesa_noop_VertexAttrib4fNV;
+ vfmt->VertexAttrib4fvNV = _mesa_noop_VertexAttrib4fvNV;
+ vfmt->VertexAttrib1fARB = _mesa_noop_VertexAttrib1fARB;
+ vfmt->VertexAttrib1fvARB = _mesa_noop_VertexAttrib1fvARB;
+ vfmt->VertexAttrib2fARB = _mesa_noop_VertexAttrib2fARB;
+ vfmt->VertexAttrib2fvARB = _mesa_noop_VertexAttrib2fvARB;
+ vfmt->VertexAttrib3fARB = _mesa_noop_VertexAttrib3fARB;
+ vfmt->VertexAttrib3fvARB = _mesa_noop_VertexAttrib3fvARB;
+ vfmt->VertexAttrib4fARB = _mesa_noop_VertexAttrib4fARB;
+ vfmt->VertexAttrib4fvARB = _mesa_noop_VertexAttrib4fvARB;
+
+ vfmt->Rectf = _mesa_noop_Rectf;
+
+ vfmt->DrawArrays = _mesa_noop_DrawArrays;
+ vfmt->DrawElements = _mesa_noop_DrawElements;
+ vfmt->DrawRangeElements = _mesa_noop_DrawRangeElements;
+ vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
+ vfmt->DrawElementsBaseVertex = _mesa_noop_DrawElementsBaseVertex;
+ vfmt->DrawRangeElementsBaseVertex = _mesa_noop_DrawRangeElementsBaseVertex;
+ vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
+}
+
+
+/**
+ * Is the given dispatch table using the no-op functions?
+ */
+GLboolean
+_mesa_using_noop_vtxfmt(const struct _glapi_table *dispatch)
+{
+ return GET_Begin((struct _glapi_table *) dispatch) == _mesa_noop_Begin;
+}
+
+
+#endif /* FEATURE_beginend */
diff --git a/mesalib/src/mesa/vbo/vbo_noop.h b/mesalib/src/mesa/vbo/vbo_noop.h
new file mode 100644
index 000000000..f9180374f
--- /dev/null
+++ b/mesalib/src/mesa/vbo/vbo_noop.h
@@ -0,0 +1,45 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2011 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _API_NOOP_H
+#define _API_NOOP_H
+
+
+#include "main/mfeatures.h"
+#include "main/mtypes.h"
+
+
+#if FEATURE_beginend
+
+extern void
+_mesa_noop_vtxfmt_init(GLvertexformat *vfmt);
+
+extern GLboolean
+_mesa_using_noop_vtxfmt(const struct _glapi_table *dispatch);
+
+
+#endif /* FEATURE_beginend */
+
+
+#endif /* _API_NOOP_H */
diff --git a/mesalib/src/mesa/vbo/vbo_save.h b/mesalib/src/mesa/vbo/vbo_save.h
index a85a7cbf6..4d4a5bf17 100644
--- a/mesalib/src/mesa/vbo/vbo_save.h
+++ b/mesalib/src/mesa/vbo/vbo_save.h
@@ -122,6 +122,7 @@ struct vbo_save_primitive_store {
struct vbo_save_context {
struct gl_context *ctx;
GLvertexformat vtxfmt;
+ GLvertexformat vtxfmt_noop; /**< Used if out_of_memory is true */
struct gl_client_array arrays[VBO_ATTRIB_MAX];
const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
@@ -129,6 +130,8 @@ struct vbo_save_context {
GLubyte active_sz[VBO_ATTRIB_MAX];
GLuint vertex_size;
+ GLboolean out_of_memory; /**< True if last VBO allocation failed */
+
GLfloat *buffer;
GLuint count;
GLuint wrap_count;
diff --git a/mesalib/src/mesa/vbo/vbo_save_api.c b/mesalib/src/mesa/vbo/vbo_save_api.c
index 87a52e81f..64da7ac49 100644
--- a/mesalib/src/mesa/vbo/vbo_save_api.c
+++ b/mesalib/src/mesa/vbo/vbo_save_api.c
@@ -75,13 +75,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/eval.h"
#include "main/macros.h"
#include "main/mfeatures.h"
-#include "main/api_noop.h"
#include "main/api_validate.h"
#include "main/api_arrayelt.h"
#include "main/vtxfmt.h"
#include "main/dispatch.h"
#include "vbo_context.h"
+#include "vbo_noop.h"
#if FEATURE_dlist
@@ -185,6 +185,7 @@ _save_copy_vertices(struct gl_context *ctx,
static struct vbo_save_vertex_store *
alloc_vertex_store(struct gl_context *ctx)
{
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
struct vbo_save_vertex_store *vertex_store =
CALLOC_STRUCT(vbo_save_vertex_store);
@@ -197,11 +198,22 @@ alloc_vertex_store(struct gl_context *ctx)
vertex_store->bufferobj = ctx->Driver.NewBufferObject(ctx,
VBO_BUF_ID,
GL_ARRAY_BUFFER_ARB);
+ if (vertex_store->bufferobj) {
+ save->out_of_memory =
+ !ctx->Driver.BufferData(ctx,
+ GL_ARRAY_BUFFER_ARB,
+ VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat),
+ NULL, GL_STATIC_DRAW_ARB,
+ vertex_store->bufferobj);
+ }
+ else {
+ save->out_of_memory = GL_TRUE;
+ }
- ctx->Driver.BufferData(ctx,
- GL_ARRAY_BUFFER_ARB,
- VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat),
- NULL, GL_STATIC_DRAW_ARB, vertex_store->bufferobj);
+ if (save->out_of_memory) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "internal VBO allocation");
+ _mesa_install_save_vtxfmt(ctx, &save->vtxfmt_noop);
+ }
vertex_store->buffer = NULL;
vertex_store->used = 0;
@@ -231,14 +243,19 @@ map_vertex_store(struct gl_context *ctx,
{
assert(vertex_store->bufferobj);
assert(!vertex_store->buffer);
- vertex_store->buffer =
- (GLfloat *) ctx->Driver.MapBufferRange(ctx, 0,
- vertex_store->bufferobj->Size,
- GL_MAP_WRITE_BIT, /* not used */
- vertex_store->bufferobj);
-
- assert(vertex_store->buffer);
- return vertex_store->buffer + vertex_store->used;
+ if (vertex_store->bufferobj->Size > 0) {
+ vertex_store->buffer =
+ (GLfloat *) ctx->Driver.MapBufferRange(ctx, 0,
+ vertex_store->bufferobj->Size,
+ GL_MAP_WRITE_BIT, /* not used */
+ vertex_store->bufferobj);
+ assert(vertex_store->buffer);
+ return vertex_store->buffer + vertex_store->used;
+ }
+ else {
+ /* probably ran out of memory for buffers */
+ return NULL;
+ }
}
@@ -246,7 +263,9 @@ static void
unmap_vertex_store(struct gl_context *ctx,
struct vbo_save_vertex_store *vertex_store)
{
- ctx->Driver.UnmapBuffer(ctx, vertex_store->bufferobj);
+ if (vertex_store->bufferobj->Size > 0) {
+ ctx->Driver.UnmapBuffer(ctx, vertex_store->bufferobj);
+ }
vertex_store->buffer = NULL;
}
@@ -400,6 +419,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
*/
save->vertex_store = alloc_vertex_store(ctx);
save->buffer_ptr = map_vertex_store(ctx, save->vertex_store);
+ save->out_of_memory = save->buffer_ptr == NULL;
}
if (save->prim_store->used > VBO_SAVE_PRIM_SIZE - 6) {
@@ -733,7 +753,12 @@ dlist_fallback(struct gl_context *ctx)
_save_copy_to_current(ctx);
_save_reset_vertex(ctx);
_save_reset_counters(ctx);
- _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
+ if (save->out_of_memory) {
+ _mesa_install_save_vtxfmt(ctx, &save->vtxfmt_noop);
+ }
+ else {
+ _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
+ }
ctx->Driver.SaveNeedFlush = 0;
}
@@ -826,7 +851,12 @@ vbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode)
save->prim[i].count = 0;
save->prim[i].num_instances = 1;
- _mesa_install_save_vtxfmt(ctx, &save->vtxfmt);
+ if (save->out_of_memory) {
+ _mesa_install_save_vtxfmt(ctx, &save->vtxfmt_noop);
+ }
+ else {
+ _mesa_install_save_vtxfmt(ctx, &save->vtxfmt);
+ }
ctx->Driver.SaveNeedFlush = 1;
return GL_TRUE;
}
@@ -852,7 +882,12 @@ _save_End(void)
* etc. received between here and the next begin will be compiled
* as opcodes.
*/
- _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
+ if (save->out_of_memory) {
+ _mesa_install_save_vtxfmt(ctx, &save->vtxfmt_noop);
+ }
+ else {
+ _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
+ }
}
@@ -933,6 +968,37 @@ _save_DrawArrays(GLenum mode, GLint start, GLsizei count)
static void GLAPIENTRY
+_save_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type,
+ const GLvoid **indices, GLsizei primcount)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode;
+ (void) count;
+ (void) type;
+ (void) indices;
+ (void) primcount;
+ _mesa_compile_error(ctx, GL_INVALID_OPERATION, "glMultiDrawElements");
+}
+
+
+static void GLAPIENTRY
+_save_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count,
+ GLenum type, const GLvoid **indices,
+ GLsizei primcount, const GLint *basevertex)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ (void) mode;
+ (void) count;
+ (void) type;
+ (void) indices;
+ (void) primcount;
+ (void) basevertex;
+ _mesa_compile_error(ctx, GL_INVALID_OPERATION,
+ "glMultiDrawElementsBaseVertex");
+}
+
+
+static void GLAPIENTRY
_save_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
{
GET_CURRENT_CONTEXT(ctx);
@@ -993,6 +1059,7 @@ _save_PrimitiveRestartNV(void)
/* Unlike the functions above, these are to be hooked into the vtxfmt
* maintained in ctx->ListState, active when the list is known or
* suspected to be outside any begin/end primitive.
+ * Note: OBE = Outside Begin/End
*/
static void GLAPIENTRY
_save_OBE_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
@@ -1011,11 +1078,15 @@ static void GLAPIENTRY
_save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei count)
{
GET_CURRENT_CONTEXT(ctx);
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
GLint i;
if (!_mesa_validate_DrawArrays(ctx, mode, start, count))
return;
+ if (save->out_of_memory)
+ return;
+
_ae_map_vbos(ctx);
vbo_save_NotifyBegin(ctx, (mode | VBO_SAVE_PRIM_WEAK
@@ -1037,11 +1108,15 @@ _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum type,
const GLvoid * indices)
{
GET_CURRENT_CONTEXT(ctx);
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
GLint i;
if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices, 0))
return;
+ if (save->out_of_memory)
+ return;
+
_ae_map_vbos(ctx);
if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj))
@@ -1081,9 +1156,48 @@ _save_OBE_DrawRangeElements(GLenum mode, GLuint start, GLuint end,
const GLvoid * indices)
{
GET_CURRENT_CONTEXT(ctx);
- if (_mesa_validate_DrawRangeElements(ctx, mode,
- start, end, count, type, indices, 0)) {
- _save_OBE_DrawElements(mode, count, type, indices);
+ struct vbo_save_context *save = &vbo_context(ctx)->save;
+
+ if (!_mesa_validate_DrawRangeElements(ctx, mode,
+ start, end, count, type, indices, 0))
+ return;
+
+ if (save->out_of_memory)
+ return;
+
+ _save_OBE_DrawElements(mode, count, type, indices);
+}
+
+
+static void GLAPIENTRY
+_save_OBE_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type,
+ const GLvoid **indices, GLsizei primcount)
+{
+ GLsizei i;
+
+ for (i = 0; i < primcount; i++) {
+ if (count[i] > 0) {
+ CALL_DrawElements(GET_DISPATCH(), (mode, count[i], type, indices[i]));
+ }
+ }
+}
+
+
+static void GLAPIENTRY
+_save_OBE_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count,
+ GLenum type,
+ const GLvoid **indices,
+ GLsizei primcount,
+ const GLint *basevertex)
+{
+ GLsizei i;
+
+ for (i = 0; i < primcount; i++) {
+ if (count[i] > 0) {
+ CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode, count[i], type,
+ indices[i],
+ basevertex[i]));
+ }
}
}
@@ -1223,8 +1337,8 @@ _save_vtxfmt_init(struct gl_context *ctx)
_MESA_INIT_EVAL_VTXFMT(vfmt, _save_);
- /* These are all errors as we at least know we are in some sort of
- * begin/end pair:
+ /* These calls all generate GL_INVALID_OPERATION since this vtxfmt is
+ * only used when we're inside a glBegin/End pair.
*/
vfmt->Begin = _save_Begin;
vfmt->Rectf = _save_Rectf;
@@ -1233,9 +1347,8 @@ _save_vtxfmt_init(struct gl_context *ctx)
vfmt->DrawRangeElements = _save_DrawRangeElements;
vfmt->DrawElementsBaseVertex = _save_DrawElementsBaseVertex;
vfmt->DrawRangeElementsBaseVertex = _save_DrawRangeElementsBaseVertex;
- /* Loops back into vfmt->DrawElements */
- vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements;
- vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex;
+ vfmt->MultiDrawElementsEXT = _save_MultiDrawElements;
+ vfmt->MultiDrawElementsBaseVertex = _save_MultiDrawElementsBaseVertex;
}
@@ -1424,6 +1537,7 @@ vbo_save_api_init(struct vbo_save_context *save)
_save_vtxfmt_init(ctx);
_save_current_init(ctx);
+ _mesa_noop_vtxfmt_init(&save->vtxfmt_noop);
/* These will actually get set again when binding/drawing */
for (i = 0; i < VBO_ATTRIB_MAX; i++)
@@ -1436,11 +1550,8 @@ vbo_save_api_init(struct vbo_save_context *save)
ctx->ListState.ListVtxfmt.DrawArrays = _save_OBE_DrawArrays;
ctx->ListState.ListVtxfmt.DrawElements = _save_OBE_DrawElements;
ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements;
- /* loops back into _save_OBE_DrawElements */
- ctx->ListState.ListVtxfmt.MultiDrawElementsEXT =
- _mesa_noop_MultiDrawElements;
- ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex =
- _mesa_noop_MultiDrawElementsBaseVertex;
+ ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _save_OBE_MultiDrawElements;
+ ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex = _save_OBE_MultiDrawElementsBaseVertex;
_mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
}