blob: 01e611dafacfdd6a7cebc75b19a677ca5ebf2741 [file] [log] [blame]
Jamie Madill440dc742013-06-20 11:55:55 -04001//
2// Copyright (c) 2013 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
7#ifndef TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
8#define TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_
9
10#include <vector>
11
12namespace sh
13{
14
15struct Uniform;
16struct BlockMemberInfo;
17
18class BlockLayoutEncoder
19{
20 public:
21 BlockLayoutEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
22
23 void encodeFields(const std::vector<Uniform> &fields);
24 void encodeType(const Uniform &uniform);
25 size_t getBlockSize() { return mCurrentOffset * ComponentSize; }
26
27 static const size_t ComponentSize = 4u;
28 static const unsigned int RegisterSize = 4u;
29
30 protected:
31 size_t mCurrentOffset;
32
33 void nextRegister();
34
35 virtual void enterAggregateType() = 0;
36 virtual void exitAggregateType() = 0;
37 virtual void getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut) = 0;
38 virtual void advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride) = 0;
39
40 private:
41 std::vector<BlockMemberInfo> *mBlockInfoOut;
42};
43
44// Block layout according to the std140 block layout
45// See "Standard Uniform Block Layout" in Section 2.11.6 of the OpenGL ES 3.0 specification
46
47class Std140BlockEncoder : public BlockLayoutEncoder
48{
49 public:
50 Std140BlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
51
52 protected:
53 virtual void enterAggregateType();
54 virtual void exitAggregateType();
55 virtual void getBlockLayoutInfo(const Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut);
56 virtual void advanceOffset(const Uniform &uniform, int arrayStride, int matrixStride);
57};
58
59}
60
61#endif // TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_