1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "bufferobj.h"
33 #include "intel_context.h"
34 #include "intel_buffer_objects.h"
39 * There is some duplication between mesa's bufferobjects and our
40 * bufmgr buffers. Both have an integer handle and a hashtable to
41 * lookup an opaque structure. It would be nice if the handles and
42 * internal structure where somehow shared.
44 static struct gl_buffer_object
*intel_bufferobj_alloc( GLcontext
*ctx
,
48 struct intel_context
*intel
= intel_context(ctx
);
49 struct intel_buffer_object
*obj
= MALLOC_STRUCT(intel_buffer_object
);
51 _mesa_initialize_buffer_object(&obj
->Base
, name
, target
);
53 /* XXX: We generate our own handle, which is different to 'name' above.
55 bmGenBuffers(intel
, "bufferobj", 1, &obj
->buffer
);
63 * Deallocate/free a vertex/pixel buffer object.
64 * Called via glDeleteBuffersARB().
66 static void intel_bufferobj_free( GLcontext
*ctx
,
67 struct gl_buffer_object
*obj
)
69 struct intel_context
*intel
= intel_context(ctx
);
70 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
74 if (intel_obj
->buffer
)
75 bmDeleteBuffers( intel
, 1, &intel_obj
->buffer
);
77 _mesa_free(intel_obj
);
83 * Allocate space for and store data in a buffer object. Any data that was
84 * previously stored in the buffer object is lost. If data is NULL,
85 * memory will be allocated, but no copy will occur.
86 * Called via glBufferDataARB().
88 static void intel_bufferobj_data( GLcontext
*ctx
,
93 struct gl_buffer_object
*obj
)
95 struct intel_context
*intel
= intel_context(ctx
);
96 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
98 /* XXX: do something useful with 'usage' (eg. populate flags
106 bmBufferDataAUB(intel
, intel_obj
->buffer
, size
, data
, 0,
112 * Replace data in a subrange of buffer object. If the data range
113 * specified by size + offset extends beyond the end of the buffer or
114 * if data is NULL, no copy is performed.
115 * Called via glBufferSubDataARB().
117 static void intel_bufferobj_subdata( GLcontext
*ctx
,
122 struct gl_buffer_object
* obj
)
124 struct intel_context
*intel
= intel_context(ctx
);
125 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
128 bmBufferSubDataAUB(intel
, intel_obj
->buffer
, offset
, size
, data
, 0, 0);
133 * Called via glGetBufferSubDataARB().
135 static void intel_bufferobj_get_subdata( GLcontext
*ctx
,
140 struct gl_buffer_object
* obj
)
142 struct intel_context
*intel
= intel_context(ctx
);
143 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
146 bmBufferGetSubData(intel
, intel_obj
->buffer
, offset
, size
, data
);
152 * Called via glMapBufferARB().
154 static void *intel_bufferobj_map( GLcontext
*ctx
,
157 struct gl_buffer_object
*obj
)
159 struct intel_context
*intel
= intel_context(ctx
);
160 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
162 /* XXX: Translate access to flags arg below:
165 assert(intel_obj
->buffer
);
166 obj
->Pointer
= bmMapBuffer(intel
, intel_obj
->buffer
, 0);
172 * Called via glMapBufferARB().
174 static GLboolean
intel_bufferobj_unmap( GLcontext
*ctx
,
176 struct gl_buffer_object
*obj
)
178 struct intel_context
*intel
= intel_context(ctx
);
179 struct intel_buffer_object
*intel_obj
= intel_buffer_object(obj
);
182 assert(intel_obj
->buffer
);
183 assert(obj
->Pointer
);
184 bmUnmapBufferAUB(intel
, intel_obj
->buffer
, 0, 0);
189 struct buffer
*intel_bufferobj_buffer( const struct intel_buffer_object
*intel_obj
)
191 assert(intel_obj
->Base
.Name
);
192 assert(intel_obj
->buffer
);
193 return intel_obj
->buffer
;
196 void intel_bufferobj_init( struct intel_context
*intel
)
198 GLcontext
*ctx
= &intel
->ctx
;
200 ctx
->Driver
.NewBufferObject
= intel_bufferobj_alloc
;
201 ctx
->Driver
.DeleteBuffer
= intel_bufferobj_free
;
202 ctx
->Driver
.BufferData
= intel_bufferobj_data
;
203 ctx
->Driver
.BufferSubData
= intel_bufferobj_subdata
;
204 ctx
->Driver
.GetBufferSubData
= intel_bufferobj_get_subdata
;
205 ctx
->Driver
.MapBuffer
= intel_bufferobj_map
;
206 ctx
->Driver
.UnmapBuffer
= intel_bufferobj_unmap
;