summaryrefslogtreecommitdiff
path: root/createcalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'createcalls.cpp')
-rw-r--r--createcalls.cpp211
1 files changed, 47 insertions, 164 deletions
diff --git a/createcalls.cpp b/createcalls.cpp
index 1d4e2e5..f8c166e 100644
--- a/createcalls.cpp
+++ b/createcalls.cpp
@@ -83,6 +83,8 @@ project_layer * Layer_Init(project_data *File, memory *Memory)
File->Layer[Index] = (project_layer *)AllocateMemory(Memory, sizeof(project_layer), F_Layers);
project_layer *Layer = File->Layer[Index];
+ *Layer = {};
+ Layer->BitmapInfo.CurrentFrame = -1;
History_Entry_SetPointer(Memory, &Layer->BitmapInfo.AVInfo);
@@ -110,10 +112,13 @@ Cache_CheckBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory,
return 0;
memory_table *Table = &Memory->Slot[B_LoadedBitmaps];
int32 FrameToSeek = TimelineFrame - BitmapInfo->FrameOffset;
- // Stills have a frame index of zero.
- if (FrameToSeek < 0 || Source->SourceType == source_type_image) {
+ if (FrameToSeek < 0) {
FrameToSeek = 0;
- };
+ }
+ // Stills have a frame index of one.
+ if (Source->SourceType == source_type_image) {
+ FrameToSeek = 0;
+ }
for (int i = 0; i < Table->NumberOfPointers; i++) {
cached_bitmap *Bitmap = &Memory->Bitmap[i];
if (Bitmap->Frame == FrameToSeek && Bitmap->SourceOwner == Source) {
@@ -138,145 +143,6 @@ STB_LoadStill(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory)
}
static void
-Mask_RasterizePoints(mask *Mask)
-{
- Mask->NumberOfVerts = 0;
- for (int i = 0; i < Mask->NumberOfPoints; i++) {
- mask_point Point0 = Mask->Point[i];
- mask_point Point1 = Mask->Point[i+1];
- if (i+1 == Mask->NumberOfPoints)
- Point1 = Mask->Point[0];
-
- if (Point0.HandleBezier && Point1.HandleBezier) {
- Bezier_CubicCalcPoints(Point0.Pos, Point0.Pos + Point0.TangentRight, Point1.Pos + Point1.TangentLeft, Point1.Pos,
- Mask->TriangulatedPointCache, &Mask->NumberOfVerts);
- } else if (Point0.HandleBezier) {
- Bezier_CubicCalcPoints(Point0.Pos, Point0.Pos + Point0.TangentRight, Point1.Pos, Point1.Pos,
- Mask->TriangulatedPointCache, &Mask->NumberOfVerts);
- } else if (Point1.HandleBezier) {
- Bezier_CubicCalcPoints(Point0.Pos, Point0.Pos, Point1.Pos + Point1.TangentLeft, Point1.Pos,
- Mask->TriangulatedPointCache, &Mask->NumberOfVerts);
- } else {
- real32 *Data = (real32 *)Mask->TriangulatedPointCache + Mask->NumberOfVerts*3;
- *(Data++) = Point0.Pos.x;
- *(Data++) = Point0.Pos.y;
- *(Data++) = 0;
- // NOTE(fox): CubicCalcPoints sometimes misses generating the start
- // point of the next path in the above two cases, so I'm making
- // straight lines always add both points as a hotfix. This leads
- // to cases of duplicate verts, but it doesn't seem like it harms
- // the rendering in any way.
- *(Data++) = Point1.Pos.x;
- *(Data++) = Point1.Pos.y;
- *(Data++) = 0;
- Mask->NumberOfVerts += 2;
- }
- }
-}
-
-static void
-Mask_TriangulateAndRasterize(memory *Memory, project_layer *Layer, mask *Mask)
-{
- if (!Mask->TriangulatedPointCache) {
- Mask->TriangulatedPointCache = AllocateMemory(Memory, 50*1024, P_VectorPoints);
- }
- Mask_RasterizePoints(Mask);
-
- gl_vertex_shader VertData;
- gl_effect_layer Test = Layer->BitmapInfo.TestM;
- gl_effect_layer Test2 = Layer->BitmapInfo.Test;
-
- uint32 Width = Layer->Source->Info.Width;
- uint32 Height = Layer->Source->Info.Height;
-
- uint8 *Data = (uint8 *)Layer->BitmapInfo.BitmapBuffer;
-
- glBindFramebuffer(GL_FRAMEBUFFER, Test.FramebufferObject);
-
- glEnable(GL_STENCIL_TEST);
- // glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-
- glStencilFunc(GL_ALWAYS, 0, 0xFF); // always write
- glStencilMask(0xff); // allow writing; ANDs any writes to the stencil buffer with this
-
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-
- glUseProgram(DefaultShaderProgram);
-
- int VertexMode = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
- int FragmentMode = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
- glUniform1i(VertexMode, 1);
- glUniform1i(FragmentMode, 0);
-
- // secondary VBO
- glGenVertexArrays(1, &VertData.VertexArrayObject);
- glBindVertexArray(VertData.VertexArrayObject);
- glBindBuffer(GL_ARRAY_BUFFER, VertData.VertexBufferObject);
- glBufferData(GL_ARRAY_BUFFER, Mask->NumberOfVerts*3*sizeof(real32), Mask->TriangulatedPointCache, GL_STREAM_DRAW);
-
- // position attribute
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
-
- int Scale = glGetUniformLocation(DefaultShaderProgram, "CompDimensions");
- glUniform3f(Scale, Width, Height, 0);
-
-
- glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
- glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
-
- glDisable(GL_CULL_FACE);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, Mask->NumberOfVerts);
-
- // glEnable(GL_CULL_FACE);
-
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- glBindVertexArray(0);
-
- // glBindRenderbuffer(GL_RENDERBUFFER, Test.Color_Renderbuffer);
-
- VertexMode = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
- FragmentMode = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
- glUniform1i(VertexMode, 0);
- glUniform1i(FragmentMode, 1);
-
-
- // // Switch to main buffer
- glBindBuffer(GL_ARRAY_BUFFER, DefaultVerts.VertexBufferObject);
- glBufferData(GL_ARRAY_BUFFER, sizeof(DefaultVertices), DefaultVertices, GL_STATIC_DRAW);
- // position attribute
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- // texture coordinate (note the last parameter's offset)
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
- glEnableVertexAttribArray(1);
-
- glStencilFunc(GL_NOTEQUAL, 0, 0xFF);
- glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
- glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, 0);
-
- glDisable(GL_STENCIL_TEST);
- glStencilMask(0xFF);
- glStencilFunc(GL_ALWAYS, 0, 0xFF);
-
- glBindFramebuffer(GL_READ_FRAMEBUFFER, Test.FramebufferObject);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Test2.FramebufferObject);
- glBlitFramebuffer(0, 0, Width, Height, 0, 0, Width, Height,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
- glBindFramebuffer(GL_FRAMEBUFFER, Test2.FramebufferObject);
-
- glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
-
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
-}
-
-static void
Layer_InitSource(project_layer *Layer, source *Source, memory *Memory)
{
uint16 Width = Source->Info.Width;
@@ -320,7 +186,7 @@ Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int
cached_bitmap *Bitmap = Cache_CheckBitmap(Source, BitmapInfo, Memory, CurrentFrame);
if (!Bitmap) {
if (Source->SourceType == source_type_image) {
- Bitmap = AV_LoadVideoFrame(Source, BitmapInfo, Memory, 1);
+ Bitmap = STB_LoadStill(Source, BitmapInfo, Memory);
} else {
Bitmap = AV_LoadVideoFrame(Source, BitmapInfo, Memory, CurrentFrame);
}
@@ -338,8 +204,8 @@ Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int
Bitmap_CopyToPointer(Memory->Scratch, DestBuffer, BytesPerPixel, PackedSize);
} else {
Bitmap_CopyToPointer(Bitmap->Data, DestBuffer, BytesPerPixel, UnpackedSize);
- TestGL_InitTexture(&BitmapInfo->Test, DestBuffer, Width, Height);
- TestGL_MaskTexture(&BitmapInfo->TestM, DestBuffer, Width, Height);
+ // GL_InitTexture(&BitmapInfo->Test, DestBuffer, Width, Height);
+ // GL_MaskTexture(&BitmapInfo->TestM, DestBuffer, Width, Height);
if (Layer->NumberOfMasks) {
for (int i = 0; i < Layer->NumberOfMasks; i++) {
@@ -359,8 +225,8 @@ Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int
}
#else
Bitmap_CopyToPointer(Bitmap->Data, DestBuffer, BytesPerPixel, UnpackedSize);
- TestGL_UpdateTexture(&BitmapInfo->Test, DestBuffer, Width, Height, 0);
- TestGL_UpdateTexture(&BitmapInfo->TestM, DestBuffer, Width, Height, 1);
+ GL_UpdateTexture(&BitmapInfo->Test, DestBuffer, Width, Height, 0);
+ GL_UpdateTexture(&BitmapInfo->TestM, DestBuffer, Width, Height, 1);
if (Layer->NumberOfMasks) {
for (int i = 0; i < Layer->NumberOfMasks; i++) {
@@ -368,6 +234,13 @@ Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int
if (Mask->IsClosed)
Mask_TriangulateAndRasterize(Memory, Layer, Mask);
}
+ Bitmap_StencilAlpha(Bitmap->Data, DestBuffer, BytesPerPixel, UnpackedSize);
+ }
+
+ for (int i = 0; i < Layer->NumberOfEffects; i++)
+ {
+ if (Layer->Effect[i]->IsActive)
+ Layer->Effect[i]->func(Source, BitmapInfo, Memory, Layer->Effect[i]->Property);
}
#endif
}
@@ -406,11 +279,18 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory)
{
void *SourceString = String_GenerateFromChar(Memory, "../asset/24.mp4");
Source_Generate(File, Memory, SourceString);
+ SourceString = String_GenerateFromChar(Memory, "../asset/a.jpg");
+ Source_Generate(File, Memory, SourceString);
+ SourceString = String_GenerateFromChar(Memory, "../asset/b.jpg");
+ Source_Generate(File, Memory, SourceString);
+ SourceString = String_GenerateFromChar(Memory, "../asset/c.jpg");
+ Source_Generate(File, Memory, SourceString);
+ SourceString = String_GenerateFromChar(Memory, "../asset/p.mp4");
+ Source_Generate(File, Memory, SourceString);
- source *Source = &File->Source[0];
- Layer_CreateFromSource(File, State, Memory, Source);
- SelectLayer(File->Layer[0], State, 0);
- property_channel *Property = &File->Layer[0]->x;
+ // Layer_CreateFromSource(File, State, Memory, &File->Source[0]);
+ // SelectLayer(File->Layer[0], State, 0);
+ // property_channel *Property = &File->Layer[0]->x;
// for (int i = 0; i < 16; i++)
// Keyframe_Insert(Property, Memory, i*2, i*2*100);
// Keyframe_Insert(Property, Memory, 1, 100);
@@ -420,10 +300,11 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory)
// History_Undo(Memory);
// History_Redo(Memory);
- Property->IsToggled = true;
+ // Property->IsToggled = true;
// AddEffect(File->Layer[0], Memory, 3);
+ /*
mask *Mask = &File->Layer[0]->Mask[0];
File->Layer[0]->NumberOfMasks = 1;
Mask->Point[0].Pos = V2(200, 200);
@@ -452,6 +333,7 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory)
Mask->NumberOfPoints = 5;
Mask->IsClosed = true;
+ */
// if (!Source_Generate(File, Memory, "../asset/test.png"))
// PostMsg(State, "File open fail...");
@@ -498,26 +380,28 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory)
}
static void
-CreateDemoScene(project_data *File, memory *Memory)
+CreateDemoScene(project_data *File, project_state *State, memory *Memory)
{
-#if 0
- project_layer *Layer1 = CreateSolidLayer(File, Memory, 720, 1280, V4(0.0, 0.0, 0.0, 1.0));
- Layer1->x.CurrentValue.f = 1280/2;
- Layer1->y.CurrentValue.f = 720/2;
+ Layer_CreateFromSource(File, State, Memory, &File->Source[1]);
+ project_layer *Layer1 = File->Layer[0];
+ Layer1->x.CurrentValue.f = 1920/2;
+ Layer1->y.CurrentValue.f = 1080/2;
Layer1->StartFrame = 0;
Layer1->EndFrame = File->EndFrame;
- project_layer *Layer2 = CreateSolidLayer(File, Memory, 499, 503, V4(0.0, 1.0, 0.4, 1.0));
- Layer2->x.CurrentValue.f = 1280/2;
- Layer2->y.CurrentValue.f = 720/2;
+ Layer_CreateFromSource(File, State, Memory, &File->Source[2]);
+ project_layer *Layer2 = File->Layer[1];
+ Layer2->x.CurrentValue.f = 1920/2;
+ Layer2->y.CurrentValue.f = 1080/2;
Layer2->StartFrame = 0;
Layer2->EndFrame = File->EndFrame;
Keyframe_Insert(&Layer2->rotation, Memory, 2, 0);
Keyframe_Insert(&Layer2->rotation, Memory, 50, 360);
Layer2->rotation.IsToggled = true;
Layer2->scale.IsToggled = true;
- project_layer *Layer3 = CreateSolidLayer(File, Memory, 157, 163, V4(1.0, 0.3, 0.2, 1.0));
- Layer3->x.CurrentValue.f = 1280/4;
- Layer3->y.CurrentValue.f = 720/4;
+ Layer_CreateFromSource(File, State, Memory, &File->Source[3]);
+ project_layer *Layer3 = File->Layer[2];
+ Layer3->x.CurrentValue.f = 1920/4;
+ Layer3->y.CurrentValue.f = 1080/4;
Layer3->opacity.CurrentValue.f = 0.5f;
Layer3->StartFrame = 0;
Layer3->EndFrame = File->EndFrame;
@@ -526,7 +410,6 @@ CreateDemoScene(project_data *File, memory *Memory)
Keyframe_Insert(&Layer3->x, Memory, 60, Layer3->x.CurrentValue.f+(1280/3));
Layer3->x.IsToggled = true;
Layer3->y.IsToggled = true;
-#endif
}
#if 0