summaryrefslogtreecommitdiff
path: root/src/effects_constructors.cpp
blob: 4b87036e9672d2c335afc2b3fcf693615614a363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#if SPECIAL
#include "main.h"
#endif

static void
Effect_AddEntry(project_state *State, char *Name, char *ID, void (*func)(real32 *, int, int, int, void *, uint16), const char *GL_Shader, effect_display_type DisplayType = effect_display_type_standard)
{
    header_effect *Effect = &State->Effect[State->Playhead_Effect];
    Effect->Name = Name;
    Effect->ID = ID;
    Effect->func = func;
    Effect->DisplayType = DisplayType;
    Effect->PropertyStartIndex = State->Playhead_Property;
    if (GL_Shader) {
        Effect->GLShaderIndex = Effect_GL_InitShader(GL_Shader);
        Effect->UseGL = true;
    }
}

static void
Effect_EndEntry(project_state *State)
{
    State->Playhead_Effect++;
}

static void
Effect_AddProperty_Real(project_state *State, char *Name, real32 DefaultValue, real32 MinVal, real32 MaxVal, property_display_type DisplayType)
{
    header_effect *Effect = &State->Effect[State->Playhead_Effect];
    Effect->Property_Count++;
    header_property *Property = &State->Property[State->Playhead_Property++];
    Property->Name = Name;
    Property->DefaultValue = DefaultValue;
    Property->DisplayType = DisplayType;
    Property->MinVal = MinVal;
    Property->MaxVal = MaxVal;
}

static void
Effect_AddProperty_Col(project_state *State, char *Name, v4 DefaultValue)
{
    Effect_AddProperty_Real(State, "r", DefaultValue.r, 0, 1, property_display_type_color);
    Effect_AddProperty_Real(State, "g", DefaultValue.g, 0, 1, property_display_type_color);
    Effect_AddProperty_Real(State, "b", DefaultValue.b, 0, 1, property_display_type_color);
    Effect_AddProperty_Real(State, "a", DefaultValue.a, 0, 1, property_display_type_color);
}

static void
Effect_AddProperty_Blendmode(project_state *State, char *Name, blend_mode DefaultValue)
{
    header_effect *Effect = &State->Effect[State->Playhead_Effect];
    Effect->Property_Count++;
    header_property *Property = &State->Property[State->Playhead_Property++];
    Property->Name = Name;
    Property->DefaultValue = DefaultValue;
    Property->DisplayType = property_display_type_blendmode;
}

static header_effect*
Effect_EntryFromID(project_state *State, char *ID)
{
    for (int i = 0; i < State->Playhead_Effect; i++) {
        if (String_Compare(ID, State->Effect[i].ID, 8))
            return &State->Effect[i];
    }
    Assert(0);
    return &State->Effect[0];
}

static void
Effect_InitEntries(project_state *State)
{
    /*
    */
    // Curves
    /*
    Effect_AddEntry(State, "Curves", "REALCRVS", &NULL, NULL, effect_display_type_curves);
    Effect_AddProperty_Real(State, "Selected channel", 0.0f);
    Effect_AddProperty_Real(State, "Number of points (main)", 2.0f);
    Effect_AddProperty_Col(State, "Number of points (individual)", V4(2.0f));
    for (int i = 0; i < MAX_CURVESPOINTS*5/2; i++) {
        v4 PointData = ((i % (MAX_CURVESPOINTS/2)) == 0) ? V4(0, 0, 1, 1) : V4(0);
        Effect_AddProperty_Col(State, "PointData", PointData);
    }
    Effect_EndEntry(State);
    */

    // Solid color
    Effect_AddEntry(State, "Solid color", "REALSCOL", &Effect_DrawColor, GLShader_SolidColor);
    Effect_AddProperty_Col(State, "Color", V4(0.3f, 0.2f, 0.6f, 1.0f));
    Effect_EndEntry(State);

    // Gaussian blur
    Effect_AddEntry(State, "Gaussian blur", "REALGBLR", &Effect_GaussianBlur, GLShader_GaussianBlur);
    Effect_AddProperty_Real(State, "Radius", 1.0f, 0.0f, 200.0f);
    Effect_EndEntry(State);

    // Curves
    Effect_AddEntry(State, "Curves", "REALCRVS", &Effect_Curves, NULL, effect_display_type_curves);
    for (int i = 0; i < MAX_PROPERTIES_PER_EFFECT; i++) {
        Effect_AddProperty_Real(State, "point", 0.0f);
    }
    Effect_EndEntry(State);

    // Levels
    Effect_AddEntry(State, "Levels", "REALLVLS", &Effect_Levels, GLShader_Levels, effect_display_type_levels);
    // min/max is handled by the UI
    Effect_AddProperty_Real(State, "All start point", 0.0f);
    Effect_AddProperty_Real(State, "All mid point", 1.0f);
    Effect_AddProperty_Real(State, "All end point", 1.0f);
    Effect_AddProperty_Col(State, "Channel start point", V4(0.0f));
    Effect_AddProperty_Col(State, "Channel mid point",   V4(1.0f));
    Effect_AddProperty_Col(State, "Channel end point",   V4(1.0f));
    Effect_EndEntry(State);
    /*
    // Test gradient
    Effect_AddEntry(State, "Test gradient", "REALTGRD", &Effect_TestGradient, NULL);
    Effect_AddProperty_Col(State, "Color", V4(0.3f, 0.2f, 0.6f, 1.0f));
    Effect_EndEntry(State);
    */
}