Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 1 | // |
| 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 Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 11 | #define GL_APICALL |
| 12 | #include <GLES3/gl3.h> |
| 13 | #include <GLES2/gl2.h> |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 14 | |
| 15 | namespace sh |
| 16 | { |
| 17 | |
| 18 | struct Uniform; |
| 19 | struct BlockMemberInfo; |
| 20 | |
| 21 | class 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 Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 28 | void encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 29 | 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 Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 41 | 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 Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 43 | |
| 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 | |
| 51 | class Std140BlockEncoder : public BlockLayoutEncoder |
| 52 | { |
| 53 | public: |
| 54 | Std140BlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut); |
| 55 | |
| 56 | protected: |
| 57 | virtual void enterAggregateType(); |
| 58 | virtual void exitAggregateType(); |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 59 | 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 Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | #endif // TRANSLATOR_COMMON_BLOCKLAYOUTENCODER_H_ |