d7136ed6fb97e0b13ed685236ffec8fb672bfd94
[mesa.git] / src / mesa / drivers / dri / i965 / brw_primitive_restart.c
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jordan Justen <jordan.l.justen@intel.com>
25 *
26 */
27
28 #include "main/imports.h"
29 #include "main/bufferobj.h"
30
31 #include "brw_context.h"
32 #include "brw_draw.h"
33
34 /**
35 * Check if primitive restart is enabled, and if so, handle it properly.
36 *
37 * In some cases the support will be handled in software. When available
38 * hardware will handle primitive restart.
39 */
40 GLboolean
41 brw_handle_primitive_restart(struct gl_context *ctx,
42 const struct _mesa_prim *prim,
43 GLuint nr_prims,
44 const struct _mesa_index_buffer *ib)
45 {
46 struct brw_context *brw = brw_context(ctx);
47
48 /* We only need to handle cases where there is an index buffer. */
49 if (ib == NULL) {
50 return GL_FALSE;
51 }
52
53 /* If the driver has requested software handling of primitive restarts,
54 * then the VBO module has already taken care of things, and we can
55 * just draw as normal.
56 */
57 if (ctx->Const.PrimitiveRestartInSoftware) {
58 return GL_FALSE;
59 }
60
61 /* If we have set the in_progress flag, then we are in the middle
62 * of handling the primitive restart draw.
63 */
64 if (brw->prim_restart.in_progress) {
65 return GL_FALSE;
66 }
67
68 /* If PrimitiveRestart is not enabled, then we aren't concerned about
69 * handling this draw.
70 */
71 if (!(ctx->Array.PrimitiveRestart)) {
72 return GL_FALSE;
73 }
74
75 /* Signal that we are in the process of handling the
76 * primitive restart draw
77 */
78 brw->prim_restart.in_progress = true;
79
80 vbo_sw_primitive_restart(ctx, prim, nr_prims, ib);
81
82 brw->prim_restart.in_progress = false;
83
84 /* The primitive restart draw was completed, so return true. */
85 return GL_TRUE;
86 }
87