mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-26 03:30:46 +00:00
1a5e64329f
We need something more manageable to deal with the textures - and the hightile code in particular needs a better backend to read the images.
130 lines
4.1 KiB
C++
130 lines
4.1 KiB
C++
/*
|
|
** texture.cpp
|
|
** The base texture class
|
|
**
|
|
**---------------------------------------------------------------------------
|
|
** Copyright 2004-2007 Randy Heit
|
|
** Copyright 2006-2018 Christoph Oelckers
|
|
** All rights reserved.
|
|
**
|
|
** Redistribution and use in source and binary forms, with or without
|
|
** modification, are permitted provided that the following conditions
|
|
** are met:
|
|
**
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
** notice, this list of conditions and the following disclaimer.
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
** documentation and/or other materials provided with the distribution.
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
** derived from this software without specific prior written permission.
|
|
**
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
**---------------------------------------------------------------------------
|
|
**
|
|
**
|
|
*/
|
|
|
|
#include "memarena.h"
|
|
#include "bitmap.h"
|
|
#include "image.h"
|
|
#include "files.h"
|
|
#include "cache1d.h"
|
|
|
|
int FImageSource::NextID;
|
|
|
|
//===========================================================================
|
|
//
|
|
// the default just returns an empty texture.
|
|
//
|
|
//===========================================================================
|
|
|
|
TArray<uint8_t> FImageSource::CreatePalettedPixels(int conversion)
|
|
{
|
|
TArray<uint8_t> Pixels(Width * Height, true);
|
|
memset(Pixels.Data(), 0, Width * Height);
|
|
return Pixels;
|
|
}
|
|
|
|
|
|
//===========================================================================
|
|
//
|
|
// FImageSource::CopyPixels
|
|
//
|
|
// this is the generic case that can handle
|
|
// any properly implemented texture for software rendering.
|
|
// Its drawback is that it is limited to the base palette which is
|
|
// why all classes that handle different palettes should subclass this
|
|
// method
|
|
//
|
|
//===========================================================================
|
|
|
|
int FImageSource::CopyTranslatedPixels(FBitmap *bmp, PalEntry *remap)
|
|
{
|
|
auto ppix = CreatePalettedPixels(false);
|
|
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap);
|
|
return 0;
|
|
}
|
|
|
|
int FImageSource::CopyPixels(FBitmap* bmp, int conversion)
|
|
{
|
|
return CopyTranslatedPixels(bmp, nullptr); // This should never get called for ART tiles.
|
|
}
|
|
|
|
|
|
//==========================================================================
|
|
//
|
|
//
|
|
//
|
|
//==========================================================================
|
|
|
|
typedef FImageSource * (*CreateFunc)(FileReader & file);
|
|
|
|
struct TexCreateInfo
|
|
{
|
|
CreateFunc TryCreate;
|
|
};
|
|
|
|
FImageSource *PNGImage_TryCreate(FileReader &);
|
|
FImageSource *JPEGImage_TryCreate(FileReader &);
|
|
FImageSource *DDSImage_TryCreate(FileReader &);
|
|
FImageSource *PCXImage_TryCreate(FileReader &);
|
|
FImageSource *TGAImage_TryCreate(FileReader &);
|
|
|
|
|
|
// Examines the lump contents to decide what type of texture to create,
|
|
// and creates the texture.
|
|
FImageSource * FImageSource::GetImage(const char *name)
|
|
{
|
|
static TexCreateInfo CreateInfo[] = {
|
|
{ PNGImage_TryCreate },
|
|
{ JPEGImage_TryCreate },
|
|
{ DDSImage_TryCreate },
|
|
{ PCXImage_TryCreate },
|
|
{ TGAImage_TryCreate },
|
|
{ nullptr }
|
|
};
|
|
|
|
auto data = kopenFileReader(name, 0);
|
|
if (!data.isOpen()) return nullptr;
|
|
|
|
for (size_t i = 0; CreateInfo[i].TryCreate; i++)
|
|
{
|
|
auto image = CreateInfo[i].TryCreate(data);
|
|
if (image != nullptr)
|
|
{
|
|
image->Name = name;
|
|
return image;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|