blob: b6fb7bffaeb7dd0e3eab6523534efb474f3e9dc3 [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>
Jamie Madill912cbfe2013-08-30 13:21:03 -040011#define GL_APICALL
12#include <GLES3/gl3.h>
13#include <GLES2/gl2.h>
Jamie Madill440dc742013-06-20 11:55:55 -040014
15namespace sh
16{
17
Jamie Madill9d2ffb12013-08-30 13:21:04 -040018struct ShaderVariable;
19struct InterfaceBlockField;
Jamie Madill440dc742013-06-20 11:55:55 -040020struct BlockMemberInfo;
21
22class BlockLayoutEncoder
23{
24 public:
25 BlockLayoutEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
26
Jamie Madill9d2ffb12013-08-30 13:21:04 -040027 void encodeInterfaceBlockFields(const std::vector<InterfaceBlockField> &fields);
28 void encodeInterfaceBlockField(const InterfaceBlockField &field);
Jamie Madill912cbfe2013-08-30 13:21:03 -040029 void encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix);
Jamie Madill86a97a12013-08-30 13:21:09 -040030 size_t getBlockSize() const { return mCurrentOffset * BytesPerComponent; }
Jamie Madill440dc742013-06-20 11:55:55 -040031
Jamie Madill2b538b82013-08-30 13:21:09 -040032 static const size_t BytesPerComponent = 4u;
33 static const unsigned int ComponentsPerRegister = 4u;
Jamie Madill440dc742013-06-20 11:55:55 -040034
35 protected:
36 size_t mCurrentOffset;
37
38 void nextRegister();
39
40 virtual void enterAggregateType() = 0;
41 virtual void exitAggregateType() = 0;
Jamie Madill912cbfe2013-08-30 13:21:03 -040042 virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
43 virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
Jamie Madill440dc742013-06-20 11:55:55 -040044
45 private:
46 std::vector<BlockMemberInfo> *mBlockInfoOut;
47};
48
49// Block layout according to the std140 block layout
50// See "Standard Uniform Block Layout" in Section 2.11.6 of the OpenGL ES 3.0 specification
51
52class Std140BlockEncoder : public BlockLayoutEncoder
53{
54 public:
55 Std140BlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
56
57 protected:
58 virtual void enterAggregateType();
59 virtual void exitAggregateType();
Jamie Madill912cbfe2013-08-30 13:21:03 -040060 virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
61 virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
Jamie Madill440dc742013-06-20 11:55:55 -040062};
63
64}
65
66#endif // TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_