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
|
static uint16 Effect_GL_InitShader(int EffectIndex);
static uint16 GL_EffectShaderProgram[512];
static void GL_BindDefaultVertexArrays();
static void GL_InitTexture(gl_effect_layer *Test);
void Effect_GL_Levels(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, property_channel Property[])
{
real32 All_Start = Property[0].CurrentValue.f;
real32 All_Mid = Property[1].CurrentValue.f;
real32 All_End = Property[2].CurrentValue.f;
v4 Start = Property[3].CurrentValue.col;
v4 Mid = Property[4].CurrentValue.col;
v4 End = Property[5].CurrentValue.col;
if (!BitmapInfo->Test.Initialized) {
GL_InitTexture(&BitmapInfo->Test);
}
gl_effect_layer Test = BitmapInfo->Test;
uint8 *Data = (uint8 *)BitmapInfo->BitmapBuffer;
uint16 Width = Source->Info.Width;
uint16 Height = Source->Info.Height;
glBindTexture(GL_TEXTURE_2D, Test.Texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, Data);
glBindFramebuffer(GL_FRAMEBUFFER, Test.FramebufferObject);
glBindRenderbuffer(GL_RENDERBUFFER, Test.Color_Renderbuffer);
uint16 ShaderProgram = Effect_GL_InitShader(1);
GL_BindDefaultVertexArrays();
int vertexColorLocation = glGetUniformLocation(ShaderProgram, "Start");
glUniform1f(vertexColorLocation, All_Start);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "Mid");
glUniform1f(vertexColorLocation, All_Mid);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "End");
glUniform1f(vertexColorLocation, All_End);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "StartCol");
glUniform4f(vertexColorLocation, Start.r, Start.g, Start.b, Start.a);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "MidCol");
glUniform4f(vertexColorLocation, Mid.r, Mid.g, Mid.b, Mid.a);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "EndCol");
glUniform4f(vertexColorLocation, End.r, End.g, End.b, End.a);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void Effect_GL_GaussianBlur(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, property_channel Property[])
{
real32 Radius = Property[0].CurrentValue.f;
if (!BitmapInfo->Test.Initialized) {
GL_InitTexture(&BitmapInfo->Test);
}
gl_effect_layer Test = BitmapInfo->Test;
uint8 *Data = (uint8 *)BitmapInfo->BitmapBuffer;
uint16 Width = Source->Info.Width;
uint16 Height = Source->Info.Height;
glBindTexture(GL_TEXTURE_2D, Test.Texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, Data);
glBindFramebuffer(GL_FRAMEBUFFER, Test.FramebufferObject);
glBindRenderbuffer(GL_RENDERBUFFER, Test.Color_Renderbuffer);
uint16 ShaderProgram = Effect_GL_InitShader(2);
GL_BindDefaultVertexArrays();
int vertexColorLocation = glGetUniformLocation(ShaderProgram, "Radius");
glUniform1f(vertexColorLocation, Radius + 1.60f);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "Direction");
glUniform2f(vertexColorLocation, 1.0f, 0.0f);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
// This blur works in two passes.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, Data);
vertexColorLocation = glGetUniformLocation(ShaderProgram, "Direction");
glUniform2f(vertexColorLocation, 0.0f, 1.0f);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
|