LCOV - code coverage report
Current view: top level - xenolith/application - XLTexture.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 46 67 68.7 %
Date: 2024-05-12 00:16:13 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "XLTexture.h"
      24             : #include "XLTemporaryResource.h"
      25             : 
      26             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      27             : 
      28       68426 : Texture::~Texture() { }
      29             : 
      30       34078 : bool Texture::init(const core::ImageData *data) {
      31       34078 :         if (!ResourceObject::init(ResourceType::Texture)) {
      32           0 :                 return false;
      33             :         }
      34             : 
      35       34078 :         _data = data;
      36       34078 :         return true;
      37             : }
      38             : 
      39          90 : bool Texture::init(const core::ImageData *data, const Rc<core::Resource> &res) {
      40          90 :         if (!ResourceObject::init(ResourceType::Texture, res)) {
      41           0 :                 return false;
      42             :         }
      43             : 
      44          90 :         _data = data;
      45          90 :         return true;
      46             : }
      47             : 
      48          30 : bool Texture::init(const Rc<core::DynamicImage> &image) {
      49          30 :         if (!ResourceObject::init(ResourceType::Texture)) {
      50           0 :                 return false;
      51             :         }
      52             : 
      53          30 :         _dynamic = image;
      54          30 :         return true;
      55             : }
      56             : 
      57          15 : bool Texture::init(const core::ImageData *data, const Rc<TemporaryResource> &tmp) {
      58          15 :         if (!ResourceObject::init(ResourceType::Texture, tmp)) {
      59           0 :                 return false;
      60             :         }
      61             : 
      62          15 :         _data = data;
      63          15 :         return true;
      64             : }
      65             : 
      66        4441 : StringView Texture::getName() const {
      67        4441 :         if (_dynamic) {
      68        4360 :                 return _dynamic->getInfo().key;
      69          81 :         } else if (_data) {
      70          81 :                 return _data->key;
      71             :         }
      72           0 :         return StringView();
      73             : }
      74             : 
      75       30742 : uint64_t Texture::getIndex() const {
      76       30742 :         if (_dynamic) {
      77        1724 :                 return _dynamic->getInstance()->data.image->getIndex();
      78       29018 :         } else if (_data->image) {
      79       29018 :                 return _data->image->getIndex();
      80             :         }
      81           0 :         return 0;
      82             : }
      83             : 
      84       54562 : bool Texture::hasAlpha() const {
      85       54562 :         if (_dynamic) {
      86           0 :                 auto info = _dynamic->getInfo();
      87           0 :                 auto fmt = core::getImagePixelFormat(info.format);
      88           0 :                 switch (fmt) {
      89           0 :                 case core::PixelFormat::A:
      90             :                 case core::PixelFormat::IA:
      91             :                 case core::PixelFormat::RGBA:
      92           0 :                         return (info.hints & core::ImageHints::Opaque) == core::ImageHints::None;
      93             :                         break;
      94           0 :                 default:
      95           0 :                         break;
      96             :                 }
      97           0 :                 return false;
      98           0 :         } else {
      99       54562 :                 auto fmt = core::getImagePixelFormat(_data->format);
     100       54562 :                 switch (fmt) {
     101       54562 :                 case core::PixelFormat::A:
     102             :                 case core::PixelFormat::IA:
     103             :                 case core::PixelFormat::RGBA:
     104       54562 :                         return (_data->hints & core::ImageHints::Opaque) == core::ImageHints::None;
     105             :                         break;
     106           0 :                 default:
     107           0 :                         break;
     108             :                 }
     109           0 :                 return false;
     110             :         }
     111             : }
     112             : 
     113       39475 : Extent3 Texture::getExtent() const {
     114       39475 :         if (_dynamic) {
     115           0 :                 return _dynamic->getExtent();
     116       39475 :         } else if (_data) {
     117       39475 :                 return _data->extent;
     118             :         }
     119           0 :         return Extent3();
     120             : }
     121             : 
     122      580355 : bool Texture::isLoaded() const {
     123      580355 :         return _dynamic || (_temporary && _temporary->isLoaded() && _data->image) || _data->image;
     124             : }
     125             : 
     126          96 : core::MaterialImage Texture::getMaterialImage() const {
     127          96 :         core::MaterialImage ret;
     128          96 :         if (_dynamic) {
     129          15 :                 ret.dynamic = _dynamic->getInstance();
     130          15 :                 ret.image = &ret.dynamic->data;
     131             :         } else {
     132          81 :                 ret.image = _data;
     133             :         }
     134          96 :         return ret;
     135           0 : }
     136             : 
     137             : }

Generated by: LCOV version 1.14