Debian Codegraph @

drivers/gles3/effects/feed_effects.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* feed_effects.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #ifdef GLES3_ENABLED
32
33 #include "feed_effects.h"
34
35 #ifdef ANDROID_ENABLED
36 #include <GLES3/gl3ext.h>
37 #endif
38
39 #define GL_PROGRAM_POINT_SIZE 0x8642
40
41 using namespace GLES3;
42
43 FeedEffects *FeedEffects::singleton = nullptr;
44
45 FeedEffects *FeedEffects::get_singleton() {
46 return singleton;
47 }
48
49 FeedEffects::FeedEffects() {
50 singleton = this;
51
52 feed.shader.initialize();
53 feed.shader_version = feed.shader.version_create();
54 feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT);
55
56 { // Screen Triangle.
57 glGenBuffers(1, &screen_triangle);
58 glBindBuffer(GL_ARRAY_BUFFER, screen_triangle);
59
60 const float qv[6] = {
61 -1.0f,
62 -1.0f,
63 3.0f,
64 -1.0f,
65 -1.0f,
66 3.0f,
67 };
68
69 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, qv, GL_STATIC_DRAW);
70 glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
71
72 glGenVertexArrays(1, &screen_triangle_array);
73 glBindVertexArray(screen_triangle_array);
74 glBindBuffer(GL_ARRAY_BUFFER, screen_triangle);
75 glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, nullptr);
76 glEnableVertexAttribArray(RS::ARRAY_VERTEX);
77 glBindVertexArray(0);
78 glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
79 }
80 }
81
82 FeedEffects::~FeedEffects() {
83 singleton = nullptr;
84 glDeleteBuffers(1, &screen_triangle);
85 glDeleteVertexArrays(1, &screen_triangle_array);
86 feed.shader.version_free(feed.shader_version);
87 }
88
89 Transform3D transform3D_from_mat4(const float *p_mat4) {
90 Transform3D res;
91
92 res.basis.rows[0][0] = p_mat4[0];
93 res.basis.rows[1][0] = p_mat4[1];
94 res.basis.rows[2][0] = p_mat4[2];
95 // p_mat4[3] = 0;
96 res.basis.rows[0][1] = p_mat4[4];
97 res.basis.rows[1][1] = p_mat4[5];
98 res.basis.rows[2][1] = p_mat4[6];
99 // p_mat4[7] = 0;
100 res.basis.rows[0][2] = p_mat4[8];
101 res.basis.rows[1][2] = p_mat4[9];
102 res.basis.rows[2][2] = p_mat4[10];
103 // p_mat4[11] = 0;
104 res.origin.x = p_mat4[12];
105 res.origin.y = p_mat4[13];
106 res.origin.z = p_mat4[14];
107 // p_mat4[15] = 1;
108
109 return res;
110 }
111
112 void FeedEffects::draw() {
113 bool success = feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT, FeedShaderGLES3::USE_EXTERNAL_SAMPLER);
114 if (!success) {
115 OS::get_singleton()->print("Godot : FeedShaderGLES3 Could not bind version_bind_shader USE_EXTERNAL_SAMPLER");
116 return;
117 }
118
119 draw_screen_triangle();
120 }
121
122 void FeedEffects::draw_screen_triangle() {
123 glBindVertexArray(screen_triangle_array);
124 glDrawArrays(GL_TRIANGLES, 0, 3);
125 glBindVertexArray(0);
126 }
127
128 #endif // GLES3_ENABLED