| 70 | }; |
| 71 | |
| 72 | Status MakeGlTexture(const Object& object, const ObjectData& data, |
| 73 | GlTexture* gl_texture) { |
| 74 | if (object.access == AccessType::READ_WRITE || |
| 75 | object.access == AccessType::WRITE) { |
| 76 | return InvalidArgumentError("Read-write textures are not supported"); |
| 77 | } |
| 78 | if (object.data_type != DataType::FLOAT16 && |
| 79 | object.data_type != DataType::FLOAT32) { |
| 80 | return InvalidArgumentError("Textures support float16 or float32 only."); |
| 81 | } |
| 82 | switch (object.data_type) { |
| 83 | case DataType::FLOAT16: { |
| 84 | if (data.size() % 2 != 0) { |
| 85 | return InvalidArgumentError("Texture size is not aligned"); |
| 86 | } |
| 87 | return absl::visit( |
| 88 | TextureF16Maker{ |
| 89 | .data = absl::MakeConstSpan( |
| 90 | reinterpret_cast<const uint16_t*>(data.data()), |
| 91 | data.size() / 2), |
| 92 | .gl_texture = gl_texture, |
| 93 | }, |
| 94 | object.size); |
| 95 | } |
| 96 | case DataType::FLOAT32: { |
| 97 | if (data.size() % sizeof(float) != 0) { |
| 98 | return InvalidArgumentError("Texture size is not aligned"); |
| 99 | } |
| 100 | return absl::visit( |
| 101 | TextureF32Maker{ |
| 102 | .data = absl::MakeConstSpan( |
| 103 | reinterpret_cast<const float*>(data.data()), |
| 104 | data.size() / sizeof(float)), |
| 105 | .gl_texture = gl_texture, |
| 106 | }, |
| 107 | object.size); |
| 108 | } |
| 109 | default: |
| 110 | return InvalidArgumentError("Unsupported textures data type."); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | struct TextureRefMaker { |
| 115 | Status operator()(const uint3& size) const { |
no test coverage detected