Path: blob/master/drivers/gles3/effects/feed_effects.cpp
10000 views
/**************************************************************************/1/* feed_effects.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#ifdef GLES3_ENABLED3132#include "feed_effects.h"3334#ifdef ANDROID_ENABLED35#include <GLES3/gl3ext.h>36#endif3738#define GL_PROGRAM_POINT_SIZE 0x86423940using namespace GLES3;4142FeedEffects *FeedEffects::singleton = nullptr;4344FeedEffects *FeedEffects::get_singleton() {45return singleton;46}4748FeedEffects::FeedEffects() {49singleton = this;5051feed.shader.initialize();52feed.shader_version = feed.shader.version_create();53feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT);5455{ // Screen Triangle.56glGenBuffers(1, &screen_triangle);57glBindBuffer(GL_ARRAY_BUFFER, screen_triangle);5859const float qv[6] = {60-1.0f,61-1.0f,623.0f,63-1.0f,64-1.0f,653.0f,66};6768glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, qv, GL_STATIC_DRAW);69glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind7071glGenVertexArrays(1, &screen_triangle_array);72glBindVertexArray(screen_triangle_array);73glBindBuffer(GL_ARRAY_BUFFER, screen_triangle);74glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, nullptr);75glEnableVertexAttribArray(RS::ARRAY_VERTEX);76glBindVertexArray(0);77glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind78}79}8081FeedEffects::~FeedEffects() {82singleton = nullptr;83glDeleteBuffers(1, &screen_triangle);84glDeleteVertexArrays(1, &screen_triangle_array);85feed.shader.version_free(feed.shader_version);86}8788Transform3D transform3D_from_mat4(const float *p_mat4) {89Transform3D res;9091res.basis.rows[0][0] = p_mat4[0];92res.basis.rows[1][0] = p_mat4[1];93res.basis.rows[2][0] = p_mat4[2];94// p_mat4[3] = 0;95res.basis.rows[0][1] = p_mat4[4];96res.basis.rows[1][1] = p_mat4[5];97res.basis.rows[2][1] = p_mat4[6];98// p_mat4[7] = 0;99res.basis.rows[0][2] = p_mat4[8];100res.basis.rows[1][2] = p_mat4[9];101res.basis.rows[2][2] = p_mat4[10];102// p_mat4[11] = 0;103res.origin.x = p_mat4[12];104res.origin.y = p_mat4[13];105res.origin.z = p_mat4[14];106// p_mat4[15] = 1;107108return res;109}110111void FeedEffects::draw() {112bool success = feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT, FeedShaderGLES3::USE_EXTERNAL_SAMPLER);113if (!success) {114OS::get_singleton()->print("Godot : FeedShaderGLES3 Could not bind version_bind_shader USE_EXTERNAL_SAMPLER");115return;116}117118draw_screen_triangle();119}120121void FeedEffects::draw_screen_triangle() {122glBindVertexArray(screen_triangle_array);123glDrawArrays(GL_TRIANGLES, 0, 3);124glBindVertexArray(0);125}126127#endif // GLES3_ENABLED128129130