xref: /aosp_15_r20/external/mesa3d/src/mesa/main/draw.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \brief Array type draw functions, the main workhorse of any OpenGL API
27  * \author Keith Whitwell
28  */
29 
30 
31 #ifndef DRAW_H
32 #define DRAW_H
33 
34 #include <stdbool.h>
35 #include "util/glheader.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 struct gl_context;
42 struct gl_vertex_array_object;
43 struct _mesa_prim
44 {
45    GLubyte mode;    /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */
46 
47    /**
48     * tnl: If true, line stipple emulation will reset the pattern walker.
49     * vbo: If false and the primitive is a line loop, the first vertex is
50     *      the beginning of the line loop and it won't be drawn.
51     *      Instead, it will be moved to the end.
52     */
53    bool begin;
54 
55    /**
56     * tnl: If true and the primitive is a line loop, it will be closed.
57     * vbo: Same as tnl.
58     */
59    bool end;
60 
61    GLuint start;
62    GLuint count;
63    GLint basevertex;
64    GLuint draw_id;
65 };
66 
67 /* Would like to call this a "vbo_index_buffer", but this would be
68  * confusing as the indices are not neccessarily yet in a non-null
69  * buffer object.
70  */
71 struct _mesa_index_buffer
72 {
73    GLuint count;
74    uint8_t index_size_shift; /* logbase2(index_size) */
75    struct gl_buffer_object *obj;
76    const void *ptr;
77 };
78 
79 
80 void
81 _mesa_set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs);
82 
83 void
84 _mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao);
85 
86 void
87 _mesa_save_and_set_draw_vao(struct gl_context *ctx,
88                             struct gl_vertex_array_object *vao,
89                             GLbitfield vp_input_filter,
90                             struct gl_vertex_array_object **old_vao,
91                             GLbitfield *old_vp_input_filter);
92 
93 void
94 _mesa_restore_draw_vao(struct gl_context *ctx,
95                        struct gl_vertex_array_object *saved,
96                        GLbitfield saved_vp_input_filter);
97 
98 void
99 _mesa_bitmap(struct gl_context *ctx, GLsizei width, GLsizei height,
100              GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
101              const GLubyte *bitmap, struct pipe_resource *tex);
102 
103 static inline unsigned
_mesa_get_index_size_shift(GLenum type)104 _mesa_get_index_size_shift(GLenum type)
105 {
106    /* The type is already validated, so use a fast conversion.
107     *
108     * GL_UNSIGNED_BYTE  - GL_UNSIGNED_BYTE = 0
109     * GL_UNSIGNED_SHORT - GL_UNSIGNED_BYTE = 2
110     * GL_UNSIGNED_INT   - GL_UNSIGNED_BYTE = 4
111     *
112     * Divide by 2 to get 0,1,2.
113     */
114    return (type - GL_UNSIGNED_BYTE) >> 1;
115 }
116 
117 static inline bool
_mesa_is_index_type_valid(GLenum type)118 _mesa_is_index_type_valid(GLenum type)
119 {
120    /* GL_UNSIGNED_BYTE  = 0x1401
121     * GL_UNSIGNED_SHORT = 0x1403
122     * GL_UNSIGNED_INT   = 0x1405
123     *
124     * The trick is that bit 1 and bit 2 mean USHORT and UINT, respectively.
125     * After clearing those two bits (with ~6), we should get UBYTE.
126     * Both bits can't be set, because the enum would be greater than UINT.
127     */
128    return type <= GL_UNSIGNED_INT && (type & ~6) == GL_UNSIGNED_BYTE;
129 }
130 
131 #ifdef __cplusplus
132 } // extern "C"
133 #endif
134 
135 #endif
136