Hash :
834e8b77
Author :
Date :
2014-04-11T13:33:58
Move ShaderVariables to common shared source. Also move the block layout encoding utilities to the common folder. The combined changes allow us to include the shader and block code into both libGLESv2 and the translator separately. This in turn fixes the Chromium component build, where we were calling internal translator functions directly from libGLESv2. BUG=angle:568 Change-Id: Ibcfa2c936a7c737ad515c10bd24061ff39ee5747 Reviewed-on: https://chromium-review.googlesource.com/192891 Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: 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
//
// Copyright (c) 2013-2014 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.
//
// shadervars.h:
// Types to represent GL variables (varyings, uniforms, etc)
//
#ifndef COMMON_SHADERVARIABLE_H_
#define COMMON_SHADERVARIABLE_H_
#include <string>
#include <vector>
#include <algorithm>
#define GL_APICALL
#include <GLES3/gl3.h>
#include <GLES2/gl2.h>
namespace gl
{
enum InterpolationType
{
INTERPOLATION_SMOOTH,
INTERPOLATION_CENTROID,
INTERPOLATION_FLAT
};
struct ShaderVariable
{
GLenum type;
GLenum precision;
std::string name;
unsigned int arraySize;
ShaderVariable(GLenum type, GLenum precision, const char *name, unsigned int arraySize);
bool isArray() const { return arraySize > 0; }
unsigned int elementCount() const { return std::max(1u, arraySize); }
};
struct Uniform : public ShaderVariable
{
unsigned int registerIndex;
unsigned int elementIndex; // For struct varyings
std::vector<Uniform> fields;
Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
unsigned int registerIndexIn, unsigned int elementIndexIn);
bool isStruct() const { return !fields.empty(); }
};
struct Attribute : public ShaderVariable
{
int location;
Attribute();
Attribute(GLenum type, GLenum precision, const char *name, unsigned int arraySize, int location);
};
struct InterfaceBlockField : public ShaderVariable
{
bool isRowMajorMatrix;
std::vector<InterfaceBlockField> fields;
InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix);
bool isStruct() const { return !fields.empty(); }
};
struct Varying : public ShaderVariable
{
InterpolationType interpolation;
std::vector<Varying> fields;
unsigned int registerIndex; // Assigned during link
unsigned int elementIndex; // First register element for varyings, assigned during link
std::string structName;
Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn);
bool isStruct() const { return !fields.empty(); }
bool registerAssigned() const { return registerIndex != GL_INVALID_INDEX; }
void resetRegisterAssignment();
};
struct BlockMemberInfo
{
BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix);
int offset;
int arrayStride;
int matrixStride;
bool isRowMajorMatrix;
static const BlockMemberInfo defaultBlockInfo;
};
typedef std::vector<BlockMemberInfo> BlockMemberInfoArray;
enum BlockLayoutType
{
BLOCKLAYOUT_STANDARD,
BLOCKLAYOUT_PACKED,
BLOCKLAYOUT_SHARED
};
struct InterfaceBlock
{
InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex);
std::string name;
unsigned int arraySize;
size_t dataSize;
BlockLayoutType layout;
bool isRowMajorLayout;
std::vector<InterfaceBlockField> fields;
std::vector<BlockMemberInfo> blockInfo;
unsigned int registerIndex;
};
}
#endif // COMMON_SHADERVARIABLE_H_