| 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. | 
|---|
| 2 | // | 
|---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|---|
| 4 | // you may not use this file except in compliance with the License. | 
|---|
| 5 | // You may obtain a copy of the License at | 
|---|
| 6 | // | 
|---|
| 7 | //    http://www.apache.org/licenses/LICENSE-2.0 | 
|---|
| 8 | // | 
|---|
| 9 | // Unless required by applicable law or agreed to in writing, software | 
|---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|---|
| 12 | // See the License for the specific language governing permissions and | 
|---|
| 13 | // limitations under the License. | 
|---|
| 14 |  | 
|---|
| 15 | #ifndef sw_Stream_hpp | 
|---|
| 16 | #define sw_Stream_hpp | 
|---|
| 17 |  | 
|---|
| 18 | #include "Common/Types.hpp" | 
|---|
| 19 |  | 
|---|
| 20 | namespace sw | 
|---|
| 21 | { | 
|---|
| 22 | class Resource; | 
|---|
| 23 |  | 
|---|
| 24 | enum StreamType ENUM_UNDERLYING_TYPE_UNSIGNED_INT | 
|---|
| 25 | { | 
|---|
| 26 | STREAMTYPE_COLOR,     // 4 normalized unsigned bytes, ZYXW order | 
|---|
| 27 | STREAMTYPE_UDEC3,     // 3 unsigned 10-bit fields | 
|---|
| 28 | STREAMTYPE_DEC3N,     // 3 normalized signed 10-bit fields | 
|---|
| 29 | STREAMTYPE_INDICES,   // 4 unsigned bytes, stored unconverted into X component | 
|---|
| 30 | STREAMTYPE_FLOAT,     // Normalization ignored | 
|---|
| 31 | STREAMTYPE_BYTE, | 
|---|
| 32 | STREAMTYPE_SBYTE, | 
|---|
| 33 | STREAMTYPE_SHORT, | 
|---|
| 34 | STREAMTYPE_USHORT, | 
|---|
| 35 | STREAMTYPE_INT, | 
|---|
| 36 | STREAMTYPE_UINT, | 
|---|
| 37 | STREAMTYPE_FIXED,     // Normalization ignored (16.16 format) | 
|---|
| 38 | STREAMTYPE_HALF,      // Normalization ignored | 
|---|
| 39 | STREAMTYPE_2_10_10_10_INT, | 
|---|
| 40 | STREAMTYPE_2_10_10_10_UINT, | 
|---|
| 41 |  | 
|---|
| 42 | STREAMTYPE_LAST = STREAMTYPE_2_10_10_10_UINT | 
|---|
| 43 | }; | 
|---|
| 44 |  | 
|---|
| 45 | struct StreamResource | 
|---|
| 46 | { | 
|---|
| 47 | Resource *resource; | 
|---|
| 48 | const void *buffer; | 
|---|
| 49 | unsigned int stride; | 
|---|
| 50 | }; | 
|---|
| 51 |  | 
|---|
| 52 | struct Stream : public StreamResource | 
|---|
| 53 | { | 
|---|
| 54 | Stream(Resource *resource = 0, const void *buffer = 0, unsigned int stride = 0) | 
|---|
| 55 | { | 
|---|
| 56 | this->resource = resource; | 
|---|
| 57 | this->buffer = buffer; | 
|---|
| 58 | this->stride = stride; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | Stream &define(StreamType type, unsigned int count, bool normalized = false) | 
|---|
| 62 | { | 
|---|
| 63 | this->type = type; | 
|---|
| 64 | this->count = count; | 
|---|
| 65 | this->normalized = normalized; | 
|---|
| 66 |  | 
|---|
| 67 | return *this; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | Stream &define(const void *buffer, StreamType type, unsigned int count, bool normalized = false) | 
|---|
| 71 | { | 
|---|
| 72 | this->buffer = buffer; | 
|---|
| 73 | this->type = type; | 
|---|
| 74 | this->count = count; | 
|---|
| 75 | this->normalized = normalized; | 
|---|
| 76 |  | 
|---|
| 77 | return *this; | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | Stream &defaults() | 
|---|
| 81 | { | 
|---|
| 82 | static const float4 null = {0, 0, 0, 1}; | 
|---|
| 83 |  | 
|---|
| 84 | resource = 0; | 
|---|
| 85 | buffer = &null; | 
|---|
| 86 | stride = 0; | 
|---|
| 87 | type = STREAMTYPE_FLOAT; | 
|---|
| 88 | count = 0; | 
|---|
| 89 | normalized = false; | 
|---|
| 90 |  | 
|---|
| 91 | return *this; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | operator bool() const   // Returns true if stream contains data | 
|---|
| 95 | { | 
|---|
| 96 | return count != 0; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | StreamType type; | 
|---|
| 100 | unsigned char count; | 
|---|
| 101 | bool normalized; | 
|---|
| 102 | }; | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | #endif   // sw_Stream_hpp | 
|---|
| 106 |  | 
|---|