- backend update from GZDoom for adding vcpkg integration

This commit is contained in:
Christoph Oelckers 2023-09-02 09:13:41 +02:00
parent e88d2fb6b4
commit 4e53f3bd81
17 changed files with 149 additions and 63 deletions

View file

@ -1,11 +1,4 @@
cmake_minimum_required( VERSION 3.1.0 )
project(Raze)
set ( PROJECT_NAME "raze")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
cmake_minimum_required( VERSION 3.16 )
if( COMMAND cmake_policy )
if( POLICY CMP0011 )
@ -14,8 +7,54 @@ if( COMMAND cmake_policy )
if( POLICY CMP0054 )
cmake_policy( SET CMP0054 NEW )
endif()
if ( POLICY CMP0067 )
cmake_policy( SET CMP0067 NEW )
endif()
if ( POLICY CMP0057 )
cmake_policy( SET CMP0057 NEW )
endif()
if ( POLICY CMP0091 )
cmake_policy( SET CMP0091 NEW )
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
if (LIBVPX_VCPKG)
list(APPEND VCPKG_MANIFEST_FEATURES "vcpkg-libvpx")
endif()
if (OPENAL_SOFT_VCPKG)
list(APPEND VCPKG_MANIFEST_FEATURES "vcpkg-openal-soft")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows"))
# Force static triplet on Windows
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
endif()
project(Raze)
if (WIN32 AND VCPKG_TOOLCHAIN)
option(LIBVPX_VCPKG "Use libvpx from vcpkg" OFF)
endif()
if (VCPKG_TOOLCHAIN)
option(OPENAL_SOFT_VCPKG "Use OpenAL from vcpkg" OFF)
endif()
if (NOT VCPKG_TOOLCHAIN)
set(VCPKG_MANIFEST_FEATURES)
endif()
set ( PROJECT_NAME "raze")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
list( APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
include( FindPackageHandleStandardArgs )
@ -188,6 +227,7 @@ find_package( BZip2 )
find_package( JPEG )
find_package( VPX )
find_package( ZLIB )
find_package( WebP )
include( TargetArch )

View file

@ -307,7 +307,7 @@ if( UNIX )
add_definitions( -DNO_CLOCK_GETTIME )
endif()
else()
set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} rt )
list( APPEND PROJECT_LIBRARIES rt )
endif()
endif()
@ -324,7 +324,7 @@ add_custom_target( revision_check ALL
set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} "${ZLIB_LIBRARIES}" "${JPEG_LIBRARIES}" "${BZIP2_LIBRARIES}" "${CMAKE_DL_LIBS}" "${TESS_LIBRARIES}" "${DRPC_LIBRARIES}")
if (HAVE_VULKAN)
set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} "zvulkan")
list( APPEND PROJECT_LIBRARIES "zvulkan" )
endif()
# ZMUSIC
@ -383,6 +383,12 @@ else()
message( SEND_ERROR "Could not find libvpx" )
endif()
#if (TARGET WebP::webp)
list( APPEND PROJECT_LIBRARIES WebP::webp WebP::webpdemux WebP::libwebpmux )
if (TARGET WebP::webpdecoder)
list( APPEND PROJECT_LIBRARIES WebP::webpdecoder)
endif()
#endif()
include_directories( SYSTEM "${ZLIB_INCLUDE_DIR}" "${ZMUSIC_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${TESS_INCLUDE_DIR}" "${DRPC_INCLUDE_DIR}" )
@ -1080,6 +1086,7 @@ set (PCH_SOURCES
common/textures/formats/anmtexture.cpp
common/textures/formats/startscreentexture.cpp
common/textures/formats/qoitexture.cpp
common/textures/formats/webptexture.cpp
common/textures/hires/hqresize.cpp
common/models/models_md3.cpp
common/models/models_md2.cpp
@ -1430,6 +1437,11 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
${CMAKE_SOURCE_DIR}/soundfont/${PROJECT_NAME}.sf2 $<TARGET_FILE_DIR:${PROJECT_NAME}>/soundfonts/${PROJECT_NAME}.sf2
)
if (VCPKG_TOOLCHAIN)
x_vcpkg_install_local_dependencies(TARGETS ${PROJECT_NAME} DESTINATION ".")
endif()
if( CMAKE_COMPILER_IS_GNUCXX )
# GCC misoptimizes this file
endif()

View file

@ -422,7 +422,7 @@ void FFont::ReadSheetFont(std::vector<FileSys::FolderEntry> &folderdata, int wid
FBitmap* sheetimg = &sheetBitmaps[sheetBitmaps.Reserve(1)];
sheetimg->Create(tex->GetTexelWidth(), tex->GetTexelHeight());
tex->GetTexture()->GetImage()->CopyPixels(sheetimg, FImageSource::normal);
tex->GetTexture()->GetImage()->CopyPixels(sheetimg, FImageSource::normal, 0);
for (int y = 0; y < numtex_y; y++)
{

View file

@ -35,5 +35,3 @@ extern TArray<TranslationMap> TranslationLookup;
extern TArray<PalEntry> TranslationColors;
class FImageSource;
void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors);

View file

@ -25,9 +25,9 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
*/
//-------------------------------------------------------------------------
#include <string.h>
#include "animlib.h"
#include "m_swap.h"
#include "m_alloc.h"
//****************************************************************************
//

View file

@ -118,7 +118,7 @@ void iCopyColors(uint8_t *pout, const uint8_t *pin, int count, int step, FCopyIn
a = TSrc::A(pin, tr, tg, tb);
if (TBlend::ProcessAlpha0() || a)
{
int gray = clamp<int>(TSrc::Gray(pin),0,255);
int gray = std::clamp<int>(TSrc::Gray(pin),0,255);
PalEntry pe = cm->GrayscaleToColor[gray];
TBlend::OpC(pout[TDest::RED], pe.r , a, inf);

View file

@ -36,8 +36,6 @@
#ifndef __BITMAP_H__
#define __BITMAP_H__
#include "basics.h"
#include "palentry.h"
struct FCopyInfo;
@ -320,9 +318,9 @@ struct cCMYK
struct cYCbCr
{
static __forceinline unsigned char R(const unsigned char * p) { return clamp((int)(p[0] + 1.40200 * (int(p[2]) - 0x80)), 0, 255); }
static __forceinline unsigned char G(const unsigned char * p) { return clamp((int)(p[0] - 0.34414 * (int(p[1] - 0x80)) - 0.71414 * (int(p[2]) - 0x80)), 0, 255); }
static __forceinline unsigned char B(const unsigned char * p) { return clamp((int)(p[0] + 1.77200 * (int(p[1]) - 0x80)), 0, 255); }
static __forceinline unsigned char R(const unsigned char * p) { return std::clamp((int)(p[0] + 1.40200 * (int(p[2]) - 0x80)), 0, 255); }
static __forceinline unsigned char G(const unsigned char * p) { return std::clamp((int)(p[0] - 0.34414 * (int(p[1] - 0x80)) - 0.71414 * (int(p[2]) - 0x80)), 0, 255); }
static __forceinline unsigned char B(const unsigned char * p) { return std::clamp((int)(p[0] + 1.77200 * (int(p[1]) - 0x80)), 0, 255); }
static __forceinline unsigned char A(const unsigned char * p, uint8_t x, uint8_t y, uint8_t z) { return 255; }
static __forceinline int Gray(const unsigned char * p) { return (R(p) * 77 + G(p) * 143 + B(p) * 36) >> 8; }
};
@ -470,7 +468,7 @@ struct bCopyAlpha
struct bOverlay
{
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = (s*a + d*(255-a))/255; }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = max(s,d); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = std::max(s,d); }
static __forceinline bool ProcessAlpha0() { return false; }
};
@ -483,21 +481,21 @@ struct bBlend
struct bAdd
{
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = min<int>((d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 255); }
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = std::min<int>((d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 255); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; }
static __forceinline bool ProcessAlpha0() { return false; }
};
struct bSubtract
{
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = max<int>((d*BLENDUNIT - s*i->alpha) >> BLENDBITS, 0); }
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = std::max<int>((d*BLENDUNIT - s*i->alpha) >> BLENDBITS, 0); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; }
static __forceinline bool ProcessAlpha0() { return false; }
};
struct bReverseSubtract
{
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = max<int>((-d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 0); }
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = std::max<int>((-d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 0); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; }
static __forceinline bool ProcessAlpha0() { return false; }
};

View file

@ -33,6 +33,7 @@
**
*/
#include <memory>
#include "files.h"
#include "filesystem.h"
#include "bitmap.h"
@ -72,12 +73,12 @@ FImageSource *AnmImage_TryCreate(FileReader & file, int lumpnum)
file.Seek(0, FileReader::SeekSet);
auto buffer = file.ReadPadded(1);
anim_t anim;
if (ANIM_LoadAnim(&anim, buffer.data(), buffer.size() - 1) < 0)
std::unique_ptr<anim_t> anim = std::make_unique<anim_t>(); // note that this struct is very large and should not go onto the stack!
if (ANIM_LoadAnim(anim.get(), buffer.data(), buffer.size() - 1) < 0)
{
return nullptr;
}
int numframes = ANIM_NumFrames(&anim);
int numframes = ANIM_NumFrames(anim.get());
if (numframes >= 1)
{
return new FAnmTexture(lumpnum, 320, 200);
@ -106,14 +107,14 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
anim_t anim;
if (ANIM_LoadAnim(&anim, source, (int)lump.GetSize()) >= 0)
std::unique_ptr<anim_t> anim = std::make_unique<anim_t>(); // note that this struct is very large and should not go onto the stack!
if (ANIM_LoadAnim(anim.get(), source, (int)lump.GetSize()) >= 0)
{
int numframes = ANIM_NumFrames(&anim);
int numframes = ANIM_NumFrames(anim.get());
if (numframes >= 1)
{
memcpy(palette, ANIM_GetPalette(&anim), 768);
memcpy(pixels, ANIM_DrawFrame(&anim, 1), Width*Height);
memcpy(palette, ANIM_GetPalette(anim.get()), 768);
memcpy(pixels, ANIM_DrawFrame(anim.get(), 1), Width * Height);
return;
}
}
@ -121,6 +122,12 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
memset(palette, 0, 768);
}
struct workbuf
{
uint8_t buffer[64000];
uint8_t palette[768];
};
//==========================================================================
//
//
@ -130,16 +137,15 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion, int frame)
{
PalettedPixels pixels(Width*Height);
uint8_t buffer[64000];
uint8_t palette[768];
uint8_t remap[256];
std::unique_ptr<workbuf> w = std::make_unique<workbuf>();
ReadFrame(buffer, palette);
ReadFrame(w->buffer, w->palette);
for(int i=0;i<256;i++)
{
remap[i] = ColorMatcher.Pick(palette[i*3], palette[i*3+1], palette[i*3+2]);
remap[i] = ColorMatcher.Pick(w->palette[i*3], w->palette[i*3+1], w->palette[i*3+2]);
}
ImageHelpers::FlipNonSquareBlockRemap (pixels.Data(), buffer, Width, Height, Width, remap);
ImageHelpers::FlipNonSquareBlockRemap (pixels.Data(), w->buffer, Width, Height, Width, remap);
return pixels;
}
@ -151,18 +157,17 @@ PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion, int frame)
int FAnmTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{
uint8_t buffer[64000];
uint8_t palette[768];
ReadFrame(buffer, palette);
std::unique_ptr<workbuf> w = std::make_unique<workbuf>();
ReadFrame(w->buffer, w->palette);
auto dpix = bmp->GetPixels();
for (int i = 0; i < Width * Height; i++)
{
int p = i * 4;
int index = buffer[i];
dpix[p + 0] = palette[index * 3 + 2];
dpix[p + 1] = palette[index * 3 + 1];
dpix[p + 2] = palette[index * 3];
int index = w->buffer[i];
dpix[p + 0] = w->palette[index * 3 + 2];
dpix[p + 1] = w->palette[index * 3 + 1];
dpix[p + 2] = w->palette[index * 3];
dpix[p + 3] = 255;
}

View file

@ -67,7 +67,7 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source)
int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{
SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette);
SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette, frame);
return 0;
}

View file

@ -200,7 +200,7 @@ PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion, int frame)
int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette);
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion, frame);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette, frame);
}

View file

@ -41,6 +41,17 @@
#include "m_swap.h"
// Doom patch format header
struct patch_t
{
int16_t width; // bounding box size
int16_t height;
int16_t leftoffset; // pixels to the left of origin
int16_t topoffset; // pixels below the origin
uint32_t columnofs[1]; // only [width] used
};
// posts are runs of non masked source pixels
struct column_t
{
@ -266,8 +277,8 @@ PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion, int frame)
int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette);
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion, frame);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette, frame);
}
//==========================================================================

View file

@ -40,6 +40,16 @@
#include "image.h"
#include "m_swap.h"
// Doom patch format header
struct patch_t
{
int16_t width; // bounding box size
int16_t height;
int16_t leftoffset; // pixels to the left of origin
int16_t topoffset; // pixels below the origin
uint32_t columnofs[1]; // only [width] used
};
//==========================================================================
//
@ -201,7 +211,7 @@ PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion, int frame)
int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{
if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion);
if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion, frame);
else
{
auto lump = fileSystem.ReadFile(SourceLump);

View file

@ -331,6 +331,7 @@ FImageSource *PCXImage_TryCreate(FileReader &, int lumpnum);
FImageSource *TGAImage_TryCreate(FileReader &, int lumpnum);
FImageSource *StbImage_TryCreate(FileReader &, int lumpnum);
FImageSource *QOIImage_TryCreate(FileReader &, int lumpnum);
FImageSource *WebPImage_TryCreate(FileReader &, int lumpnum);
FImageSource *AnmImage_TryCreate(FileReader &, int lumpnum);
FImageSource *RawPageImage_TryCreate(FileReader &, int lumpnum);
FImageSource *FlatImage_TryCreate(FileReader &, int lumpnum);
@ -352,6 +353,7 @@ FImageSource * FImageSource::GetImage(int lumpnum, bool isflat)
{ PCXImage_TryCreate, false },
{ StbImage_TryCreate, false },
{ QOIImage_TryCreate, false },
{ WebPImage_TryCreate, false },
{ TGAImage_TryCreate, false },
{ AnmImage_TryCreate, false },
{ StartupPageImage_TryCreate, false },

View file

@ -5,20 +5,24 @@
#include "bitmap.h"
#include "memarena.h"
#ifndef MAKE_ID
#ifndef __BIG_ENDIAN__
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
#else
#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24)))
#endif
#endif
using std::min;
using std::max;
using std::clamp;
class FImageSource;
using PrecacheInfo = TMap<int, std::pair<int, int>>;
extern FMemArena ImageArena;
// Doom patch format header
struct patch_t
{
int16_t width; // bounding box size
int16_t height;
int16_t leftoffset; // pixels to the left of origin
int16_t topoffset; // pixels below the origin
uint32_t columnofs[1]; // only [width] used
};
// Pixel store wrapper that can either own the pixels itself or refer to an external store.
struct PalettedPixels
{
friend class FImageSource;

View file

@ -42,11 +42,13 @@
#include <malloc.h> // for alloca()
#endif
#include "basics.h"
#include "m_crc32.h"
#include "m_swap.h"
#if __has_include("c_cvars.h")
#include "c_cvars.h"
#endif
#include "m_png.h"
#include "basics.h"
// MACROS ------------------------------------------------------------------
@ -103,6 +105,8 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const uint8_
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// allow this to compile without CVARs.
#if __has_include("c_cvars.h")
CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
if (self < 0)
@ -111,6 +115,10 @@ CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
self = 9;
}
CVAR(Float, png_gamma, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
#else
const int png_level = 5;
const float png_gamma = 0;
#endif
// PRIVATE DATA DEFINITIONS ------------------------------------------------

View file

@ -37,7 +37,6 @@
#include "zstring.h"
#include "files.h"
#include "palentry.h"
#include "basics.h"
// Screenshot buffer image data types
enum ESSType

View file

@ -45,7 +45,6 @@
#include "floatrect.h"
#include "refcounted.h"
typedef TMap<int, bool> SpriteHits;
class FImageSource;
class FGameTexture;
class IHardwareTexture;