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,PrimitiveMode mode,GLint first,GLsizei count)18 ANGLE_INLINE bool ValidateDrawArrays(const Context *context,
19 PrimitiveMode mode,
20 GLint first,
21 GLsizei count)
22 {
23 return ValidateDrawArraysCommon(context, mode, first, count, 1);
24 }
25
ValidateUniform2f(const Context * context,UniformLocation location,GLfloat x,GLfloat y)26 ANGLE_INLINE bool ValidateUniform2f(const Context *context,
27 UniformLocation location,
28 GLfloat x,
29 GLfloat y)
30 {
31 return ValidateUniform(context, GL_FLOAT_VEC2, location, 1);
32 }
33
ValidateBindBuffer(const Context * context,BufferBinding target,BufferID buffer)34 ANGLE_INLINE bool ValidateBindBuffer(const Context *context, BufferBinding target, BufferID buffer)
35 {
36 if (!context->isValidBufferBinding(target))
37 {
38 context->validationError(GL_INVALID_ENUM, err::kInvalidBufferTypes);
39 return false;
40 }
41
42 if (!context->getState().isBindGeneratesResourceEnabled() &&
43 !context->isBufferGenerated(buffer))
44 {
45 context->validationError(GL_INVALID_OPERATION, err::kObjectNotGenerated);
46 return false;
47 }
48
49 return true;
50 }
51
ValidateDrawElements(const Context * context,PrimitiveMode mode,GLsizei count,DrawElementsType type,const void * indices)52 ANGLE_INLINE bool ValidateDrawElements(const Context *context,
53 PrimitiveMode mode,
54 GLsizei count,
55 DrawElementsType type,
56 const void *indices)
57 {
58 return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
59 }
60
ValidateVertexAttribPointer(const Context * context,GLuint index,GLint size,VertexAttribType type,GLboolean normalized,GLsizei stride,const void * ptr)61 ANGLE_INLINE bool ValidateVertexAttribPointer(const Context *context,
62 GLuint index,
63 GLint size,
64 VertexAttribType type,
65 GLboolean normalized,
66 GLsizei stride,
67 const void *ptr)
68 {
69 if (!ValidateFloatVertexFormat(context, index, size, type))
70 {
71 return false;
72 }
73
74 if (stride < 0)
75 {
76 context->validationError(GL_INVALID_VALUE, err::kNegativeStride);
77 return false;
78 }
79
80 if (context->getClientVersion() >= ES_3_1)
81 {
82 const Caps &caps = context->getCaps();
83 if (stride > caps.maxVertexAttribStride)
84 {
85 context->validationError(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribStride);
86 return false;
87 }
88
89 if (index >= static_cast<GLuint>(caps.maxVertexAttribBindings))
90 {
91 context->validationError(GL_INVALID_VALUE, err::kExceedsMaxVertexAttribBindings);
92 return false;
93 }
94 }
95
96 // [OpenGL ES 3.0.2] Section 2.8 page 24:
97 // An INVALID_OPERATION error is generated when a non-zero vertex array object
98 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
99 // and the pointer argument is not NULL.
100 bool nullBufferAllowed = context->getState().areClientArraysEnabled() &&
101 context->getState().getVertexArray()->id().value == 0;
102 if (!nullBufferAllowed && context->getState().getTargetBuffer(BufferBinding::Array) == 0 &&
103 ptr != nullptr)
104 {
105 context->validationError(GL_INVALID_OPERATION, err::kClientDataInVertexArray);
106 return false;
107 }
108
109 if (context->getExtensions().webglCompatibility)
110 {
111 // WebGL 1.0 [Section 6.14] Fixed point support
112 // The WebGL API does not support the GL_FIXED data type.
113 if (type == VertexAttribType::Fixed)
114 {
115 context->validationError(GL_INVALID_ENUM, err::kFixedNotInWebGL);
116 return false;
117 }
118
119 if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false))
120 {
121 return false;
122 }
123 }
124
125 return true;
126 }
127
128 void RecordBindTextureTypeError(const Context *context, TextureType target);
129
ValidateBindTexture(const Context * context,TextureType target,TextureID texture)130 ANGLE_INLINE bool ValidateBindTexture(const Context *context, TextureType target, TextureID texture)
131 {
132 if (!context->getStateCache().isValidBindTextureType(target))
133 {
134 RecordBindTextureTypeError(context, target);
135 return false;
136 }
137
138 if (texture.value == 0)
139 {
140 return true;
141 }
142
143 Texture *textureObject = context->getTexture(texture);
144 if (textureObject && textureObject->getType() != target)
145 {
146 context->validationError(GL_INVALID_OPERATION, err::kTextureTargetMismatch);
147 return false;
148 }
149
150 if (!context->getState().isBindGeneratesResourceEnabled() &&
151 !context->isTextureGenerated(texture))
152 {
153 context->validationError(GL_INVALID_OPERATION, err::kObjectNotGenerated);
154 return false;
155 }
156
157 return true;
158 }
159
160 // Validation of all Tex[Sub]Image2D parameters except TextureTarget.
161 bool ValidateES2TexImageParametersBase(const Context *context,
162 TextureTarget target,
163 GLint level,
164 GLenum internalformat,
165 bool isCompressed,
166 bool isSubImage,
167 GLint xoffset,
168 GLint yoffset,
169 GLsizei width,
170 GLsizei height,
171 GLint border,
172 GLenum format,
173 GLenum type,
174 GLsizei imageSize,
175 const void *pixels);
176
177 // Validation of TexStorage*2DEXT
178 bool ValidateES2TexStorageParametersBase(const Context *context,
179 TextureType target,
180 GLsizei levels,
181 GLenum internalformat,
182 GLsizei width,
183 GLsizei height);
184
185 } // namespace gl
186
187 #endif // LIBANGLE_VALIDATION_ES2_H_
188