Skip to content

Commit 73b4173

Browse files
committed
Merge remote-tracking branch 'fork/master' into add_version
2 parents 140fac8 + afa8221 commit 73b4173

22 files changed

Lines changed: 373 additions & 66 deletions

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
[submodule "libs/luautf8"]
1414
path = libs/luautf8
1515
url = https://github.com/starwing/luautf8.git
16+
[submodule "libs/luasocket"]
17+
path = libs/luasocket
18+
url = https://github.com/lunarmodules/luasocket.git
19+
[submodule "dep/compressonator"]
20+
path = dep/compressonator
21+
url = https://github.com/GPUOpen-Tools/compressonator

CMakeLists.txt

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ set(SIMPLEGRAPHIC_SOURCES
5454
"engine/render/r_main.h"
5555
"engine/render/r_texture.cpp"
5656
"engine/render/r_texture.h"
57-
# "engine/system/win/sys_console.cpp"
58-
"engine/system/win/sys_console_unix.cpp"
5957
"engine/system/win/sys_local.h"
6058
"engine/system/win/sys_main.cpp"
6159
"engine/system/win/sys_opengl.cpp"
@@ -86,6 +84,16 @@ if (APPLE)
8684
)
8785
endif()
8886

87+
if (WIN32)
88+
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
89+
"engine/system/win/sys_console.cpp"
90+
)
91+
else()
92+
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
93+
"engine/system/win/sys_console_unix.cpp"
94+
)
95+
endif()
96+
8997
add_library(SimpleGraphic SHARED
9098
${SIMPLEGRAPHIC_SOURCES}
9199
${SIMPLEGRAPHIC_PLATFORM_SOURCES}
@@ -122,6 +130,21 @@ find_package(Threads REQUIRED)
122130
find_package(zstd REQUIRED)
123131
find_package(ZLIB REQUIRED)
124132

133+
add_library(cmp_core STATIC
134+
dep/compressonator/cmp_core/source/cmp_core.cpp
135+
dep/compressonator/cmp_core/source/cmp_core.h
136+
dep/compressonator/cmp_core/shaders/bc3_encode_kernel.cpp
137+
dep/compressonator/cmp_core/shaders/bc7_encode_kernel.cpp
138+
)
139+
140+
target_include_directories(cmp_core PRIVATE
141+
dep/compressonator/applications/_libs/cmp_math
142+
)
143+
144+
target_include_directories(cmp_core PUBLIC
145+
dep/compressonator/cmp_core/shaders
146+
dep/compressonator/cmp_core/source
147+
)
125148

126149
add_library(imgui STATIC
127150
dep/imgui/imconfig.h
@@ -204,6 +227,7 @@ target_link_libraries(SimpleGraphic
204227
PRIVATE
205228
unofficial::angle::libEGL
206229
unofficial::angle::libGLESv2
230+
cmp_core
207231
fmt::fmt
208232
glfw
209233
gli
@@ -293,6 +317,40 @@ target_link_libraries(lua-utf8
293317
install(TARGETS lua-utf8 RUNTIME DESTINATION ".")
294318
install(FILES $<TARGET_RUNTIME_DLLS:lua-utf8> DESTINATION ".")
295319

320+
# luasocket module
321+
322+
add_library(luasocket SHARED
323+
"libs/luasocket/src/auxiliar.c"
324+
"libs/luasocket/src/buffer.c"
325+
"libs/luasocket/src/compat.c"
326+
"libs/luasocket/src/except.c"
327+
"libs/luasocket/src/inet.c"
328+
"libs/luasocket/src/io.c"
329+
"libs/luasocket/src/luasocket.c"
330+
"libs/luasocket/src/options.c"
331+
"libs/luasocket/src/select.c"
332+
"libs/luasocket/src/tcp.c"
333+
"libs/luasocket/src/timeout.c"
334+
"libs/luasocket/src/udp.c"
335+
"libs/luasocket/src/wsocket.c"
336+
)
337+
338+
target_include_directories(luasocket
339+
PRIVATE
340+
${LSOCKET_SOURCE_DIR}/src
341+
)
342+
343+
target_link_libraries(luasocket
344+
PRIVATE
345+
LuaJIT::LuaJIT
346+
wsock32
347+
ws2_32
348+
)
349+
350+
set_target_properties( luasocket PROPERTIES OUTPUT_NAME "socket" )
351+
install(TARGETS luasocket RUNTIME DESTINATION ".")
352+
install(FILES $<TARGET_RUNTIME_DLLS:luasocket> DESTINATION ".")
353+
296354
# lzip module
297355

298356
add_library(lzip SHARED libs/LZip/lzip.cpp)

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define CFG_LOGFILE "SimpleGraphic/SimpleGraphic.log"
1111
#define CFG_DATAPATH "SimpleGraphic/"
1212

13-
#define CFG_SCON_TITLE "SimpleGraphic Console"
13+
#define CFG_SCON_TITLE L"SimpleGraphic Console"
1414
#define CFG_SCON_TEXTCOL 0x00FFFFFF // 255 255 255
1515
#define CFG_SCON_TEXTBG 0x001A3400 // 0 52 26
1616
#define CFG_SCON_WINBG 0x00000000 // 0 0 0

dep/compressonator

Submodule compressonator added at f4b53d7

engine/common/common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,12 @@ IndexedUTF32String IndexUTF8ToUTF32(std::string_view input)
479479
auto p0 = (uint32_t)b[0] & 0b111;
480480
auto p1 = (uint32_t)b[1] & 0b11'1111;
481481
auto p2 = (uint32_t)b[2] & 0b11'1111;
482-
auto p3 = (uint32_t)b[2] & 0b11'1111;
482+
auto p3 = (uint32_t)b[3] & 0b11'1111;
483483
codepoint = p0 << 18 | p1 << 12 | p2 << 6 | p3;
484484
byteIdx += 4;
485485
}
486486
else {
487-
codepoints.push_back(0xFFFDu);
487+
codepoint = 0xFFFDu;
488488
byteIdx += 1;
489489
}
490490
codepoints.push_back(codepoint);

engine/render/r_main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,15 @@ void r_renderer_c::Init(r_featureFlag_e features)
920920
glCompressedTexImage2D = NULL;
921921
}
922922

923+
if (strstr(st_ext, "GL_EXT_texture_compression_bptc")) {
924+
sys->con->Printf("using GL_EXT_texture_compression_bptc\n");
925+
texBC7 = true;
926+
}
927+
else {
928+
sys->con->Printf("GL_EXT_texture_compression_bptc not supported\n");
929+
texBC7 = false;
930+
}
931+
923932
if (strstr(st_ext, "GL_EXT_debug_marker")) {
924933
sys->con->Printf("using GL_EXT_debug_marker\n");
925934
glInsertEventMarkerEXT = (PFNGLINSERTEVENTMARKEREXTPROC)openGL->GetProc("glInsertEventMarkerEXT");

engine/render/r_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
120120

121121
bool texNonPOT = false; // Non power-of-2 textures supported?
122122
dword texMaxDim = 0; // Maximum texture dimension
123+
bool texBC7 = true; // BC7 textures supported?
123124

124125
PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D = nullptr;
125126
PFNGLINSERTEVENTMARKEREXTPROC glInsertEventMarkerEXT = nullptr;

engine/render/r_texture.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <atomic>
1010
#include "r_local.h"
1111

12+
#include "cmp_core.h"
1213
#include "stb_image_resize.h"
1314
#include <gli/gl.hpp>
1415
#include <gli/generate_mipmaps.hpp>
@@ -462,6 +463,93 @@ std::unique_ptr<image_c> r_tex_c::BuildMipSet(std::unique_ptr<image_c> img)
462463
return img;
463464
}
464465

466+
static gli::texture2d_array TranscodeTexture(gli::texture2d_array src, gli::format dstFormat, bool dropFinestMipIfPossible)
467+
{
468+
// Very limited format support, only really sufficient as a fallback when BC7 isn't available.
469+
470+
// Source formats: BC7
471+
const auto srcFormat = src.format();
472+
if (src.format() != gli::FORMAT_RGBA_BP_UNORM_BLOCK16)
473+
return src;
474+
475+
// Destination formats: BC3 or RGBA8
476+
if (dstFormat != gli::FORMAT_RGBA_DXT5_UNORM_BLOCK16 && dstFormat != gli::FORMAT_RGBA8_UNORM_PACK8)
477+
return src;
478+
479+
// To save VRAM and processing costs, there is the option to discard the finest mip level of the source if there's coarser levels available.
480+
// If so, the transcoding will generate destination levels 0..n-1 from levels 1..n of the source.
481+
size_t firstLevel = 0;
482+
if (dropFinestMipIfPossible && src.levels() > 1)
483+
firstLevel = 1;
484+
485+
const auto outExtent = src.extent(firstLevel);
486+
const auto outLayers = src.layers();
487+
const auto outLevels = src.levels() - firstLevel;
488+
489+
gli::texture2d_array dst(dstFormat, outExtent, outLayers, outLevels);
490+
491+
std::array<uint8_t, 64> rgba{};
492+
for (size_t layer = 0; layer < outLayers; ++layer) {
493+
for (size_t dstLevel = 0; dstLevel < outLevels; ++dstLevel) {
494+
auto* dstData = (uint8_t*)dst.data(layer, 0, dstLevel);
495+
const auto dstExtent = dst.extent(dstLevel);
496+
const auto dstRowStride = dstExtent.x * 4;
497+
498+
const size_t srcLevel = dstLevel + firstLevel;
499+
const auto* srcData = (const uint8_t*)src.data(layer, 0, srcLevel);
500+
501+
const auto srcBlockSize = gli::block_extent(srcFormat);
502+
const auto srcBlocksPerRow = (dstExtent.y + srcBlockSize.y - 1) / srcBlockSize.y; // round up partial blocks
503+
const auto srcBlocksPerColumn = (dstExtent.x + srcBlockSize.x - 1) / srcBlockSize.x; // -''-
504+
505+
for (size_t blockRow = 0; blockRow < srcBlocksPerRow; ++blockRow) {
506+
const size_t rowBase = blockRow * srcBlockSize.y;
507+
const size_t rowsLeft = (std::min)(4ull, dstExtent.y - rowBase);
508+
509+
for (size_t blockCol = 0; blockCol < srcBlocksPerColumn; ++blockCol) {
510+
// Read source 4x4 texel block, no branching needed.
511+
DecompressBlockBC7(srcData, rgba.data());
512+
513+
// Recompress or distribute the 4x4 RGBA block.
514+
if (dstFormat == gli::FORMAT_RGBA_DXT5_UNORM_BLOCK16) {
515+
// The block order in the level data for BC3 is the same as for BC7, so we can just append them as they appear.
516+
CompressBlockBC3(rgba.data(), 16, dstData + blockCol * gli::block_size(dstFormat));
517+
518+
// Advance the storage write pointer as we go.
519+
dstData += gli::block_size(dstFormat);
520+
}
521+
else if (dstFormat == gli::FORMAT_RGBA8_UNORM_PACK8) {
522+
// Compressed blocks unconditionally have 4x4 texels each, even if the source extent isn't evenly divisible into blocks with padding on the right and bottom of the block.
523+
// When copying these to RGBA storage which doesn't have this padding we need to ensure we don't go past the edges of the destination.
524+
525+
// Here we work off that dstData points at the top left pixel of the block row in the destination.
526+
const size_t colBase = blockCol * srcBlockSize.x;
527+
const size_t colsLeft = (std::min)(4ull, dstExtent.x - colBase);
528+
const size_t colBytesLeft = colsLeft * 4;
529+
for (size_t innerRow = 0; innerRow < rowsLeft; ++innerRow) {
530+
auto* dstPtr = dstData + dstRowStride * innerRow + colBase * 4;
531+
memcpy(dstPtr, rgba.data() + innerRow * 16, colBytesLeft);
532+
}
533+
// Note that dstData is advanced at the end of the source block row to make copy logic easier to follow.
534+
}
535+
srcData += gli::block_size(srcFormat);
536+
}
537+
538+
// Advance the destination buffer only at the end of an source block row if writing to RGBA output.
539+
if (!gli::is_compressed(dstFormat))
540+
dstData += dstRowStride * rowsLeft;
541+
}
542+
543+
const auto* srcEnd = srcData + src.size(srcLevel);
544+
const auto* dstEnd = dstData + dst.size(dstLevel);
545+
assert(srcData == srcEnd);
546+
assert(dstData == dstEnd);
547+
}
548+
}
549+
550+
return dst;
551+
}
552+
465553
void r_tex_c::LoadFile()
466554
{
467555
if (_stricmp(fileName.c_str(), "@white") == 0) {
@@ -492,6 +580,11 @@ void r_tex_c::LoadFile()
492580
};
493581
error = img->Load(path, sizeCallback);
494582
if ( !error ) {
583+
const bool useTextureFormatFallback = !renderer->texBC7;
584+
if (useTextureFormatFallback) {
585+
if (img->tex.format() == gli::FORMAT_RGBA_BP_UNORM_BLOCK16)
586+
img->tex = TranscodeTexture(img->tex, gli::FORMAT_RGBA8_UNORM_PACK8, true);
587+
}
495588
stackLayers = img->tex.layers();
496589
const bool is_async = !!(flags & TF_ASYNC);
497590
img = BuildMipSet(std::move(img));

engine/system/sys_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class sys_IMain {
6969
int processorCount = 0;
7070
std::filesystem::path basePath;
7171
std::optional<std::filesystem::path> userPath;
72+
std::optional<std::string> userPathReason;
7273

7374
virtual int GetTime() = 0;
7475
virtual void Sleep(int msec) = 0;

engine/system/sys_video.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class sys_IVideo {
4747

4848
virtual int Apply(sys_vidSet_s* set) = 0; // Apply settings
4949

50-
virtual void SetActive(bool active) = 0; // Respond to window activated status change
5150
virtual void SetForeground() = 0; // Activate the window if shown
5251
virtual bool IsActive() = 0; // Get activated status
5352
virtual void FramebufferSizeChanged(int width, int height) = 0; // Respond to framebuffer size change

0 commit comments

Comments
 (0)