From c48fcba3d8b632d6f2453b0d2b62bda575186ed9 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 14 Oct 2023 13:01:03 +0200 Subject: [PATCH] CMake: build tinydisplay using CMake Based on work by @toadkarter (#1487) and @pmp-p (#1547) Fixes #1481 --- cmake/install/Panda3DConfig.cmake | 7 +- dtool/Config.cmake | 8 +- panda/CMakeLists.txt | 3 + panda/src/tinydisplay/CMakeLists.txt | 127 ++++++++++++++++++++++++++ panda/src/tinydisplay/srgb_tables.cxx | 2 + panda/src/tinydisplay/srgb_tables.h | 5 + 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 panda/src/tinydisplay/CMakeLists.txt diff --git a/cmake/install/Panda3DConfig.cmake b/cmake/install/Panda3DConfig.cmake index b062bcb175..ad39f864cd 100644 --- a/cmake/install/Panda3DConfig.cmake +++ b/cmake/install/Panda3DConfig.cmake @@ -103,6 +103,11 @@ # Panda3D::OpenGLES2::pandagles2 # # +# TinyDisplay - Support for software rendering. +# +# Panda3D::TinyDisplay::p3tinydisplay +# +# # Vision - Support for vision processing. # # Panda3D::Vision::p3vision @@ -126,7 +131,7 @@ set(_panda_components Bullet ODE FFmpeg OpenAL FMOD - OpenGL DX9 OpenGLES1 OpenGLES2 + OpenGL DX9 OpenGLES1 OpenGLES2 TinyDisplay Vision VRPN ) diff --git a/dtool/Config.cmake b/dtool/Config.cmake index 3d8ca9272f..c1f03e580f 100644 --- a/dtool/Config.cmake +++ b/dtool/Config.cmake @@ -448,10 +448,10 @@ on DirectX rendering." OFF) mark_as_advanced(SUPPORT_FIXED_FUNCTION) # Should build tinydisplay? -#option(HAVE_TINYDISPLAY -# "Builds TinyDisplay, a light software renderer based on TinyGL, -#that is built into Panda. TinyDisplay is not as full-featured as Mesa -#but is many times faster." ON) +option(HAVE_TINYDISPLAY + "Builds TinyDisplay, a light software renderer based on TinyGL, +that is built into Panda. TinyDisplay is not as full-featured as Mesa +but is many times faster." ON) # Is SDL installed, and where? set(Threads_FIND_QUIETLY TRUE) # Fix for builtin FindSDL diff --git a/panda/CMakeLists.txt b/panda/CMakeLists.txt index 72f5628ba2..99a2d65fe4 100644 --- a/panda/CMakeLists.txt +++ b/panda/CMakeLists.txt @@ -60,6 +60,9 @@ add_subdirectory(src/wgldisplay) add_subdirectory(src/windisplay) add_subdirectory(src/x11display) +# Creates a metalib, so should go after +add_subdirectory(src/tinydisplay) + # For other components # bullet add_subdirectory(src/bullet) diff --git a/panda/src/tinydisplay/CMakeLists.txt b/panda/src/tinydisplay/CMakeLists.txt new file mode 100644 index 0000000000..0311a79cce --- /dev/null +++ b/panda/src/tinydisplay/CMakeLists.txt @@ -0,0 +1,127 @@ +if (NOT HAVE_TINYDISPLAY) + return() +endif() + +set(P3TINYDISPLAY_HEADERS + config_tinydisplay.h + tinyGeomMunger.I tinyGeomMunger.h + tinySDLGraphicsPipe.I tinySDLGraphicsPipe.h + tinySDLGraphicsWindow.I tinySDLGraphicsWindow.h + tinyGraphicsBuffer.I tinyGraphicsBuffer.h + tinyGraphicsStateGuardian.I tinyGraphicsStateGuardian.h + tinyTextureContext.I tinyTextureContext.h + tinyWinGraphicsPipe.I tinyWinGraphicsPipe.h + tinyWinGraphicsWindow.I tinyWinGraphicsWindow.h + tinyXGraphicsPipe.I tinyXGraphicsPipe.h + tinyXGraphicsWindow.I tinyXGraphicsWindow.h + tinyOffscreenGraphicsPipe.I tinyOffscreenGraphicsPipe.h + srgb_tables.h + zbuffer.h + zfeatures.h + zgl.h + zline.h + zmath.h + ztriangle.h + ztriangle_two.h + ztriangle_code_1.h + ztriangle_code_2.h + ztriangle_code_3.h + ztriangle_code_4.h + ztriangle_table.h + store_pixel.h + store_pixel_code.h + store_pixel_table.h +) + +set(P3TINYDISPLAY_SOURCES + clip.cxx + config_tinydisplay.cxx + error.cxx + image_util.cxx + init.cxx + td_light.cxx + memory.cxx + specbuf.cxx + store_pixel.cxx + td_texture.cxx + tinyGeomMunger.cxx + tinyGraphicsBuffer.cxx + tinyGraphicsStateGuardian.cxx + tinyOffscreenGraphicsPipe.cxx + tinySDLGraphicsPipe.cxx + tinySDLGraphicsWindow.cxx + tinyTextureContext.cxx + tinyWinGraphicsPipe.cxx + tinyWinGraphicsWindow.cxx + tinyXGraphicsPipe.cxx + tinyXGraphicsWindow.cxx + vertex.cxx + srgb_tables.cxx + zbuffer.cxx + zdither.cxx + zline.cxx + zmath.cxx +) + +set(P3TINYDISPLAY_ZTRIANGLE_SOURCES + ztriangle_1.cxx + ztriangle_2.cxx + ztriangle_3.cxx + ztriangle_4.cxx + ztriangle_table.cxx +) + +set_source_files_properties(${P3TINYDISPLAY_ZTRIANGLE_SOURCES} + PROPERTIES SKIP_UNITY_BUILD_INCLUSION YES) + +if(NOT MSVC) + set_source_files_properties(${P3TINYDISPLAY_ZTRIANGLE_SOURCES} + PROPERTIES COMPILE_FLAGS "-Wno-unused-but-set-variable") +endif() + +if(HAVE_COCOA) + set(P3TINYDISPLAY_HEADERS ${P3TINYDISPLAY_HEADERS} + tinyCocoaGraphicsPipe.I tinyCocoaGraphicsPipe.h + tinyCocoaGraphicsWindow.I tinyCocoaGraphicsWindow.h) + + set(P3TINYDISPLAY_SOURCES ${P3TINYDISPLAY_SOURCES} + tinyCocoaGraphicsPipe.cxx + tinyCocoaGraphicsWindow.mm) + + set_source_files_properties(tinyCocoaGraphicsWindow.mm + PROPERTIES SKIP_UNITY_BUILD_INCLUSION YES) + + add_compile_definitions(HAVE_COCOA) +endif() + +composite_sources(p3tinydisplay P3TINYDISPLAY_SOURCES) + +# Determine the additional components to link in. +set(COCOADISPLAY_LINK_TARGETS) + +if(WIN32) + list(APPEND COCOADISPLAY_LINK_TARGETS p3windisplay) +endif() + +if(HAVE_X11) + list(APPEND COCOADISPLAY_LINK_TARGETS p3x11display) +endif() + +if(HAVE_COCOA) + list(APPEND COCOADISPLAY_LINK_TARGETS p3cocoadisplay) +endif() + +set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "TinyDisplay") +add_metalib(p3tinydisplay ${MODULE_TYPE} + ${P3TINYDISPLAY_HEADERS} ${P3TINYDISPLAY_SOURCES} ${P3TINYDISPLAY_ZTRIANGLE_SOURCES} + COMPONENTS ${COCOADISPLAY_LINK_TARGETS}) +unset(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME) + +set_target_properties(p3tinydisplay PROPERTIES DEFINE_SYMBOL BUILDING_TINYDISPLAY) + +install(TARGETS p3tinydisplay + EXPORT TinyDisplay COMPONENT TinyDisplay + DESTINATION ${MODULE_DESTINATION} + ARCHIVE COMPONENT TinyDisplayDevel) + +export_targets(TinyDisplay NAMESPACE "Panda3D::TinyDisplay::" COMPONENT TinyDisplayDevel) diff --git a/panda/src/tinydisplay/srgb_tables.cxx b/panda/src/tinydisplay/srgb_tables.cxx index b7901d39cd..8192d869d2 100644 --- a/panda/src/tinydisplay/srgb_tables.cxx +++ b/panda/src/tinydisplay/srgb_tables.cxx @@ -1,3 +1,5 @@ +#include "srgb_tables.h" + const unsigned short decode_sRGB[256] = { 0x0000, 0x0013, 0x0027, 0x003b, 0x004f, 0x0063, 0x0077, 0x008b, 0x009f, 0x00b3, 0x00c6, 0x00db, 0x00f0, 0x0107, 0x011f, 0x0139, 0x0153, 0x016f, 0x018c, 0x01aa, 0x01ca, 0x01eb, diff --git a/panda/src/tinydisplay/srgb_tables.h b/panda/src/tinydisplay/srgb_tables.h index 2ff9108aa5..aa0ace53bb 100644 --- a/panda/src/tinydisplay/srgb_tables.h +++ b/panda/src/tinydisplay/srgb_tables.h @@ -1,6 +1,11 @@ +#ifndef SRGB_TABLES_H +#define SRGB_TABLES_H + /* 8-bit sRGB to 16-bit linear */ extern const unsigned short decode_sRGB[256]; /* 12-bit linear to 8-bit sRGB. I used 12-bit because it can represent all possible 8-bit sRGB values. */ extern const unsigned char encode_sRGB[4096]; + +#endif