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 context->validationError(entryPoint, GL_INVALID_ENUM, err::kInvalidBufferTypes);
44 return false;
45 }
46
47 if (!context->getState().isBindGeneratesResourceEnabled() &&
48 !context->isBufferGenerated(buffer))
49 {
50 context->validationError(entryPoint, 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 context->validationError(entryPoint, 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 context->validationError(entryPoint, GL_INVALID_VALUE,
93 err::kExceedsMaxVertexAttribStride);
94 return false;
95 }
96
97 if (index >= static_cast<GLuint>(caps.maxVertexAttribBindings))
98 {
99 context->validationError(entryPoint, GL_INVALID_VALUE,
100 err::kExceedsMaxVertexAttribBindings);
101 return false;
102 }
103 }
104
105 // [OpenGL ES 3.0.2] Section 2.8 page 24:
106 // An INVALID_OPERATION error is generated when a non-zero vertex array object
107 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
108 // and the pointer argument is not NULL.
109 bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
110 context->getState().getVertexArray()->id().value == 0;
111 if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
112 ptr != nullptr)
113 {
114 context->validationError(entryPoint, GL_INVALID_OPERATION, err::kClientDataInVertexArray);
115 return false;
116 }
117
118 if (context->isWebGL())
119 {
120 // WebGL 1.0 [Section 6.14] Fixed point support
121 // The WebGL API does not support the GL_FIXED data type.
122 if (type == VertexAttribType::Fixed)
123 {
124 context->validationError(entryPoint, GL_INVALID_ENUM, err::kFixedNotInWebGL);
125 return false;
126 }
127
128 if (!ValidateWebGLVertexAttribPointer(context, entryPoint, type, normalized, stride, ptr,
129 false))
130 {
131 return false;
132 }
133 }
134
135 return true;
136 }
137
138 void RecordBindTextureTypeError(const Context *context,
139 angle::EntryPoint entryPoint,
140 TextureType target);
141
ValidateBindTexture(const Context * context,angle::EntryPoint entryPoint,TextureType target,TextureID texture)142 ANGLE_INLINE bool ValidateBindTexture(const Context *context,
143 angle::EntryPoint entryPoint,
144 TextureType target,
145 TextureID texture)
146 {
147 if (!context->getStateCache().isValidBindTextureType(target))
148 {
149 RecordBindTextureTypeError(context, entryPoint, target);
150 return false;
151 }
152
153 if (texture.value == 0)
154 {
155 return true;
156 }
157
158 Texture *textureObject = context->getTexture(texture);
159 if (textureObject && textureObject->getType() != target)
160 {
161 context->validationErrorF(
162 entryPoint, GL_INVALID_OPERATION, err::kTextureTargetMismatchWithLabel,
163 static_cast<uint8_t>(target), static_cast<uint8_t>(textureObject->getType()),
164 textureObject->getLabel().c_str());
165 return false;
166 }
167
168 if (!context->getState().isBindGeneratesResourceEnabled() &&
169 !context->isTextureGenerated(texture))
170 {
171 context->validationError(entryPoint, GL_INVALID_OPERATION, err::kObjectNotGenerated);
172 return false;
173 }
174
175 return true;
176 }
177
178 // Validation of all Tex[Sub]Image2D parameters except TextureTarget.
179 bool ValidateES2TexImageParametersBase(const Context *context,
180 angle::EntryPoint entryPoint,
181 TextureTarget target,
182 GLint level,
183 GLenum internalformat,
184 bool isCompressed,
185 bool isSubImage,
186 GLint xoffset,
187 GLint yoffset,
188 GLsizei width,
189 GLsizei height,
190 GLint border,
191 GLenum format,
192 GLenum type,
193 GLsizei imageSize,
194 const void *pixels);
195
196 // Validation of TexStorage*2DEXT
197 bool ValidateES2TexStorageParametersBase(const Context *context,
198 angle::EntryPoint entryPoint,
199 TextureType target,
200 GLsizei levels,
201 GLenum internalformat,
202 GLsizei width,
203 GLsizei height);
204
205 } // namespace gl
206
207 #endif // LIBANGLE_VALIDATION_ES2_H_
208