1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // validationES2.h:
7 // Inlined validation functions for OpenGL ES 2.0 entry points.
8
9 #ifndef LIBANGLE_VALIDATION_ES2_H_
10 #define LIBANGLE_VALIDATION_ES2_H_
11
12 #include "libANGLE/ErrorStrings.h"
13 #include "libANGLE/validationES.h"
14 #include "libANGLE/validationES2_autogen.h"
15
16 namespace gl
17 {
ValidateDrawArrays(const Context * context,angle::EntryPoint entryPoint,PrimitiveMode mode,GLint first,GLsizei count)18 ANGLE_INLINE bool ValidateDrawArrays(const Context *context,
19 angle::EntryPoint entryPoint,
20 PrimitiveMode mode,
21 GLint first,
22 GLsizei count)
23 {
24 return ValidateDrawArraysCommon(context, entryPoint, mode, first, count, 1);
25 }
26
ValidateUniform2f(const Context * context,angle::EntryPoint entryPoint,UniformLocation location,GLfloat x,GLfloat y)27 ANGLE_INLINE bool ValidateUniform2f(const Context *context,
28 angle::EntryPoint entryPoint,
29 UniformLocation location,
30 GLfloat x,
31 GLfloat y)
32 {
33 return ValidateUniform(context, entryPoint, GL_FLOAT_VEC2, location, 1);
34 }
35
ValidateBindBuffer(const Context * context,angle::EntryPoint entryPoint,BufferBinding target,BufferID buffer)36 ANGLE_INLINE bool ValidateBindBuffer(const Context *context,
37 angle::EntryPoint entryPoint,
38 BufferBinding target,
39 BufferID buffer)
40 {
41 if (!context->isValidBufferBinding(target))
42 {
43 ANGLE_VALIDATION_ERROR(GL_INVALID_ENUM, err::kInvalidBufferTypes);
44 return false;
45 }
46
47 if (!context->getState().isBindGeneratesResourceEnabled() &&
48 !context->isBufferGenerated(buffer))
49 {
50 ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kObjectNotGenerated);
51 return false;
52 }
53
54 return true;
55 }
56
ValidateDrawElements(const Context * context,angle::EntryPoint entryPoint,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices)57 ANGLE_INLINE bool ValidateDrawElements(const Context *context,
58 angle::EntryPoint entryPoint,
59 PrimitiveMode mode,
60 GLsizei count,
61 DrawElementsType type,
62 const void *indices)
63 {
64 return ValidateDrawElementsCommon(context, entryPoint, mode, count, type, indices, 1);
65 }
66
ValidateVertexAttribPointer(const Context * context,angle::EntryPoint entryPoint,GLuint index,GLint size,VertexAttribType type,GLboolean normalized,GLsizei stride,const void * ptr)67 ANGLE_INLINE bool ValidateVertexAttribPointer(const Context *context,
68 angle::EntryPoint entryPoint,
69 GLuint index,
70 GLint size,
71 VertexAttribType type,
72 GLboolean normalized,
73 GLsizei stride,
74 const void *ptr)
75 {
76 if (!ValidateFloatVertexFormat(context, entryPoint, index, size, type))
77 {
78 return false;
79 }
80
81 if (stride < 0)
82 {
83 ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kNegativeStride);
84 return false;
85 }
86
87 if (context->getClientVersion() >= ES_3_1)
88 {
89 const Caps &caps = context->getCaps();
90 if (stride > caps.maxVertexAttribStride)
91 {
92 ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribStride);
93 return false;
94 }
95
96 if (index >= static_cast<GLuint>(caps.maxVertexAttribBindings))
97 {
98 ANGLE_VALIDATION_ERROR(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribBindings);
99 return false;
100 }
101 }
102
103 // [OpenGL ES 3.0.2] Section 2.8 page 24:
104 // An INVALID_OPERATION error is generated when a non-zero vertex array object
105 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
106 // and the pointer argument is not NULL.
107 bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
108 context->getState().getVertexArray()->id().value == 0;
109 if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
110 ptr != nullptr)
111 {
112 ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kClientDataInVertexArray);
113 return false;
114 }
115
116 if (context->isWebGL())
117 {
118 // WebGL 1.0 [Section 6.14] Fixed point support
119 // The WebGL API does not support the GL_FIXED data type.
120 if (type == VertexAttribType::Fixed)
121 {
122 ANGLE_VALIDATION_ERROR(GL_INVALID_ENUM, err::kFixedNotInWebGL);
123 return false;
124 }
125
126 if (!ValidateWebGLVertexAttribPointer(context, entryPoint, type, normalized, stride, ptr,
127 false))
128 {
129 return false;
130 }
131 }
132
133 return true;
134 }
135
136 void RecordBindTextureTypeError(const Context *context,
137 angle::EntryPoint entryPoint,
138 TextureType target);
139
ValidateBindTexture(const Context * context,angle::EntryPoint entryPoint,TextureType target,TextureID texture)140 ANGLE_INLINE bool ValidateBindTexture(const Context *context,
141 angle::EntryPoint entryPoint,
142 TextureType target,
143 TextureID texture)
144 {
145 if (!context->getStateCache().isValidBindTextureType(target))
146 {
147 RecordBindTextureTypeError(context, entryPoint, target);
148 return false;
149 }
150
151 if (texture.value == 0)
152 {
153 return true;
154 }
155
156 Texture *textureObject = context->getTexture(texture);
157 if (textureObject && textureObject->getType() != target)
158 {
159 ANGLE_VALIDATION_ERRORF(GL_INVALID_OPERATION, err::kTextureTargetMismatchWithLabel,
160 static_cast<uint8_t>(target),
161 static_cast<uint8_t>(textureObject->getType()),
162 textureObject->getLabel().c_str());
163 return false;
164 }
165
166 if (!context->getState().isBindGeneratesResourceEnabled() &&
167 !context->isTextureGenerated(texture))
168 {
169 ANGLE_VALIDATION_ERROR(GL_INVALID_OPERATION, err::kObjectNotGenerated);
170 return false;
171 }
172
173 return true;
174 }
175
176 // Validation of all Tex[Sub]Image2D parameters except TextureTarget.
177 bool ValidateES2TexImageParametersBase(const Context *context,
178 angle::EntryPoint entryPoint,
179 TextureTarget target,
180 GLint level,
181 GLenum internalformat,
182 bool isCompressed,
183 bool isSubImage,
184 GLint xoffset,
185 GLint yoffset,
186 GLsizei width,
187 GLsizei height,
188 GLint border,
189 GLenum format,
190 GLenum type,
191 GLsizei imageSize,
192 const void *pixels);
193
194 // Validation of TexStorage*2DEXT
195 bool ValidateES2TexStorageParametersBase(const Context *context,
196 angle::EntryPoint entryPoint,
197 TextureType target,
198 GLsizei levels,
199 GLenum internalformat,
200 GLsizei width,
201 GLsizei height);
202
203 // Validation of [Push,Pop]DebugGroup
204 bool ValidatePushDebugGroupBase(const Context *context,
205 angle::EntryPoint entryPoint,
206 GLenum source,
207 GLuint id,
208 GLsizei length,
209 const GLchar *message);
210 bool ValidatePopDebugGroupBase(const Context *context, angle::EntryPoint entryPoint);
211
212 // Validation of ObjectLabel
213 bool ValidateObjectLabelBase(const Context *context,
214 angle::EntryPoint entryPoint,
215 GLenum identifier,
216 GLuint name,
217 GLsizei length,
218 const GLchar *label);
219
220 // Validation of GetObjectLabel
221 bool ValidateGetObjectLabelBase(const Context *context,
222 angle::EntryPoint entryPoint,
223 GLenum identifier,
224 GLuint name,
225 GLsizei bufSize,
226 const GLsizei *length,
227 const GLchar *label);
228
229 // Validation of ObjectPtrLabel
230 bool ValidateObjectPtrLabelBase(const Context *context,
231 angle::EntryPoint entryPoint,
232 const void *ptr,
233 GLsizei length,
234 const GLchar *label);
235
236 // Validation of GetObjectPtrLabel
237 bool ValidateGetObjectPtrLabelBase(const Context *context,
238 angle::EntryPoint entryPoint,
239 const void *ptr,
240 GLsizei bufSize,
241 const GLsizei *length,
242 const GLchar *label);
243
244 } // namespace gl
245
246 #endif // LIBANGLE_VALIDATION_ES2_H_
247