10 Commits

19 changed files with 103 additions and 55 deletions

View File

@ -9,7 +9,7 @@ on:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
EM_VERSION: 2.0.24
EM_VERSION: 3.1.32
EM_CACHE_FOLDER: 'emsdk-cache'
jobs:

View File

@ -2,43 +2,31 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(imgui C CXX)
set(CPP_FILES
add_library(imgui
"imgui/imgui.h"
"imgui/imgui.cpp"
"imgui/imgui_draw.cpp"
"imgui/imgui_widgets.cpp"
"imgui/imgui_tables.cpp"
"imgui/imgui_demo.cpp"
"imgui/misc/cpp/imgui_stdlib.cpp"
"imgui_plot_var.cpp"
#"imgui_impl_sdl_gl3.cpp" # very old
#"imgui_impl_sdl.cpp" # old
#"imgui_impl_opengl3.cpp" # old
"imgui/backends/imgui_impl_sdl.cpp"
"imgui/backends/imgui_impl_opengl3.cpp"
)
set(HPP_FILES
"imgui/imgui.h"
"imgui/imstb_rectpack.h"
"imgui/imstb_textedit.h"
"imgui/imstb_truetype.h"
"imgui/misc/cpp/imgui_stdlib.h"
"imgui/misc/cpp/imgui_stdlib.cpp"
"imgui_plot_var.hpp"
"imgui_plot_var.cpp"
#"imgui_impl_sdl_gl3.h" # very old
#"imgui_impl_sdl.h" # old
#"imgui_impl_opengl3.h" # old
"imgui/backends/imgui_impl_sdl.h"
# TODO: seperate backends into libs
"imgui/backends/imgui_impl_sdl2.h"
"imgui/backends/imgui_impl_sdl2.cpp"
"imgui/backends/imgui_impl_opengl3.h"
"imgui/backends/imgui_impl_opengl3.cpp"
)
add_library(imgui ${CPP_FILES} ${HPP_FILES})
target_compile_features(imgui PUBLIC cxx_std_11)
if(MM_OPENGL_3_GLES)

View File

@ -11,9 +11,8 @@ target_link_libraries(stb_image stb)
add_library(stb_image_write "stb/stb_image_write.h" "stb_image_write.cpp")
target_link_libraries(stb_image_write stb)
# lel TODO: add back in when patent expires
#add_library(stb_perlin "stb/stb_perlin.h" "stb_perlin.cpp")
#target_link_libraries(stb_perlin stb)
add_library(stb_perlin "stb/stb_perlin.h" "stb_perlin.cpp")
target_link_libraries(stb_perlin stb)
add_library(stb_rect_pack "stb/stb_rect_pack.h" "stb_rect_pack.cpp")
target_link_libraries(stb_rect_pack stb)

View File

@ -10,6 +10,8 @@ if(NOT EMSCRIPTEN)
"${CMAKE_CURRENT_LIST_DIR}/tracy/public/TracyClient.cpp"
)
option(TRACY_ENABLE "Enable tracy profiling" OFF)
if(TRACY_ENABLE)
target_compile_definitions(tracy_client PUBLIC TRACY_ENABLE)
#target_compile_definitions(tracy_client PUBLIC TRACY_NO_SYSTEM_TRACING)

View File

@ -50,11 +50,11 @@ namespace MM::Services {
public: // send/recv
// sends a packet of max getMaxPacketSize() bytes
virtual bool sendPacket(peer_id peer, channel_id channel, uint8_t* data, size_t data_size) = 0;
virtual bool sendPacket(peer_id peer, channel_id channel, const uint8_t* data, size_t data_size) = 0;
// sends a packet, automatically split if too big
// !! only on lossless channels
virtual bool sendPacketLarge(peer_id peer, channel_id channel, uint8_t* data, size_t data_size) = 0;
virtual bool sendPacketLarge(peer_id peer, channel_id channel, const uint8_t* data, size_t data_size) = 0;
// TODO: broadcast?
// has any?

View File

@ -1,7 +1,7 @@
#include "./imgui_s.hpp"
#include <imgui/imgui.h>
#include <imgui/backends/imgui_impl_sdl.h>
#include <imgui/backends/imgui_impl_sdl2.h>
#ifdef MM_OPENGL_3
#include <imgui/backends/imgui_impl_opengl3.h>

View File

@ -97,6 +97,7 @@ Texture::handle_t Texture::createEmptyMultiSampled(int32_t internalFormat, int32
(void)height;
(void)samples;
assert(false && "GLES has no multisampling support");
return nullptr;
#endif
}

View File

@ -29,14 +29,20 @@ void setup_bloom(
const auto bloom_internal_format = GL_RGB565; // prolly fine. NOPE its not. it causes green pixely halos
const auto bloom_format_type = GL_UNSIGNED_BYTE;
#else
//const auto bloom_internal_format = GL_RGBA16F;
const auto bloom_internal_format = GL_R11F_G11F_B10F;
const auto bloom_format_type = GL_FLOAT;
const auto bloom_format_type = GL_RGBA;
const auto bloom_internal_format = GL_RGBA16F;
//const auto bloom_internal_format = GL_R11F_G11F_B10F;
const auto bloom_data_type = GL_FLOAT;
//const auto bloom_format_type = GL_RGBA_INTEGER;
//const auto bloom_internal_format = GL_RGBA16I;
//const auto bloom_data_type = GL_SHORT;
#endif
#else
//const auto bloom_internal_format = GL_RGB16F;
const auto bloom_internal_format = GL_R11F_G11F_B10F;
const auto bloom_format_type = GL_FLOAT;
const auto bloom_format_type = GL_RGB;
const auto bloom_internal_format = GL_RGB16F; // opengl silently upgrades to RGBA
//const auto bloom_internal_format = GL_R11F_G11F_B10F; // no sign
const auto bloom_data_type = GL_FLOAT;
#endif
{ // bloom in (bloom extraction)
@ -44,7 +50,7 @@ void setup_bloom(
"bloom_in",
bloom_internal_format,
w * bloom_in_scale, h * bloom_in_scale,
GL_RGB, bloom_format_type
bloom_format_type, bloom_data_type
);
{ // filter
rm_t.get("bloom_in"_hs)->bind(0);
@ -72,7 +78,7 @@ void setup_bloom(
tex_out_id,
bloom_internal_format,
w * bloom_in_scale * glm::pow(bloom_phase_scale, i), h * bloom_in_scale * glm::pow(bloom_phase_scale, i),
GL_RGB, bloom_format_type
bloom_format_type, bloom_data_type
);
{ // filter
rm_t.get(tex_out_id)->bind(0);
@ -89,7 +95,7 @@ void setup_bloom(
tex_tmp_id,
bloom_internal_format,
w * bloom_in_scale * glm::pow(bloom_phase_scale, i), h * bloom_in_scale * glm::pow(bloom_phase_scale, i),
GL_RGB, bloom_format_type
bloom_format_type, bloom_data_type
);
{ // filter
rm_t.get(tex_tmp_id)->bind(0);

View File

@ -106,7 +106,15 @@ void main() {
vec3 color = texture(color_tex, _uv).rgb;
// TODO: expose threshold
_out_color = max(vec3(0.0), color - vec3(1.0));
//_out_color = max(vec3(0.0), color - vec3(1.0));
//_out_color = mix(
//color, // < 0.0
//max(vec3(0.0), color - vec3(1.0)), // > 0.0
//step(vec3(0.0), color)
//);
_out_color = max(min(color, vec3(0.0)), color - vec3(1.0));
})")
}

View File

@ -141,7 +141,7 @@ void main() {
vec3 color = texture(color_tex, _uv).rgb;
vec3 bloom = texture(bloom_tex, _uv).rgb;
vec3 comp = color + bloom * vec3(bloom_factor);
vec3 comp = max(vec3(0.0), color + bloom * vec3(bloom_factor));
#if 0
const vec3 tint = vec3(1.5, 0.8, 1.1);

View File

@ -129,8 +129,9 @@ static void setup_fbos(MM::Engine& engine) {
assert(rs.targets["game_view"]);
}
static MM::Engine engine;
TEST(hdr_bloom_pipeline, it) {
MM::Engine engine;
auto& sdl_ss = engine.addService<MM::Services::SDLService>();
ASSERT_TRUE(engine.enableService<MM::Services::SDLService>());
@ -228,7 +229,7 @@ TEST(hdr_bloom_pipeline, it) {
col.color = {3.f, 3.f, 3.f, 1.f};
}
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 5; i++) {
auto e = scene.create();
auto& p = scene.emplace<MM::Components::Position2D>(e);
p.pos.x = i * 9.f - 40;
@ -247,7 +248,43 @@ TEST(hdr_bloom_pipeline, it) {
col.color = {rng.zeroToOne()*2.f, rng.zeroToOne()*2.f, rng.zeroToOne()*2.f, 1.f};
}
for (int i = 5; i < 10; i++) {
auto e = scene.create();
auto& p = scene.emplace<MM::Components::Position2D>(e);
p.pos.x = i * 9.f - 40;
// zoffset is created by event
auto& s = scene.emplace<MM::Components::Scale2D>(e);
s.scale = {5,5};
scene.emplace<MM::Components::Rotation2D>(e);
auto& v = scene.emplace<MM::Components::Velocity2DRotation>(e);
v.rot_vel = i * 0.3f;
auto& col = scene.emplace<MM::Components::Color>(e);
col.color = {rng.zeroToOne()*-2.f, rng.zeroToOne()*-2.f, rng.zeroToOne()*-2.f, 1.f};
}
{ // white background for negatives
auto e = scene.create();
auto& p = scene.emplace<MM::Components::Position2D>(e);
p.pos.y = 30.f;
p.pos.x = 25.f;
auto& s = scene.emplace<MM::Components::Scale2D>(e);
s.scale = {50,150};
auto& col = scene.emplace<MM::Components::Color>(e);
col.color = {1.f, 1.f, 1.f, 1.f};
}
engine.run();
#ifndef __EMSCRIPTEN__
engine.cleanup();
#endif
}
int main(int argc, char** argv) {

View File

@ -7,7 +7,7 @@ namespace MM::Random {
// Seeded (Pseudo-) Random Number Generator
struct SRNG {
// make shuffle compat
// make shuffle compat
// TODO: add more type info
using result_type = uint32_t;
@ -35,7 +35,7 @@ struct SRNG {
}
bool roll(float prob) {
return zeroToOne() <= prob;
return zeroToOne() <= prob; // TODO: just < ?
}
// more advanced

View File

@ -194,10 +194,6 @@ struct StreamWriter {
}
[[nodiscard]] size_t bytesWritten(void) noexcept {
// TODO: is this assert valid?
assert(_scratch_bits == 0);
//return _bits_written/8 + ((_bits_written % 8) ? 1 : 0);
return (_bits_written+7) / 8;
}

View File

@ -391,7 +391,7 @@ struct TestStruct {
double f64 {0.};
// float compressed [0; 1] range
constexpr static float c0_f32_resolution = 0.001;
constexpr static float c0_f32_resolution = 0.001f;
constexpr static MM::ScalarRange2<float> c0_f32_r{0.f, 1.f};
float c0_f32_0 {0.f};
float c0_f32_1 {0.f};
@ -399,7 +399,7 @@ struct TestStruct {
float c0_f32_3 {0.f};
// float compressed [-1; 1] range
constexpr static float c1_f32_resolution = 0.05;
constexpr static float c1_f32_resolution = 0.05f;
constexpr static MM::ScalarRange2<float> c1_f32_r{-1.f, 1.f};
float c1_f32_0 {0.f};
float c1_f32_1 {0.f};
@ -407,7 +407,7 @@ struct TestStruct {
float c1_f32_3 {0.f};
// float compressed [-1000; 1000] range
constexpr static float c2_f32_resolution = 0.01;
constexpr static float c2_f32_resolution = 0.01f;
constexpr static MM::ScalarRange2<float> c2_f32_r{-1000.f, 1000.f};
float c2_f32_0 {0.f};
float c2_f32_1 {0.f};

View File

@ -31,9 +31,10 @@ namespace MM::Services {
SDLService::SDLService(uint32_t _sdl_init_flags) {
MM::Logger::initSectionLogger("SDLService");
//#ifdef __EMSCRIPTEN__
//_sdl_init_flags &= ~SDL_INIT_HAPTIC;
//#endif
#ifdef __EMSCRIPTEN__
_sdl_init_flags &= ~SDL_INIT_HAPTIC;
#endif
#if 1 // hack for mingw + wine
_sdl_init_flags &= ~SDL_INIT_SENSOR;
#endif

View File

@ -60,6 +60,16 @@ struct ScalarRange2 {
[[nodiscard]] constexpr bool inRange(T&& value) const {
return value >= min() && value <= max();
}
// lerp between min and max
[[nodiscard]] constexpr T map(const float a) const {
return min() * (1.f-a) + max() * a;
}
// reverse map
[[nodiscard]] constexpr float unmap(const T& v) const {
return (v - min()) / static_cast<float>(max() - min());
}
};
} // MM