2016-10-03 21:33:42 +02:00
|
|
|
/*************************************************************************/
|
2017-03-05 15:47:28 +01:00
|
|
|
/* shader_gles3.h */
|
2016-10-03 21:33:42 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-10-03 21:33:42 +02:00
|
|
|
/*************************************************************************/
|
2022-01-13 09:45:09 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-10-03 21:33:42 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
#ifndef SHADER_GLES3_H
|
|
|
|
#define SHADER_GLES3_H
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/hash_map.h"
|
2021-09-26 21:31:17 +02:00
|
|
|
#include "core/local_vector.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/map.h"
|
|
|
|
#include "core/math/camera_matrix.h"
|
2021-09-26 21:31:17 +02:00
|
|
|
#include "core/safe_refcount.h"
|
|
|
|
#include "core/self_list.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/variant.h"
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
#include "platform_config.h"
|
|
|
|
#ifndef GLES3_INCLUDE_H
|
|
|
|
#include <GLES3/gl3.h>
|
|
|
|
#else
|
|
|
|
#include GLES3_INCLUDE_H
|
|
|
|
#endif
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include <stdio.h>
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
template <class K>
|
|
|
|
class ThreadedCallableQueue;
|
|
|
|
class ShaderCacheGLES3;
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
class ShaderGLES3 {
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2016-10-03 21:33:42 +02:00
|
|
|
struct Enum {
|
|
|
|
uint64_t mask;
|
|
|
|
uint64_t shift;
|
|
|
|
const char *defines[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumValue {
|
|
|
|
uint64_t set_mask;
|
|
|
|
uint64_t clear_mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AttributePair {
|
|
|
|
const char *name;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UniformPair {
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *name;
|
2016-10-03 21:33:42 +02:00
|
|
|
Variant::Type type_hint;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TexUnitPair {
|
|
|
|
const char *name;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UBOPair {
|
|
|
|
const char *name;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
2016-11-25 00:46:55 +01:00
|
|
|
struct Feedback {
|
|
|
|
const char *name;
|
|
|
|
int conditional;
|
|
|
|
};
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
virtual int get_ubershader_flags_uniform() const { return -1; }
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
private:
|
2016-10-03 21:33:42 +02:00
|
|
|
//@TODO Optimize to a fixed set of shader pools and use a LRU
|
|
|
|
int uniform_count;
|
|
|
|
int texunit_pair_count;
|
|
|
|
int conditional_count;
|
|
|
|
int ubo_count;
|
2016-11-25 00:46:55 +01:00
|
|
|
int feedback_count;
|
2016-10-03 21:33:42 +02:00
|
|
|
int vertex_code_start;
|
|
|
|
int fragment_code_start;
|
|
|
|
int attribute_pair_count;
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
public:
|
|
|
|
enum AsyncMode {
|
|
|
|
ASYNC_MODE_VISIBLE,
|
|
|
|
ASYNC_MODE_HIDDEN,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2016-10-03 21:33:42 +02:00
|
|
|
struct CustomCode {
|
|
|
|
String vertex;
|
|
|
|
String vertex_globals;
|
|
|
|
String fragment;
|
|
|
|
String fragment_globals;
|
|
|
|
String light;
|
2016-10-10 23:31:01 +02:00
|
|
|
String uniforms;
|
2021-09-26 21:31:17 +02:00
|
|
|
AsyncMode async_mode;
|
2016-10-03 21:33:42 +02:00
|
|
|
uint32_t version;
|
2016-10-10 23:31:01 +02:00
|
|
|
Vector<StringName> texture_uniforms;
|
|
|
|
Vector<CharString> custom_defines;
|
2019-01-25 23:28:27 +01:00
|
|
|
Set<uint32_t> versions;
|
2016-10-03 21:33:42 +02:00
|
|
|
};
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
public:
|
|
|
|
static ShaderCacheGLES3 *shader_cache;
|
|
|
|
static ThreadedCallableQueue<GLuint> *cache_write_queue;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2022-01-06 23:18:25 +01:00
|
|
|
static ThreadedCallableQueue<GLuint> *compile_queue; // Non-null if using queued asynchronous compilation (via secondary context)
|
2021-09-26 21:31:17 +02:00
|
|
|
static bool parallel_compile_supported; // True if using natively supported asyncrhonous compilation
|
|
|
|
|
|
|
|
static bool async_hidden_forbidden;
|
|
|
|
static int *compiles_started_this_frame;
|
|
|
|
static int max_simultaneous_compiles;
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
static bool log_active_async_compiles_count;
|
|
|
|
#endif
|
|
|
|
static uint64_t current_frame;
|
|
|
|
|
|
|
|
static void advance_async_shaders_compilation();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static int active_compiles_count;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
union VersionKey {
|
2021-09-26 21:31:17 +02:00
|
|
|
static const uint32_t UBERSHADER_FLAG = ((uint32_t)1) << 31;
|
2016-10-03 21:33:42 +02:00
|
|
|
struct {
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t code_version;
|
|
|
|
};
|
|
|
|
uint64_t key;
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator==(const VersionKey &p_key) const { return key == p_key.key; }
|
|
|
|
bool operator<(const VersionKey &p_key) const { return key < p_key.key; }
|
2021-09-26 21:31:17 +02:00
|
|
|
VersionKey() {}
|
|
|
|
VersionKey(uint64_t p_key) :
|
|
|
|
key(p_key) {}
|
|
|
|
_FORCE_INLINE_ bool is_subject_to_caching() const { return (version & UBERSHADER_FLAG); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Version {
|
|
|
|
VersionKey version_key;
|
|
|
|
|
|
|
|
// Set by the render thread upfront; the compile thread (for queued async.) reads them
|
|
|
|
struct Ids {
|
|
|
|
GLuint main;
|
|
|
|
GLuint vert;
|
|
|
|
GLuint frag;
|
|
|
|
} ids;
|
|
|
|
|
|
|
|
ShaderGLES3 *shader;
|
|
|
|
uint32_t code_version;
|
|
|
|
|
|
|
|
AsyncMode async_mode;
|
|
|
|
GLint *uniform_location;
|
|
|
|
Vector<GLint> texture_uniform_locations;
|
|
|
|
bool uniforms_ready;
|
|
|
|
uint64_t last_frame_processed;
|
|
|
|
|
|
|
|
enum CompileStatus {
|
|
|
|
COMPILE_STATUS_PENDING,
|
|
|
|
COMPILE_STATUS_SOURCE_PROVIDED,
|
|
|
|
COMPILE_STATUS_COMPILING_VERTEX,
|
|
|
|
COMPILE_STATUS_COMPILING_FRAGMENT,
|
|
|
|
COMPILE_STATUS_COMPILING_VERTEX_AND_FRAGMENT,
|
|
|
|
COMPILE_STATUS_PROCESSING_AT_QUEUE,
|
|
|
|
COMPILE_STATUS_BINARY_READY,
|
|
|
|
COMPILE_STATUS_BINARY_READY_FROM_CACHE,
|
|
|
|
COMPILE_STATUS_LINKING,
|
|
|
|
COMPILE_STATUS_ERROR,
|
|
|
|
COMPILE_STATUS_RESTART_NEEDED,
|
|
|
|
COMPILE_STATUS_OK,
|
|
|
|
};
|
|
|
|
CompileStatus compile_status;
|
|
|
|
SelfList<Version> compiling_list;
|
|
|
|
|
|
|
|
struct ProgramBinary {
|
|
|
|
String cache_hash;
|
|
|
|
enum Source {
|
|
|
|
SOURCE_NONE,
|
|
|
|
SOURCE_LOCAL, // Binary data will only be available if cache enabled
|
|
|
|
SOURCE_QUEUE,
|
|
|
|
SOURCE_CACHE,
|
|
|
|
} source;
|
|
|
|
// Shared with the compile thread (for queued async.); otherwise render thread only
|
|
|
|
GLenum format;
|
|
|
|
PoolByteArray data;
|
|
|
|
SafeNumeric<int> result_from_queue;
|
|
|
|
} program_binary;
|
|
|
|
|
|
|
|
Version() :
|
|
|
|
version_key(0),
|
|
|
|
ids(),
|
|
|
|
shader(nullptr),
|
|
|
|
code_version(0),
|
|
|
|
async_mode(ASYNC_MODE_VISIBLE),
|
|
|
|
uniform_location(nullptr),
|
|
|
|
uniforms_ready(false),
|
|
|
|
last_frame_processed(UINT64_MAX),
|
|
|
|
compile_status(COMPILE_STATUS_PENDING),
|
|
|
|
compiling_list(this),
|
|
|
|
program_binary() {}
|
2016-10-03 21:33:42 +02:00
|
|
|
};
|
2021-09-26 21:31:17 +02:00
|
|
|
static SelfList<Version>::List versions_compiling;
|
|
|
|
|
|
|
|
Version *version;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
struct VersionKeyHash {
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ uint32_t hash(const VersionKey &p_key) { return HashMapHasherDefault::hash(p_key.key); };
|
2016-10-03 21:33:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//this should use a way more cachefriendly version..
|
2017-03-05 16:44:50 +01:00
|
|
|
HashMap<VersionKey, Version, VersionKeyHash> version_map;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HashMap<uint32_t, CustomCode> custom_code_map;
|
2016-10-03 21:33:42 +02:00
|
|
|
uint32_t last_custom_code;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
VersionKey conditional_version;
|
|
|
|
VersionKey new_conditional_version;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
virtual String get_shader_name() const = 0;
|
|
|
|
|
|
|
|
const char **conditional_defines;
|
|
|
|
const char **uniform_names;
|
2016-10-03 21:33:42 +02:00
|
|
|
const AttributePair *attribute_pairs;
|
|
|
|
const TexUnitPair *texunit_pairs;
|
|
|
|
const UBOPair *ubo_pairs;
|
2016-11-25 00:46:55 +01:00
|
|
|
const Feedback *feedbacks;
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *vertex_code;
|
|
|
|
const char *fragment_code;
|
2016-10-03 21:33:42 +02:00
|
|
|
CharString fragment_code0;
|
|
|
|
CharString fragment_code1;
|
|
|
|
CharString fragment_code2;
|
|
|
|
CharString fragment_code3;
|
2016-10-10 23:31:01 +02:00
|
|
|
CharString fragment_code4;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
CharString vertex_code0;
|
|
|
|
CharString vertex_code1;
|
|
|
|
CharString vertex_code2;
|
2016-10-10 23:31:01 +02:00
|
|
|
CharString vertex_code3;
|
|
|
|
|
2016-11-11 16:27:52 +01:00
|
|
|
Vector<CharString> custom_defines;
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
int base_material_tex_index;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
Version *get_current_version(bool &r_async_forbidden);
|
|
|
|
// These will run on the shader compile thread if using que compile queue approach to async.
|
|
|
|
void _set_source(Version::Ids p_ids, const LocalVector<const char *> &p_vertex_strings, const LocalVector<const char *> &p_fragment_strings) const;
|
|
|
|
bool _complete_compile(Version::Ids p_ids, bool p_retrievable) const;
|
|
|
|
bool _complete_link(Version::Ids p_ids, GLenum *r_program_format = nullptr, PoolByteArray *r_program_binary = nullptr) const;
|
|
|
|
// ---
|
|
|
|
static void _log_active_compiles();
|
|
|
|
static bool _process_program_state(Version *p_version, bool p_async_forbidden);
|
|
|
|
void _setup_uniforms(CustomCode *p_cc) const;
|
|
|
|
void _dispose_program(Version *p_version);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
static ShaderGLES3 *active;
|
|
|
|
|
|
|
|
int max_image_units;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform, const Variant &p_value) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_uniform < 0) {
|
2016-10-03 21:33:42 +02:00
|
|
|
return; // do none
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_value.get_type()) {
|
|
|
|
case Variant::BOOL:
|
|
|
|
case Variant::INT: {
|
|
|
|
int val = p_value;
|
|
|
|
glUniform1i(p_uniform, val);
|
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
real_t val = p_value;
|
|
|
|
glUniform1f(p_uniform, val);
|
|
|
|
} break;
|
|
|
|
case Variant::COLOR: {
|
|
|
|
Color val = p_value;
|
|
|
|
glUniform4f(p_uniform, val.r, val.g, val.b, val.a);
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2: {
|
|
|
|
Vector2 val = p_value;
|
|
|
|
glUniform2f(p_uniform, val.x, val.y);
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
Vector3 val = p_value;
|
|
|
|
glUniform3f(p_uniform, val.x, val.y, val.z);
|
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
Plane val = p_value;
|
|
|
|
glUniform4f(p_uniform, val.normal.x, val.normal.y, val.normal.z, val.d);
|
|
|
|
} break;
|
|
|
|
case Variant::QUAT: {
|
|
|
|
Quat val = p_value;
|
|
|
|
glUniform4f(p_uniform, val.x, val.y, val.z, val.w);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::TRANSFORM2D: {
|
|
|
|
Transform2D tr = p_value;
|
|
|
|
GLfloat matrix[16] = { /* build a 16x16 matrix */
|
|
|
|
tr.elements[0][0],
|
|
|
|
tr.elements[0][1],
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
tr.elements[1][0],
|
|
|
|
tr.elements[1][1],
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
tr.elements[2][0],
|
|
|
|
tr.elements[2][1],
|
|
|
|
0,
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
|
|
|
glUniformMatrix4fv(p_uniform, 1, false, matrix);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::BASIS:
|
|
|
|
case Variant::TRANSFORM: {
|
|
|
|
Transform tr = p_value;
|
|
|
|
GLfloat matrix[16] = { /* build a 16x16 matrix */
|
|
|
|
tr.basis.elements[0][0],
|
|
|
|
tr.basis.elements[1][0],
|
|
|
|
tr.basis.elements[2][0],
|
|
|
|
0,
|
|
|
|
tr.basis.elements[0][1],
|
|
|
|
tr.basis.elements[1][1],
|
|
|
|
tr.basis.elements[2][1],
|
|
|
|
0,
|
|
|
|
tr.basis.elements[0][2],
|
|
|
|
tr.basis.elements[1][2],
|
|
|
|
tr.basis.elements[2][2],
|
|
|
|
0,
|
|
|
|
tr.origin.x,
|
|
|
|
tr.origin.y,
|
|
|
|
tr.origin.z,
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
|
|
|
glUniformMatrix4fv(p_uniform, 1, false, matrix);
|
|
|
|
} break;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
ERR_FAIL();
|
|
|
|
} // do nothing
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
bool _bind(bool p_binding_fallback);
|
|
|
|
bool _bind_ubershader();
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2016-10-03 21:33:42 +02:00
|
|
|
_FORCE_INLINE_ int _get_uniform(int p_which) const;
|
|
|
|
_FORCE_INLINE_ void _set_conditional(int p_which, bool p_value);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
void setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const UBOPair *p_ubo_pairs, int p_ubo_pair_count, const Feedback *p_feedback, int p_feedback_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start);
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ShaderGLES3();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
public:
|
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
CUSTOM_SHADER_DISABLED = 0
|
2016-10-03 21:33:42 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GLint get_uniform_location(const String &p_name) const;
|
2017-08-11 21:10:05 +02:00
|
|
|
GLint get_uniform_location(int p_index) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
static _FORCE_INLINE_ ShaderGLES3 *get_active() { return active; };
|
|
|
|
bool bind();
|
|
|
|
void unbind();
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
void clear_caches();
|
|
|
|
|
|
|
|
uint32_t create_custom_shader();
|
2021-09-26 21:31:17 +02:00
|
|
|
void set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_light, const String &p_fragment_globals, const String &p_uniforms, const Vector<StringName> &p_texture_uniforms, const Vector<CharString> &p_custom_defines, AsyncMode p_async_mode);
|
2017-08-11 21:10:05 +02:00
|
|
|
void set_custom_shader(uint32_t p_code_id);
|
|
|
|
void free_custom_shader(uint32_t p_code_id);
|
2022-04-12 20:08:09 +02:00
|
|
|
bool is_custom_code_ready_for_render(uint32_t p_code_id);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
uint32_t get_version() const { return new_conditional_version.version; }
|
2021-12-11 14:25:38 +01:00
|
|
|
bool is_version_ubershader() const { return (new_conditional_version.version & VersionKey::UBERSHADER_FLAG); }
|
2021-09-26 21:31:17 +02:00
|
|
|
_FORCE_INLINE_ bool is_version_valid() const { return version && version->compile_status == Version::COMPILE_STATUS_OK; }
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void init() = 0;
|
2021-09-26 21:31:17 +02:00
|
|
|
void init_async_compilation();
|
|
|
|
bool is_async_compilation_supported();
|
2016-10-03 21:33:42 +02:00
|
|
|
void finish();
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
void set_base_material_tex_index(int p_idx);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void add_custom_define(const String &p_define) {
|
2016-11-11 16:27:52 +01:00
|
|
|
custom_defines.push_back(p_define.utf8());
|
|
|
|
}
|
|
|
|
|
2020-01-19 08:14:10 +01:00
|
|
|
void get_custom_defines(Vector<String> *p_defines) {
|
|
|
|
for (int i = 0; i < custom_defines.size(); i++) {
|
|
|
|
p_defines->push_back(custom_defines[i].get_data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 06:31:09 +02:00
|
|
|
void remove_custom_define(const String &p_define) {
|
|
|
|
custom_defines.erase(p_define.utf8());
|
2020-01-19 08:14:10 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
virtual ~ShaderGLES3();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
// called a lot, made inline
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
int ShaderGLES3::_get_uniform(int p_which) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_which, uniform_count, -1);
|
|
|
|
ERR_FAIL_COND_V(!version, -1);
|
2016-10-03 21:33:42 +02:00
|
|
|
return version->uniform_location[p_which];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderGLES3::_set_conditional(int p_which, bool p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_which, conditional_count);
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
new_conditional_version.version |= (1 << p_which);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
new_conditional_version.version &= ~(1 << p_which);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|