blob: 57a8d81c135f067b5bd9c2d0f7109e9ce90472d1 [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
18struct Uniform;
19struct BlockMemberInfo;
20
21class BlockLayoutEncoder
22{
23 public:
24 BlockLayoutEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
25
26 void encodeFields(const std::vector<Uniform> &fields);
27 void encodeType(const Uniform &uniform);
Jamie Madill912cbfe2013-08-30 13:21:03 -040028 void encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix);
Jamie Madill440dc742013-06-20 11:55:55 -040029 size_t getBlockSize() { return mCurrentOffset * ComponentSize; }
30
31 static const size_t ComponentSize = 4u;
32 static const unsigned int RegisterSize = 4u;
33
34 protected:
35 size_t mCurrentOffset;
36
37 void nextRegister();
38
39 virtual void enterAggregateType() = 0;
40 virtual void exitAggregateType() = 0;
Jamie Madill912cbfe2013-08-30 13:21:03 -040041 virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
42 virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
Jamie Madill440dc742013-06-20 11:55:55 -040043
44 private:
45 std::vector<BlockMemberInfo> *mBlockInfoOut;
46};
47
48// Block layout according to the std140 block layout
49// See "Standard Uniform Block Layout" in Section 2.11.6 of the OpenGL ES 3.0 specification
50
51class Std140BlockEncoder : public BlockLayoutEncoder
52{
53 public:
54 Std140BlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut);
55
56 protected:
57 virtual void enterAggregateType();
58 virtual void exitAggregateType();
Jamie Madill912cbfe2013-08-30 13:21:03 -040059 virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut);
60 virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride);
Jamie Madill440dc742013-06-20 11:55:55 -040061};
62
63}
64
65#endif // TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_