1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement support for array textures in GL driver

note: feature detection was not implemented in the legacy driver, but the code itself probably works.
This commit is contained in:
sfan5 2025-04-06 22:16:17 +02:00
parent d5bf094f9a
commit 46db688cc8
14 changed files with 111 additions and 72 deletions

View file

@ -294,25 +294,9 @@ u32 CNullDriver::getTextureCount() const
ITexture *CNullDriver::addTexture(const core::dimension2d<u32> &size, const io::path &name, ECOLOR_FORMAT format)
{
if (0 == name.size()) {
os::Printer::log("Could not create ITexture, texture needs to have a non-empty name.", ELL_WARNING);
return 0;
}
IImage *image = new CImage(format, size);
ITexture *t = 0;
if (checkImage(image)) {
t = createDeviceDependentTexture(name, image);
}
ITexture *t = addTexture(name, image);
image->drop();
if (t) {
addTexture(t);
t->drop();
}
return t;
}
@ -329,7 +313,8 @@ ITexture *CNullDriver::addTexture(const io::path &name, IImage *image)
ITexture *t = 0;
if (checkImage(image)) {
t = createDeviceDependentTexture(name, image);
std::vector tmp { image };
t = createDeviceDependentTexture(name, ETT_2D, tmp);
}
if (t) {
@ -340,6 +325,27 @@ ITexture *CNullDriver::addTexture(const io::path &name, IImage *image)
return t;
}
ITexture *CNullDriver::addArrayTexture(const io::path &name, IImage **images, u32 count)
{
if (0 == name.size()) {
os::Printer::log("Could not create ITexture, texture needs to have a non-empty name.", ELL_WARNING);
return 0;
}
// this is stupid but who cares
std::vector<IImage*> tmp(images, images + count);
ITexture *t = nullptr;
if (checkImage(tmp)) {
t = createDeviceDependentTexture(name, ETT_2D_ARRAY, tmp);
}
if (t) {
addTexture(t);
t->drop();
}
return t;
}
ITexture *CNullDriver::addTextureCubemap(const io::path &name, IImage *imagePosX, IImage *imageNegX, IImage *imagePosY,
IImage *imageNegY, IImage *imagePosZ, IImage *imageNegZ)
{
@ -357,7 +363,7 @@ ITexture *CNullDriver::addTextureCubemap(const io::path &name, IImage *imagePosX
imageArray.push_back(imageNegZ);
if (checkImage(imageArray)) {
t = createDeviceDependentTextureCubemap(name, imageArray);
t = createDeviceDependentTexture(name, ETT_CUBEMAP, imageArray);
}
if (t) {
@ -384,7 +390,7 @@ ITexture *CNullDriver::addTextureCubemap(const irr::u32 sideLen, const io::path
ITexture *t = 0;
if (checkImage(imageArray)) {
t = createDeviceDependentTextureCubemap(name, imageArray);
t = createDeviceDependentTexture(name, ETT_CUBEMAP, imageArray);
if (t) {
addTexture(t);
@ -479,7 +485,8 @@ video::ITexture *CNullDriver::loadTextureFromFile(io::IReadFile *file, const io:
return nullptr;
if (checkImage(image)) {
texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), image);
std::vector tmp { image };
texture = createDeviceDependentTexture(hashName.size() ? hashName : file->getFileName(), ETT_2D, tmp);
if (texture)
os::Printer::log("Loaded texture", file->getFileName(), ELL_DEBUG);
}
@ -519,18 +526,16 @@ video::ITexture *CNullDriver::findTexture(const io::path &filename)
return 0;
}
ITexture *CNullDriver::createDeviceDependentTexture(const io::path &name, IImage *image)
ITexture *CNullDriver::createDeviceDependentTexture(const io::path &name, E_TEXTURE_TYPE type,
const std::vector<IImage*> &images)
{
SDummyTexture *dummy = new SDummyTexture(name, ETT_2D);
dummy->setSize(image->getDimension());
if (type != ETT_2D && type != ETT_CUBEMAP)
return nullptr;
SDummyTexture *dummy = new SDummyTexture(name, type);
dummy->setSize(images[0]->getDimension());
return dummy;
}
ITexture *CNullDriver::createDeviceDependentTextureCubemap(const io::path &name, const std::vector<IImage*> &image)
{
return new SDummyTexture(name, ETT_CUBEMAP);
}
bool CNullDriver::setRenderTargetEx(IRenderTarget *target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil)
{
return false;
@ -883,6 +888,9 @@ bool CNullDriver::checkImage(const std::vector<IImage*> &image) const
auto lastSize = image[0]->getDimension();
for (size_t i = 0; i < image.size(); ++i) {
if (!image[i])
return false;
ECOLOR_FORMAT format = image[i]->getColorFormat();
auto size = image[i]->getDimension();