Serenity Operating System
at master 64 lines 2.3 kB view raw
1/* 2 * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org> 3 * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/FixedArray.h> 11#include <AK/RefPtr.h> 12#include <LibGPU/Image.h> 13#include <LibGPU/ImageDataLayout.h> 14#include <LibGPU/ImageFormat.h> 15#include <LibGfx/Vector3.h> 16#include <LibGfx/Vector4.h> 17#include <LibSoftGPU/Buffer/Typed3DBuffer.h> 18 19namespace SoftGPU { 20 21class Image final : public GPU::Image { 22public: 23 Image(void const* ownership_token, GPU::PixelFormat const&, u32 width, u32 height, u32 depth, u32 max_levels); 24 25 bool width_is_power_of_two() const { return m_width_is_power_of_two; } 26 bool height_is_power_of_two() const { return m_height_is_power_of_two; } 27 bool depth_is_power_of_two() const { return m_depth_is_power_of_two; } 28 29 GPU::ImageDataLayout image_data_layout(u32 level, Vector3<i32> offset) const; 30 virtual void regenerate_mipmaps() override; 31 32 FloatVector4 const& texel(u32 level, int x, int y, int z) const 33 { 34 return *texel_pointer(level, x, y, z); 35 } 36 37 void set_texel(u32 level, int x, int y, int z, FloatVector4 const& color) 38 { 39 *texel_pointer(level, x, y, z) = color; 40 } 41 42 virtual void write_texels(u32 level, Vector3<i32> const& output_offset, void const* input_data, GPU::ImageDataLayout const&) override; 43 virtual void read_texels(u32 level, Vector3<i32> const& input_offset, void* output_data, GPU::ImageDataLayout const&) const override; 44 virtual void copy_texels(GPU::Image const& source, u32 source_level, Vector3<u32> const& source_offset, Vector3<u32> const& size, u32 destination_level, Vector3<u32> const& destination_offset) override; 45 46 FloatVector4 const* texel_pointer(u32 level, int x, int y, int z) const 47 { 48 return m_mipmap_buffers[level]->buffer_pointer(x, y, z); 49 } 50 51 FloatVector4* texel_pointer(u32 level, int x, int y, int z) 52 { 53 return m_mipmap_buffers[level]->buffer_pointer(x, y, z); 54 } 55 56private: 57 FixedArray<RefPtr<Typed3DBuffer<FloatVector4>>> m_mipmap_buffers; 58 59 bool m_width_is_power_of_two { false }; 60 bool m_height_is_power_of_two { false }; 61 bool m_depth_is_power_of_two { false }; 62}; 63 64}