2021-05-13 22:18:17 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
|
2021-08-11 19:57:22 +02:00
|
|
|
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
|
2022-08-24 23:47:49 +02:00
|
|
|
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
|
2021-05-13 22:18:17 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibGL/GL/gl.h>
|
2021-05-29 23:34:40 +02:00
|
|
|
#include <LibGL/Tex/Texture2D.h>
|
2021-05-13 22:18:17 +10:00
|
|
|
|
|
|
|
|
namespace GL {
|
|
|
|
|
|
2022-08-24 23:47:49 +02:00
|
|
|
void Texture2D::upload_texture_data(GLuint lod, GLenum internal_format, GPU::ImageDataLayout input_layout, GLvoid const* pixels)
|
2021-05-13 22:18:17 +10:00
|
|
|
{
|
|
|
|
|
// NOTE: Some target, format, and internal formats are currently unsupported.
|
|
|
|
|
// Considering we control this library, and `gl.h` itself, we don't need to add any
|
|
|
|
|
// checks here to see if we support them; the program will simply fail to compile..
|
|
|
|
|
|
2021-08-18 13:25:48 +02:00
|
|
|
auto& mip = m_mipmaps[lod];
|
2022-03-08 12:16:56 +01:00
|
|
|
m_internal_format = internal_format;
|
2022-08-24 23:47:49 +02:00
|
|
|
mip.set_width(input_layout.selection.width);
|
|
|
|
|
mip.set_height(input_layout.selection.height);
|
2022-03-08 12:16:56 +01:00
|
|
|
|
|
|
|
|
// No pixel data was supplied; leave the texture memory uninitialized.
|
2021-11-28 01:48:21 +01:00
|
|
|
if (pixels == nullptr)
|
2021-08-18 13:25:48 +02:00
|
|
|
return;
|
2021-05-13 22:18:17 +10:00
|
|
|
|
2022-08-24 23:47:49 +02:00
|
|
|
replace_sub_texture_data(lod, input_layout, { 0, 0, 0 }, pixels);
|
2021-08-31 22:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-24 23:47:49 +02:00
|
|
|
void Texture2D::replace_sub_texture_data(GLuint lod, GPU::ImageDataLayout input_layout, Vector3<i32> const& output_offset, GLvoid const* pixels)
|
2021-08-31 22:35:52 +02:00
|
|
|
{
|
2021-12-23 13:52:19 +01:00
|
|
|
// FIXME: We currently depend on the first glTexImage2D call to attach an image to mipmap level 0, which initializes the GPU image
|
|
|
|
|
// Ideally we would create separate GPU images for each level and merge them into a final image
|
|
|
|
|
// once used for rendering for the first time.
|
|
|
|
|
if (device_image().is_null())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-08-24 23:47:49 +02:00
|
|
|
device_image()->write_texels(0, lod, output_offset, pixels, input_layout);
|
2021-05-13 22:18:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|