From b26f27d9e3fd44ec5775accdc3666a339684be4c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Mon, 1 Aug 2022 20:03:12 -0400 Subject: large changes to bitmap structure --- main.cpp | 158 ++++++++++++++++++++------------------------------------------- 1 file changed, 50 insertions(+), 108 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index a575ef4..c6e129b 100644 --- a/main.cpp +++ b/main.cpp @@ -29,14 +29,6 @@ #define STBI_FAILURE_USERMSG #include "lib/stb_image.h" -extern "C" { -#include -#include -#include -#include -#include -} - #if 0 #include #else @@ -44,60 +36,18 @@ extern "C" { #define IACA_END #endif -#define internal static -#define local_persist static -#define global_variable static - -#define SwitchBool(Bool) if((Bool)) {(Bool) = 0;} else {(Bool) = 1;} -#define AmountOf(Array) sizeof((Array)) / sizeof((Array)[1]) - -typedef int8_t int8; -typedef int16_t int16; -typedef int32_t int32; - -typedef int64_t int64; -typedef int32 bool32; - -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uint64_t uint64; - -typedef float real32; -typedef double real64; - -#define NORMALIZED_COL_MIN { .col = V4(0.0f, 0.0f, 0.0f, 0.0f) } -#define NORMALIZED_COL_MAX { .col = V4(1.0f, 1.0f, 1.0f, 1.0f) } -#define NORMALIZED_REAL_MIN { 0.0f } -#define NORMALIZED_REAL_MAX { 1.0f } - - -// All of these MIN/MAX values are arbitrarily chosen; they can probably be -// increased if the user requires it. - -#define PROPERTY_REAL_MAX 1000000 -#define PROPERTY_REAL_MIN -1000000 - -#define MAX_LAYERS 2048 -#define MAX_EFFECTS 32 -#define MAX_SOURCES 1024 -#define MAX_PROPERTIES_PER_EFFECT 16 -#define MAX_KEYFRAME_BLOCKS 64 -#define MAX_KEYFRAMES_PER_BLOCK 32 -#define STRING_SIZE 256 - -#define MAX_SELECTED_PROPERTIES 16 - +#include "defines.h" #include "my_math.h" #include "main.h" #include "debug.h" +#include "functions.h" +// #include "sharebuffer.h" SDL_atomic_t CurrentEntry; SDL_atomic_t QueuedEntries; SDL_atomic_t CompletedEntries; -global_variable bool32 IsRendering = false; -global_variable instruction_mode InstructionMode = scalar_only; - +static bool32 IsRendering = false; +static instruction_mode InstructionMode = instruction_mode_scalar; render_entry Entries[256]; @@ -105,7 +55,7 @@ SDL_Thread *thread[8]; SDL_sem *Semaphore; #include "memory.cpp" -#include "effects.cpp" +// #include "effects.cpp" #include "keyframes.cpp" #include "layer.cpp" #include "strings.cpp" @@ -114,59 +64,39 @@ SDL_sem *Semaphore; #else #endif #include "prenderer.cpp" -#include "video.cpp" +#include "ffmpeg_backend.cpp" #include "bitmap_calls.cpp" #include "createcalls.cpp" #include "my_imgui_widgets.cpp" -// #include "sharebuffer.h" - -internal void +static void MainFunction(main_sdl *Main, memory *Memory, project_state *State, project_data *File, - cache_pool *Cache, pixel_buffer *CompBuffer) + cache_pool *Cache, comp_buffer *CompBuffer) { - ClearBuffer(CompBuffer, CompBuffer->OriginalBuffer); - ClearBuffer(CompBuffer, CompBuffer->EffectBuffer); + Bitmap_Clear(CompBuffer->PackedBuffer, CompBuffer->Width, CompBuffer->Height, CompBuffer->BytesPerPixel); + Bitmap_Clear(CompBuffer->UnpackedBuffer, CompBuffer->Width, CompBuffer->Height, CompBuffer->BytesPerPixel); for (int i = 0; i < File->NumberOfLayers; i++) { project_layer *Layer = File->Layer[i]; - if (Layer->RenderInfo) { - // Keyframe updating - if (State->UpdateKeyframes) { - for (int p = 0; p < Layer->NumberOfEffects; p++) { - for (int o = 0; o < Layer->Effect[p]->NumberOfProperties; o++) { - CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Effect[p]->Property[o]); - } - } - for (int r = 0; r < AmountOf(Layer->Property); r++) { - CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Property[r]); - } - } - - // Video updating - if (Layer->SourceType == source_video) { // && Layer->VideoCurrentFrame != File->CurrentFrame - Layer->VideoFrameOffset) { - video_source *Source = (video_source *)Layer->RenderInfo; - LoadVideoFrame(Source, Memory, File->CurrentFrame); // TODO(fox): Make above check work! - UpdateEffects(Layer, Memory); - Source->Raster.ToUpdate = true; + if (State->UpdateKeyframes) { + for (int p = 0; p < Layer->NumberOfEffects; p++) { + for (int o = 0; o < Layer->Effect[p]->NumberOfProperties; o++) { + CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Effect[p]->Property[o]); + } } - - // Effect updating - if (Layer->SourceType == source_image) { - image_source *Source = (image_source *)Layer->RenderInfo; - if (Source->Raster.ToUpdate) { - UpdateEffects(Layer, Memory); - Source->Raster.ToUpdate = false; - } + for (int r = 0; r < AmountOf(Layer->Property); r++) { + CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Property[r]); } } + + Layer_UpdateBitmap(Layer->Source, &Layer->BitmapInfo, Memory, File->CurrentFrame); } State->UpdateKeyframes = false; QueueCurrentFrame(File, CompBuffer, State); } #if 0 -internal void +static void MainFunction(main_sdl *Main, project_debug *D, memory *Memory, sdl_input *Input, sdl_input *OldInput, project_state *State, brush_tool *Brush, project_data *File, cache_pool *Cache, pixel_buffer *CompBuffer) @@ -255,7 +185,7 @@ MainFunction(main_sdl *Main, project_debug *D, memory *Memory, sdl_input *Input, #endif -internal void +static void DebugPrintMemoryUsage(memory Memory) { for (int i = 0; i < 8; i++) { @@ -269,7 +199,7 @@ int main(int argc, char *argv[]) { global_memory GlobalMemory = {}; - GlobalMemory.Size = ((uint64)2 * 1024 * 1024 * 1024); + GlobalMemory.Size = ((uint64)4 * 1024 * 1024 * 1024); GlobalMemory.CurrentPosition = 0; #if WINDOWS @@ -287,42 +217,53 @@ int main(int argc, char *argv[]) { InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, P_UIState, "UI state"); // TODO(fox): Make clean-up functions when these get deleted! - InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, P_SourceData, "Image/video headers"); + InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, P_AVInfo, "Image/video headers"); InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_ProjectSettings, "Project settings"); InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Layers, "Layers"); InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Effects, "Effects"); InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Keyframes, "Keyframe blocks"); InitMemoryTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Strings, "Strings"); - InitMemoryTable(&GlobalMemory, &Memory, (uint64)2 * 1024 * 1024 * 1024, B_Scratch, "Scratch buffer"); + InitMemoryTable(&GlobalMemory, &Memory, (uint64)16 * 1024 * 1024, B_LayerBitmaps, "Layer buffer"); + InitMemoryTable(&GlobalMemory, &Memory, (uint64)1 * 1024 * 1024 * 1024, B_LoadedBitmaps, "Loaded bitmap buffer"); project_state State = {}; if (SDL_HasSSE2()) { - InstructionMode = sse_enabled; + InstructionMode = instruction_mode_sse; } if (SDL_HasAVX2()) { - InstructionMode = avx_enabled; + InstructionMode = instruction_mode_avx; } project_data File = {}; File.Width = 1280; File.Height = 720; - // File.Width = 1923; - // File.Height = 1083; File.NumberOfFrames = 65; File.FPS = 30; File.CurrentFrame = 1; File.StartFrame = 0; File.EndFrame = 65; - // CreateLayerFromSource(&File, &State, &Memory, "../asset/b.jpg"); - // char String[1024]; - // uint16 Size = 1024; - // getcwd(String, Size); - // printf("dir: %s", String); +#if DEBUG + // GDB and LLDB say this plain struct that's literally under 30 bytes is + // incomplete in the layers unless I do this... + layer_bitmap_info BitmapInfo; + BitmapInfo.ToUpdate = 0; + BitmapInfo.FrameOffset = 2; + av_packet_info BS = {}; + BS.PreviousPTS = 0; +#endif + + LoadTestFootage(&File, &State, &Memory); - pixel_buffer CompBuffer = CreateBuffer(File.Width, File.Height, &Memory); + uint16 BytesPerPixel = 4; + comp_buffer CompBuffer = {}; + CompBuffer.Width = File.Width; + CompBuffer.Height = File.Height; + CompBuffer.BytesPerPixel = BytesPerPixel; + CompBuffer.PackedBuffer = Layer_AllocateBitmap(&Memory, CompBuffer.Width, CompBuffer.Height, CompBuffer.BytesPerPixel); + CompBuffer.UnpackedBuffer = Layer_AllocateBitmap(&Memory, CompBuffer.Width, CompBuffer.Height, CompBuffer.BytesPerPixel); cache_pool Cache = {}; Cache.Interact = Inactive; @@ -451,7 +392,7 @@ int main(int argc, char *argv[]) { #if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__) glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); #endif - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CompBuffer.Width, CompBuffer.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, CompBuffer.OriginalBuffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CompBuffer.Width, CompBuffer.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, CompBuffer.PackedBuffer); ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -525,11 +466,12 @@ int main(int argc, char *argv[]) { } C = SDL_AtomicGet(&CompletedEntries); if (C == 16) { - Convert4x4Chunk(&CompBuffer, 1); + Bitmap_ConvertPacking(CompBuffer.PackedBuffer, CompBuffer.UnpackedBuffer, + CompBuffer.Width, CompBuffer.Height, CompBuffer.BytesPerPixel, 1); EndRenderState(&State); glBindTexture(GL_TEXTURE_2D, textureID); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, CompBuffer.Width, CompBuffer.Height, GL_RGBA, GL_UNSIGNED_BYTE, - CompBuffer.EffectBuffer); + CompBuffer.UnpackedBuffer); // shmp->shared_framenumber = File.CurrentFrame; // if (sem_post(&shmp->sem2) == -1) -- cgit v1.2.3