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->validationError(entryPoint, GL_INVALID_OPERATION, err::kTextureTargetMismatch);
162 return false;
163 }
164
165 if (!context->getState().isBindGeneratesResourceEnabled() &&
166 !context->isTextureGenerated(texture))
167 {
168 context->validationError(entryPoint, GL_INVALID_OPERATION, err::kObjectNotGenerated);
169 return false;
170 }
171
172 return true;
173 }
174
175 // Validation of all Tex[Sub]Image2D parameters except TextureTarget.
176 bool ValidateES2TexImageParametersBase(const Context *context,
177 angle::EntryPoint entryPoint,
178 TextureTarget target,
179 GLint level,
180 GLenum internalformat,
181 bool isCompressed,
182 bool isSubImage,
183 GLint xoffset,
184 GLint yoffset,
185 GLsizei width,
186 GLsizei height,
187 GLint border,
188 GLenum format,
189 GLenum type,
190 GLsizei imageSize,
191 const void *pixels);
192
193 // Validation of TexStorage*2DEXT
194 bool ValidateES2TexStorageParametersBase(const Context *context,
195 angle::EntryPoint entryPoint,
196 TextureType target,
197 GLsizei levels,
198 GLenum internalformat,
199 GLsizei width,
200 GLsizei height);
201
202 } // namespace gl
203
204 #endif // LIBANGLE_VALIDATION_ES2_H_
205