Hash :
57ae8c16
Author :
Date :
2017-08-30T12:14:29
GLES3: Auto-generate entry points source. Lots of incidental fixes to formatting and naming. Adds specific default return type overloads for ClientWaitSync and GetUniformBlockIndex. BUG=angleproject:1309 Change-Id: Id67cbc0b19fc2cb94c859ab8390f1ff36b1bbd25 Reviewed-on: https://chromium-review.googlesource.com/637203 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// params:
// Parameter wrapper structs for OpenGL ES. These helpers cache re-used values
// in entry point routines.
#ifndef LIBANGLE_PARAMS_H_
#define LIBANGLE_PARAMS_H_
#include "angle_gl.h"
#include "common/Optional.h"
#include "common/angleutils.h"
#include "common/mathutil.h"
#include "libANGLE/entry_points_enum_autogen.h"
namespace gl
{
class Context;
template <EntryPoint EP>
struct EntryPointParam;
template <EntryPoint EP>
using EntryPointParamType = typename EntryPointParam<EP>::Type;
class ParamTypeInfo
{
public:
constexpr ParamTypeInfo(const char *selfClass, const ParamTypeInfo *parentType)
: mSelfClass(selfClass), mParentTypeInfo(parentType)
{
}
constexpr bool hasDynamicType(const ParamTypeInfo &typeInfo) const
{
return mSelfClass == typeInfo.mSelfClass ||
(mParentTypeInfo && mParentTypeInfo->hasDynamicType(typeInfo));
}
constexpr bool isValid() const { return mSelfClass != nullptr; }
private:
const char *mSelfClass;
const ParamTypeInfo *mParentTypeInfo;
};
#define ANGLE_PARAM_TYPE_INFO(NAME, BASENAME) \
static constexpr ParamTypeInfo TypeInfo = {#NAME, &BASENAME::TypeInfo}
class ParamsBase : angle::NonCopyable
{
public:
ParamsBase(Context *context, ...){};
template <EntryPoint EP, typename... ArgsT>
static void Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args);
static constexpr ParamTypeInfo TypeInfo = {nullptr, nullptr};
};
// static
template <EntryPoint EP, typename... ArgsT>
ANGLE_INLINE void ParamsBase::Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args)
{
new (objBuffer) EntryPointParamType<EP>(args...);
}
class HasIndexRange : public ParamsBase
{
public:
HasIndexRange(Context *context, GLsizei count, GLenum type, const void *indices)
: ParamsBase(context), mContext(context), mCount(count), mType(type), mIndices(indices)
{
}
template <EntryPoint EP, typename... ArgsT>
static void Factory(HasIndexRange *objBuffer, ArgsT... args);
const Optional<IndexRange> &getIndexRange() const;
ANGLE_PARAM_TYPE_INFO(HasIndexRange, ParamsBase);
private:
Context *mContext;
GLsizei mCount;
GLenum mType;
const GLvoid *mIndices;
mutable Optional<IndexRange> mIndexRange;
};
// Entry point funcs essentially re-map different entry point parameter arrays into
// the format the parameter type class expects. For example, for HasIndexRange, for the
// various indexed draw calls, they drop parameters that aren't useful and re-arrange
// the rest.
#define ANGLE_ENTRY_POINT_FUNC(NAME, CLASS, ...) \
\
template<> struct EntryPointParam<EntryPoint::NAME> \
{ \
using Type = CLASS; \
}; \
\
template<> inline void CLASS::Factory<EntryPoint::NAME>(__VA_ARGS__)
ANGLE_ENTRY_POINT_FUNC(DrawElements,
HasIndexRange,
HasIndexRange *objBuffer,
Context *context,
GLenum /*mode*/,
GLsizei count,
GLenum type,
const void *indices)
{
return ParamsBase::Factory<EntryPoint::DrawElements>(objBuffer, context, count, type, indices);
}
ANGLE_ENTRY_POINT_FUNC(DrawElementsInstanced,
HasIndexRange,
HasIndexRange *objBuffer,
Context *context,
GLenum /*mode*/,
GLsizei count,
GLenum type,
const void *indices,
GLsizei /*instanceCount*/)
{
return ParamsBase::Factory<EntryPoint::DrawElementsInstanced>(objBuffer, context, count, type,
indices);
}
ANGLE_ENTRY_POINT_FUNC(DrawElementsInstancedANGLE,
HasIndexRange,
HasIndexRange *objBuffer,
Context *context,
GLenum /*mode*/,
GLsizei count,
GLenum type,
const void *indices,
GLsizei /*instanceCount*/)
{
return ParamsBase::Factory<EntryPoint::DrawElementsInstancedANGLE>(objBuffer, context, count,
type, indices);
}
ANGLE_ENTRY_POINT_FUNC(DrawRangeElements,
HasIndexRange,
HasIndexRange *objBuffer,
Context *context,
GLenum /*mode*/,
GLuint /*start*/,
GLuint /*end*/,
GLsizei count,
GLenum type,
const void *indices)
{
return ParamsBase::Factory<EntryPoint::DrawRangeElements>(objBuffer, context, count, type,
indices);
}
#undef ANGLE_ENTRY_POINT_FUNC
template <EntryPoint EP>
struct EntryPointParam
{
using Type = ParamsBase;
};
// A template struct for determining the default value to return for each entry point.
template <EntryPoint EP, typename ReturnType>
struct DefaultReturnValue;
// Default return values for each basic return type.
template <EntryPoint EP>
struct DefaultReturnValue<EP, GLint>
{
static constexpr GLint kValue = -1;
};
// This doubles as the GLenum return value.
template <EntryPoint EP>
struct DefaultReturnValue<EP, GLuint>
{
static constexpr GLuint kValue = 0;
};
template <EntryPoint EP>
struct DefaultReturnValue<EP, GLboolean>
{
static constexpr GLboolean kValue = GL_FALSE;
};
// Catch-all rules for pointer types.
template <EntryPoint EP, typename PointerType>
struct DefaultReturnValue<EP, const PointerType *>
{
static constexpr const PointerType *kValue = nullptr;
};
template <EntryPoint EP, typename PointerType>
struct DefaultReturnValue<EP, PointerType *>
{
static constexpr PointerType *kValue = nullptr;
};
// Overloaded to return invalid index
template <>
struct DefaultReturnValue<EntryPoint::GetUniformBlockIndex, GLuint>
{
static constexpr GLuint kValue = GL_INVALID_INDEX;
};
// Specialized enum error value.
template <>
struct DefaultReturnValue<EntryPoint::ClientWaitSync, GLenum>
{
static constexpr GLenum kValue = GL_WAIT_FAILED;
};
template <EntryPoint EP, typename ReturnType>
constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
{
return DefaultReturnValue<EP, ReturnType>::kValue;
}
} // namespace gl
#endif // LIBANGLE_PARAMS_H_