<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 18, 2015 at 4:18 PM, Fredrik Höglund <span dir="ltr"><<a href="mailto:fredrik@kde.org" target="_blank">fredrik@kde.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The only difference between these functions is the legal types and<br>
sizes, so consolidate the code into a single vertex_attrib_format()<br>
function and call it from all three entry points.<br>
---<br>
src/mesa/main/varray.c | 143 +++++++++++++++----------------------------------<br>
1 file changed, 43 insertions(+), 100 deletions(-)<br>
<br>
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c<br>
index 5f58016..a6b66a0 100644<br>
--- a/src/mesa/main/varray.c<br>
+++ b/src/mesa/main/varray.c<br>
@@ -66,6 +66,21 @@<br>
#define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)<br>
#define ALL_TYPE_BITS ((1 << 15) - 1)<br>
<br>
+#define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \<br>
+ SHORT_BIT | UNSIGNED_SHORT_BIT | \<br>
+ INT_BIT | UNSIGNED_INT_BIT | \<br>
+ HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \<br>
+ FIXED_GL_BIT | \<br>
+ UNSIGNED_INT_2_10_10_10_REV_BIT | \<br>
+ INT_2_10_10_10_REV_BIT | \<br>
+ UNSIGNED_INT_10F_11F_11F_REV_BIT)<br>
+<br>
+#define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \<br>
+ SHORT_BIT | UNSIGNED_SHORT_BIT | \<br>
+ INT_BIT | UNSIGNED_INT_BIT)<br>
+<br>
+#define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT<br>
+<br>
<br>
/** Convert GL datatype enum into a <type>_BIT value seen above */<br>
static GLbitfield<br>
@@ -1739,19 +1754,12 @@ _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,<br>
}<br>
<br>
<br>
-void GLAPIENTRY<br>
-_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,<br>
- GLboolean normalized, GLuint relativeOffset)<br>
+static void<br>
+vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,<br>
+ GLboolean normalized, GLboolean integer,<br>
+ GLbitfield legalTypes, GLsizei maxSize,<br>
+ GLuint relativeOffset, const char *func)<br>
{<br>
- const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |<br>
- SHORT_BIT | UNSIGNED_SHORT_BIT |<br>
- INT_BIT | UNSIGNED_INT_BIT |<br>
- HALF_BIT | FLOAT_BIT | DOUBLE_BIT |<br>
- FIXED_GL_BIT |<br>
- UNSIGNED_INT_2_10_10_10_REV_BIT |<br>
- INT_2_10_10_10_REV_BIT |<br>
- UNSIGNED_INT_10F_11F_11F_REV_BIT);<br>
-<br>
GET_CURRENT_CONTEXT(ctx);<br>
ASSERT_OUTSIDE_BEGIN_END(ctx);<br>
<br>
@@ -1765,7 +1773,7 @@ _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,<br>
if (ctx->API == API_OPENGL_CORE &&<br>
ctx->Array.VAO == ctx->Array.DefaultVAO) {<br>
_mesa_error(ctx, GL_INVALID_OPERATION,<br>
- "glVertexAttribFormat(No array object bound)");<br>
+ "%s(No array object bound)", func);<br>
return;<br>
}<br>
<br>
@@ -1776,65 +1784,38 @@ _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,<br>
*/<br>
if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {<br>
_mesa_error(ctx, GL_INVALID_VALUE,<br>
- "glVertexAttribFormat(attribindex=%u > "<br>
+ "%s(attribindex=%u > "<br>
"GL_MAX_VERTEX_ATTRIBS)",<br>
- attribIndex);<br>
+ func, attribIndex);<br>
return;<br>
}<br>
<br>
FLUSH_VERTICES(ctx, 0);<br>
<br>
- update_array_format(ctx, "glVertexAttribFormat",<br>
- VERT_ATTRIB_GENERIC(attribIndex),<br>
- legalTypes, 1, BGRA_OR_4, size, type, normalized,<br>
- GL_FALSE, relativeOffset);<br>
+ update_array_format(ctx, func, VERT_ATTRIB_GENERIC(attribIndex),<br>
+ legalTypes, 1, maxSize, size, type, normalized,<br>
+ integer, relativeOffset);<br>
}<br>
<br>
<br>
void GLAPIENTRY<br>
-_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,<br>
- GLuint relativeOffset)<br>
+_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,<br>
+ GLboolean normalized, GLuint relativeOffset)<br>
{<br>
- const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |<br>
- SHORT_BIT | UNSIGNED_SHORT_BIT |<br>
- INT_BIT | UNSIGNED_INT_BIT);<br>
-<br>
- GET_CURRENT_CONTEXT(ctx);<br>
- ASSERT_OUTSIDE_BEGIN_END(ctx);<br>
-<br>
- /* The ARB_vertex_attrib_binding spec says:<br>
- *<br>
- * "An INVALID_OPERATION error is generated under any of the following<br>
- * conditions:<br>
- * - if no vertex array object is currently bound (see section 2.10);<br>
- * - ..."<br>
- */<br>
- if (ctx->API == API_OPENGL_CORE &&<br>
- ctx->Array.VAO == ctx->Array.DefaultVAO) {<br>
- _mesa_error(ctx, GL_INVALID_OPERATION,<br>
- "glVertexAttribIFormat(No array object bound)");<br>
- return;<br>
- }<br>
-<br>
- /* The ARB_vertex_attrib_binding spec says:<br>
- *<br>
- * "The error INVALID_VALUE is generated if index is greater than<br>
- * or equal to the value of MAX_VERTEX_ATTRIBS."<br>
- */<br>
- if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {<br>
- _mesa_error(ctx, GL_INVALID_VALUE,<br>
- "glVertexAttribIFormat(attribindex=%u > "<br>
- "GL_MAX_VERTEX_ATTRIBS)",<br>
- attribIndex);<br>
- return;<br>
- }<br>
+ vertex_attrib_format(attribIndex, size, type, normalized,<br>
+ GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,<br>
+ BGRA_OR_4, relativeOffset,<br>
+ "glVertexAttribFormat");<br>
+}<br>
<br>
- FLUSH_VERTICES(ctx, 0);<br>
<br>
- update_array_format(ctx, "glVertexAttribIFormat",<br>
- VERT_ATTRIB_GENERIC(attribIndex),<br>
- legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE,<br>
- relativeOffset);<br>
+void GLAPIENTRY<br>
+_mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,<br>
+ GLuint relativeOffset)<br>
+{<br>
+ vertex_attrib_format(attribIndex, size, type, GL_FALSE,<br>
+ GL_TRUE, ATTRIB_IFORMAT_TYPES_MASK, 4,<br>
+ relativeOffset, "glVertexAttribIFormat");<br>
}<br>
<br>
<br>
@@ -1842,47 +1823,9 @@ void GLAPIENTRY<br>
_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,<br>
GLuint relativeOffset)<br>
{<br>
- const GLbitfield legalTypes = DOUBLE_BIT;<br>
-<br>
- GET_CURRENT_CONTEXT(ctx);<br>
- ASSERT_OUTSIDE_BEGIN_END(ctx);<br>
-<br>
- /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:<br>
- *<br>
- * "An INVALID_OPERATION error is generated under any of the following<br>
- * conditions:<br>
- * • if no vertex array object is currently bound (see section 10.4);<br>
- * • ..."<br>
- *<br></blockquote><div>The comment below is missing in your new version ("we assume that this is an oversight"). <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- * This language is missing from the extension spec, but we assume<br>
- * that this is an oversight.<br>
- */<br>
- if (ctx->API == API_OPENGL_CORE &&<br>
- ctx->Array.VAO == ctx->Array.DefaultVAO) {<br>
- _mesa_error(ctx, GL_INVALID_OPERATION,<br>
- "glVertexAttribLFormat(No array object bound)");<br>
- return;<br>
- }<br>
-<br>
- /* The ARB_vertex_attrib_binding spec says:<br>
- *<br>
- * "The error INVALID_VALUE is generated if <attribindex> is greater than<br>
- * or equal to the value of MAX_VERTEX_ATTRIBS."<br>
- */<br>
- if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {<br>
- _mesa_error(ctx, GL_INVALID_VALUE,<br>
- "glVertexAttribLFormat(attribindex=%u > "<br>
- "GL_MAX_VERTEX_ATTRIBS)",<br>
- attribIndex);<br>
- return;<br>
- }<br>
-<br>
- FLUSH_VERTICES(ctx, 0);<br>
-<br>
- update_array_format(ctx, "glVertexAttribLFormat",<br>
- VERT_ATTRIB_GENERIC(attribIndex),<br>
- legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE,<br>
- relativeOffset);<br>
+ vertex_attrib_format(attribIndex, size, type, GL_FALSE,<br>
+ GL_FALSE, ATTRIB_LFORMAT_TYPES_MASK, 4,<br>
+ relativeOffset, "glVertexAttribLFormat");<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
1.8.5.3<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>