1 //
2 // Copyright 2017 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 // params:
7 //   Parameter wrapper structs for OpenGL ES. These helpers cache re-used values
8 //   in entry point routines.
9 
10 #include "libANGLE/params.h"
11 
12 #include "common/utilities.h"
13 #include "libANGLE/Context.h"
14 #include "libANGLE/VertexArray.h"
15 
16 namespace gl
17 {
18 
19 // static
20 constexpr ParamTypeInfo ParamsBase::TypeInfo;
21 constexpr ParamTypeInfo HasIndexRange::TypeInfo;
22 
HasIndexRange()23 HasIndexRange::HasIndexRange()
24     : ParamsBase(nullptr), mContext(nullptr), mCount(0), mType(GL_NONE), mIndices(nullptr)
25 {
26 }
27 
HasIndexRange(Context * context,GLsizei count,GLenum type,const void * indices)28 HasIndexRange::HasIndexRange(Context *context, GLsizei count, GLenum type, const void *indices)
29     : ParamsBase(context), mContext(context), mCount(count), mType(type), mIndices(indices)
30 {
31 }
32 
getIndexRange() const33 const Optional<IndexRange> &HasIndexRange::getIndexRange() const
34 {
35     if (mIndexRange.valid() || !mContext)
36     {
37         return mIndexRange;
38     }
39 
40     const State &state = mContext->getGLState();
41 
42     const gl::VertexArray *vao     = state.getVertexArray();
43     gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get();
44 
45     if (elementArrayBuffer)
46     {
47         uintptr_t offset = reinterpret_cast<uintptr_t>(mIndices);
48         IndexRange indexRange;
49         Error error =
50             elementArrayBuffer->getIndexRange(mContext, mType, static_cast<size_t>(offset), mCount,
51                                               state.isPrimitiveRestartEnabled(), &indexRange);
52         if (error.isError())
53         {
54             mContext->handleError(error);
55             return mIndexRange;
56         }
57 
58         mIndexRange = indexRange;
59     }
60     else
61     {
62         mIndexRange = ComputeIndexRange(mType, mIndices, mCount, state.isPrimitiveRestartEnabled());
63     }
64 
65     return mIndexRange;
66 }
67 
68 }  // namespace gl
69