summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp166
1 files changed, 68 insertions, 98 deletions
diff --git a/main.cpp b/main.cpp
index 9db6588..d0349fa 100644
--- a/main.cpp
+++ b/main.cpp
@@ -41,38 +41,40 @@
#include "main.h"
#include "debug.h"
-// #include "functions.h"
+#include "functions.h"
// #include "sharebuffer.h"
-SDL_atomic_t CurrentEntry;
-SDL_atomic_t QueuedEntries;
-SDL_atomic_t CompletedEntries;
+SDL_atomic_t Render_Interrupt;
+// SDL_atomic_t CurrentEntry;
+// SDL_atomic_t QueuedEntries;
+// SDL_atomic_t CompletedEntries;
static bool32 IsRendering = false;
static instruction_mode InstructionMode = instruction_mode_scalar;
static uint32 RandomGlobalIncrement = 0;
// render_entry Entries[256];
-SDL_Thread *thread[8];
+// SDL_Thread *thread[8];
+SDL_Thread *MainRenderThread;
SDL_sem *Semaphore;
#include "memory.cpp"
+#include "undo.cpp"
#include "strings.cpp"
+#if THREADED
+#include "threading.cpp"
+#endif
#include "createcalls.cpp"
#include "ffmpeg_backend.cpp"
+#include "my_imgui_widgets.cpp"
+#include "gl_calls.cpp"
#if 0
#include "effects.cpp"
#include "keyframes.cpp"
#include "layer.cpp"
#include "bezier.cpp"
-#if THREADED
-#include "threading.cpp"
-#endif
#include "prenderer.cpp"
#include "bitmap_calls.cpp"
-#include "my_imgui_widgets.cpp"
-#include "gl_calls.cpp"
-#include "undo.cpp"
#endif
@@ -129,16 +131,17 @@ int main(int argc, char *argv[]) {
Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, P_AVInfo, "Image/video headers");
Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, P_UndoBuffer, "Undo buffer");
- Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, P_MiscCache, "Misc persistent");
+ Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, P_MiscCache, "Misc persistent");
Memory_InitTable(&GlobalMemory, &Memory, sizeof(project_data), F_File, "File", sizeof(project_data));
Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Precomps, "Precomps", sizeof(block_composition));
- // Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Layers, "Layers");
- Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Sources, "Sources", sizeof(block_source));
+ Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Layers, "Layers", sizeof(block_layer));
+ Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Sources, "Sources", sizeof(block_source));
// Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Effects, "Effects");
// Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Keyframes, "Keyframe blocks");
- Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Strings, "Strings");
+ Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Strings, "Strings", sizeof(block_string));
+ Memory_InitTable(&GlobalMemory, &Memory, (uint64)64 * 1024 * 1024, B_ScratchSpace, "Scratch");
// Memory_InitTable(&GlobalMemory, &Memory, (uint64)200 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer");
#if ARM
@@ -153,7 +156,10 @@ int main(int argc, char *argv[]) {
#endif
project_state *State = (project_state *)Memory.Slot[P_MiscCache].Address;
+ *State = {};
project_data *File = (project_data *)Memory_Block_AllocateAddress(&Memory, F_File);
+ *File = {};
+ File->Occupied = 1;
block_composition *MainComp = (block_composition *)Memory_Block_AllocateAddress(&Memory, F_Precomps);
MainComp->Width = 1280;
@@ -164,68 +170,22 @@ int main(int argc, char *argv[]) {
MainComp->Frame_Count = 48;
MainComp->Frame_End = 48;
- Source_Generate(File, State, Memory, "../asset/a.jpg");
-
-#if 0
-
-#if DEBUG
-
- LoadTestFootage(&File, &State, &Memory);
-
- // 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_info BS = {};
- BS.PreviousPTS = 0;
- effect as = {};
-#endif
-
- 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);
-
- ui UI = {};
-
- UI.Y_TimelinePercentZoomed = UI.Default_Y_TimelinePercentZoomed;
- UI.Y_TimelinePercentOffset = UI.Default_Y_TimelinePercentOffset;
-
- // shm_unlink("/testl");
- // int fd = shm_open("/testl", O_CREAT | O_EXCL | O_RDWR,
- // S_IRUSR | S_IWUSR);
- // if (fd == -1)
- // errExit("shm_open");
-
- // if (ftruncate(fd, SHAREDMEMORY_SIZE) == -1)
- // Assert(0);
+ {
+ uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/a.jpg");
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 0);
- // void *asda = mmap(NULL, SHAREDMEMORY_SIZE,
- // PROT_READ | PROT_WRITE,
- // MAP_SHARED, fd, 0);
- // SharedMemoryInfo *shmp = (SharedMemoryInfo *)asda;
+ Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End);
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, 0);
- // if (shmp == MAP_FAILED)
- // Assert(0);
+ History_Undo(&Memory);
+ History_Redo(&Memory);
+ }
- // if (sem_init(&shmp->sem1, 1, 0) == -1)
- // Assert(0);
- // if (sem_init(&shmp->sem2, 1, 0) == -1)
- // Assert(0);
+ State->Render.MainCompBuffer = (void *)((uint8 *)Memory.Slot[P_MiscCache].Address + sizeof(project_state));
SDL_Init(SDL_INIT_VIDEO);
- Semaphore = SDL_CreateSemaphore(0);
-
- render_queue RenderInfo = {};
- RenderInfo.File = &File;
- RenderInfo.State = &State;
- RenderInfo.CompBuffer = &CompBuffer;
-
+#if 0
#if THREADED
thread_info ThreadInfo[7];
@@ -236,8 +196,7 @@ int main(int argc, char *argv[]) {
thread[i] = SDL_CreateThread(TestThread, str, &ThreadInfo[i]);
}
#endif
- sdl_input Input;
- sdl_input OldInput;
+#endif
// Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2)
@@ -322,22 +281,24 @@ int main(int argc, char *argv[]) {
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL3_Init(glsl_version);
+ int64 i = 0;
+ while (i < MainComp->Width*MainComp->Height) {
+ *((uint32 *)State->Render.MainCompBuffer + i++) = 0xFF2F0000;
+ }
+
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is required on WebGL for non power-of-two textures
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
-#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.PackedBuffer);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, MainComp->Width, MainComp->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, State->Render.MainCompBuffer);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
+ // Semaphore = SDL_CreateSemaphore(0);
+ // MainRenderThread = SDL_CreateThread(MainRenderer, "Main render thread", &State->Render);
- while (State.IsRunning)
+ while (State->IsRunning)
{
SDL_Event event;
while (SDL_PollEvent(&event))
@@ -345,19 +306,19 @@ int main(int argc, char *argv[]) {
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_DROPFILE) {
char *DropFile = event.drop.file;
- Source_Generate(&File, &State, &Memory, DropFile);
+ Source_Generate(File, State, &Memory, DropFile);
SDL_free(DropFile);
}
if (event.type == SDL_QUIT)
- State.IsRunning = false;
+ State->IsRunning = false;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
- State.IsRunning = false;
+ State->IsRunning = false;
}
- if (UI.WantSetPos) {
- ImGui::GetIO().WantSetMousePos = true;
- io.MousePos = UI.SetPos;
- }
+ // if (UI.WantSetPos) {
+ // ImGui::GetIO().WantSetMousePos = true;
+ // io.MousePos = UI.SetPos;
+ // }
ImGui_ImplOpenGL3_NewFrame();
@@ -365,17 +326,18 @@ int main(int argc, char *argv[]) {
ImGui::NewFrame();
- if (UI.WantSetPos) {
- ImGui_WrapMouseFinish(&UI, io.MousePos);
- io.MouseDelta = {};
- UI.WantSetPos = false;
- }
+ // if (UI.WantSetPos) {
+ // ImGui_WrapMouseFinish(&UI, io.MousePos);
+ // io.MouseDelta = {};
+ // UI.WantSetPos = false;
+ // }
+
+ ImGui::DockSpaceOverViewport();
+#if 0
if (!io.WantCaptureKeyboard)
ImGui_ProcessInputs(&File, &State, &CompBuffer, &Memory, &UI, io);
- ImGui::DockSpaceOverViewport();
-
ImGui_Viewport(File, &State, &UI, &Memory, CompBuffer, io, textureID);
ImGui_File(&File, &State, &Memory, &UI, io);
@@ -386,7 +348,12 @@ int main(int argc, char *argv[]) {
ImGui_Timeline(&File, &State, &Memory, &UI, io);
// ImGui_Graph(&File, &State, &Memory, &UI, io);
+#endif
+ ImGui_Viewport(MainComp, textureID);
+ ImGui::ShowDemoWindow();
+
+#if 0
#if DEBUG
ImGui_DebugUndoTree(&File, &Memory);
if (Debug.ToggleWindow) {
@@ -410,7 +377,9 @@ int main(int argc, char *argv[]) {
// Right now IsRendering does nothing. I have it here if we want to
// completely detatch the rendering updater onto its own thread so the
// UI never lags.
+#endif
+#if 0
if (State.UpdateFrame && !IsRendering) {
MainFunction(0, &Memory, &State, &File, &CompBuffer);
State.UpdateFrame = 0;
@@ -433,6 +402,7 @@ int main(int argc, char *argv[]) {
FinishRenderAndUpload(&State, &CompBuffer, textureID);
}
#endif
+#endif
ImGui::Render();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
@@ -441,15 +411,15 @@ int main(int argc, char *argv[]) {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
}
- for (int i = 0; i < 7; i++) {
- SDL_DetachThread(thread[i]);
- }
+
+ // for (int i = 0; i < 7; i++) {
+ // SDL_DetachThread(thread[i]);
+ // }
// shm_unlink("/testl");
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_Quit();
-#endif
return 0;
}