1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "WebGL2Context.h"
8
9 #include "GLContext.h"
10 #include "WebGLVertexArray.h"
11 #include "WebGLVertexAttribData.h"
12
13 #include "mozilla/Casting.h"
14
15 namespace mozilla {
16
17 bool
ValidateAttribPointerType(bool integerMode,GLenum type,uint32_t * out_alignment,const char * info)18 WebGL2Context::ValidateAttribPointerType(bool integerMode, GLenum type,
19 uint32_t* out_alignment, const char* info)
20 {
21 MOZ_ASSERT(out_alignment);
22
23 switch (type) {
24 case LOCAL_GL_BYTE:
25 case LOCAL_GL_UNSIGNED_BYTE:
26 *out_alignment = 1;
27 return true;
28
29 case LOCAL_GL_SHORT:
30 case LOCAL_GL_UNSIGNED_SHORT:
31 *out_alignment = 2;
32 return true;
33
34 case LOCAL_GL_INT:
35 case LOCAL_GL_UNSIGNED_INT:
36 *out_alignment = 4;
37 return true;
38 }
39
40 if (!integerMode) {
41 switch (type) {
42 case LOCAL_GL_HALF_FLOAT:
43 *out_alignment = 2;
44 return true;
45
46 case LOCAL_GL_FLOAT:
47 case LOCAL_GL_FIXED:
48 case LOCAL_GL_INT_2_10_10_10_REV:
49 case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
50 *out_alignment = 4;
51 return true;
52 }
53 }
54
55 ErrorInvalidEnum("%s: invalid enum value 0x%x", info, type);
56 return false;
57 }
58
59 // -------------------------------------------------------------------------
60 // Vertex Attributes
61
62 void
VertexAttribIPointer(GLuint index,GLint size,GLenum type,GLsizei stride,GLintptr offset)63 WebGL2Context::VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride,
64 GLintptr offset)
65 {
66 if (IsContextLost())
67 return;
68
69 if (!ValidateAttribIndex(index, "vertexAttribIPointer"))
70 return;
71
72 if (!ValidateAttribPointer(true, index, size, type, LOCAL_GL_FALSE, stride, offset,
73 "vertexAttribIPointer"))
74 {
75 return;
76 }
77
78 MOZ_ASSERT(mBoundVertexArray);
79
80 InvalidateBufferFetching();
81
82 MakeContextCurrent();
83 gl->fVertexAttribIPointer(index, size, type, stride, reinterpret_cast<void*>(offset));
84
85 WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
86 const bool integerFunc = true;
87 const bool normalized = false;
88 vd.VertexAttribPointer(integerFunc, mBoundArrayBuffer, size, type, normalized, stride,
89 offset);
90 }
91
92 } // namespace mozilla
93