SCons: Modernize shader builders
This commit is contained in:
parent
adc63c6149
commit
32de6285a8
@ -1,9 +1,8 @@
|
|||||||
"""Functions used to generate source files during build time"""
|
"""Functions used to generate source files during build time"""
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from methods import print_error, to_raw_cstring
|
from methods import generated_wrapper, print_error, to_raw_cstring
|
||||||
|
|
||||||
|
|
||||||
class GLES3HeaderStruct:
|
class GLES3HeaderStruct:
|
||||||
@ -189,212 +188,165 @@ def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct,
|
|||||||
return header_data
|
return header_data
|
||||||
|
|
||||||
|
|
||||||
def build_gles3_header(
|
def build_gles3_header(filename: str, shader: str) -> None:
|
||||||
filename: str,
|
include_file_in_gles3_header(shader, header_data := GLES3HeaderStruct(), 0)
|
||||||
include: str,
|
out_file_class = (
|
||||||
class_suffix: str,
|
os.path.basename(shader).replace(".glsl", "").title().replace("_", "").replace(".", "") + "ShaderGLES3"
|
||||||
optional_output_filename: Optional[str] = None,
|
)
|
||||||
header_data: Optional[GLES3HeaderStruct] = None,
|
|
||||||
):
|
|
||||||
header_data = header_data or GLES3HeaderStruct()
|
|
||||||
include_file_in_gles3_header(filename, header_data, 0)
|
|
||||||
|
|
||||||
if optional_output_filename is None:
|
with generated_wrapper(filename) as file:
|
||||||
out_file = filename + ".gen.h"
|
|
||||||
else:
|
|
||||||
out_file = optional_output_filename
|
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
|
|
||||||
defspec = 0
|
defspec = 0
|
||||||
defvariant = ""
|
defvariant = ""
|
||||||
|
|
||||||
fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
|
file.write(f"""\
|
||||||
fd.write("#pragma once\n")
|
#include "drivers/gles3/shader_gles3.h"
|
||||||
|
|
||||||
out_file_base = out_file
|
class {out_file_class} : public ShaderGLES3 {{
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
public:
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
""")
|
||||||
|
|
||||||
out_file_class = (
|
|
||||||
out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
|
|
||||||
)
|
|
||||||
fd.write("\n\n")
|
|
||||||
fd.write('#include "' + include + '"\n\n\n')
|
|
||||||
fd.write("class " + out_file_class + " : public Shader" + class_suffix + " {\n\n")
|
|
||||||
|
|
||||||
fd.write("public:\n\n")
|
|
||||||
|
|
||||||
if header_data.uniforms:
|
if header_data.uniforms:
|
||||||
fd.write("\tenum Uniforms {\n")
|
uniforms = ",\n\t\t".join(uniform.upper() for uniform in header_data.uniforms)
|
||||||
for x in header_data.uniforms:
|
file.write(f"""\
|
||||||
fd.write("\t\t" + x.upper() + ",\n")
|
enum Uniforms {{
|
||||||
fd.write("\t};\n\n")
|
{uniforms},
|
||||||
|
}};
|
||||||
|
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.variant_names:
|
if header_data.variant_names:
|
||||||
fd.write("\tenum ShaderVariant {\n")
|
variant_names = ",\n\t\t".join(name for name in header_data.variant_names)
|
||||||
for x in header_data.variant_names:
|
|
||||||
fd.write("\t\t" + x + ",\n")
|
|
||||||
fd.write("\t};\n\n")
|
|
||||||
else:
|
else:
|
||||||
fd.write("\tenum ShaderVariant { DEFAULT };\n\n")
|
variant_names = "DEFAULT"
|
||||||
defvariant = " = DEFAULT"
|
defvariant = " = DEFAULT"
|
||||||
|
file.write(f"""\
|
||||||
|
enum ShaderVariant {{
|
||||||
|
{variant_names},
|
||||||
|
}};
|
||||||
|
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.specialization_names:
|
if header_data.specialization_names:
|
||||||
fd.write("\tenum Specializations {\n")
|
specialization_names = ",\n\t\t".join(
|
||||||
counter = 0
|
f"{name.upper()} = {1 << index}" for index, name in enumerate(header_data.specialization_names)
|
||||||
for x in header_data.specialization_names:
|
|
||||||
fd.write("\t\t" + x.upper() + "=" + str(1 << counter) + ",\n")
|
|
||||||
counter += 1
|
|
||||||
fd.write("\t};\n\n")
|
|
||||||
|
|
||||||
for i in range(len(header_data.specialization_names)):
|
|
||||||
defval = header_data.specialization_values[i].strip()
|
|
||||||
if defval.upper() == "TRUE" or defval == "1":
|
|
||||||
defspec |= 1 << i
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { return _version_bind_shader(p_version,p_variant,p_specialization); }\n\n"
|
|
||||||
)
|
)
|
||||||
|
file.write(f"""\
|
||||||
|
enum Specializations {{
|
||||||
|
{specialization_names},
|
||||||
|
}};
|
||||||
|
|
||||||
|
""")
|
||||||
|
for index, specialization_value in enumerate(header_data.specialization_values):
|
||||||
|
if specialization_value.strip().upper() in ["TRUE", "1"]:
|
||||||
|
defspec |= 1 << index
|
||||||
|
|
||||||
|
file.write(f"""\
|
||||||
|
_FORCE_INLINE_ bool version_bind_shader(RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
return _version_bind_shader(p_version, p_variant, p_specialization);
|
||||||
|
}}
|
||||||
|
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.uniforms:
|
if header_data.uniforms:
|
||||||
fd.write(
|
file.write(f"""\
|
||||||
"\t_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform,RID p_version,ShaderVariant p_variant"
|
_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
+ defvariant
|
return _version_get_uniform(p_uniform, p_version, p_variant, p_specialization);
|
||||||
+ ",uint64_t p_specialization="
|
}}
|
||||||
+ str(defspec)
|
|
||||||
+ ") { return _version_get_uniform(p_uniform,p_version,p_variant,p_specialization); }\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
/* clang-format off */
|
||||||
"\t#define _FU if (version_get_uniform(p_uniform,p_version,p_variant,p_specialization)<0) return; \n\n "
|
#define TRY_GET_UNIFORM if (version_get_uniform(p_uniform, p_version, p_variant, p_specialization) < 0) return
|
||||||
)
|
/* clang-format on */
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, double p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint8_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int8_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint16_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int16_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint32_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int32_t p_value,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Color& p_color,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; glUniform4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,col); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector2& p_vec2,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat vec2[2]={float(p_vec2.x),float(p_vec2.y)}; glUniform2fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec2); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Size2i& p_vec2,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLint vec2[2]={GLint(p_vec2.x),GLint(p_vec2.y)}; glUniform2iv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec2); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector3& p_vec3,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat vec3[3]={float(p_vec3.x),float(p_vec3.y),float(p_vec3.z)}; glUniform3fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec3); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector4& p_vec4,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU GLfloat vec4[4]={float(p_vec4.x),float(p_vec4.y),float(p_vec4.z),float(p_vec4.w)}; glUniform4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec4); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform2f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform3f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c); }\n\n"
|
|
||||||
)
|
|
||||||
fd.write(
|
|
||||||
"\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d,RID p_version,ShaderVariant p_variant"
|
|
||||||
+ defvariant
|
|
||||||
+ ",uint64_t p_specialization="
|
|
||||||
+ str(defspec)
|
|
||||||
+ ") { _FU glUniform4f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c,p_d); }\n\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
"""\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D& p_transform,RID p_version,ShaderVariant p_variant"""
|
TRY_GET_UNIFORM;
|
||||||
+ defvariant
|
glUniform1f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
+ """,uint64_t p_specialization="""
|
}}
|
||||||
+ str(defspec)
|
|
||||||
+ """) { _FU
|
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, double p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint8_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1ui(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int8_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1i(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint16_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1ui(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int16_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1i(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint32_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1ui(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int32_t p_value, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform1i(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_value);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Color &p_color, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat col[4] = {{ p_color.r, p_color.g, p_color.b, p_color.a }};
|
||||||
|
glUniform4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, col);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector2 &p_vec2, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat vec2[2] = {{ float(p_vec2.x), float(p_vec2.y) }};
|
||||||
|
glUniform2fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec2);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Size2i &p_vec2, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLint vec2[2] = {{ GLint(p_vec2.x), GLint(p_vec2.y) }};
|
||||||
|
glUniform2iv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec2);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector3 &p_vec3, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat vec3[3] = {{ float(p_vec3.x), float(p_vec3.y), float(p_vec3.z) }};
|
||||||
|
glUniform3fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec3);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector4 &p_vec4, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
GLfloat vec4[4] = {{ float(p_vec4.x), float(p_vec4.y), float(p_vec4.z), float(p_vec4.w) }};
|
||||||
|
glUniform4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, vec4);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform2f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_a, p_b);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform3f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_a, p_b, p_c);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
|
glUniform4f(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), p_a, p_b, p_c, p_d);
|
||||||
|
}}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D &p_transform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
const Transform3D &tr = p_transform;
|
const Transform3D &tr = p_transform;
|
||||||
|
|
||||||
GLfloat matrix[16]={ /* build a 16x16 matrix */
|
GLfloat matrix[16] = {{ /* build a 16x16 matrix */
|
||||||
(GLfloat)tr.basis.rows[0][0],
|
(GLfloat)tr.basis.rows[0][0],
|
||||||
(GLfloat)tr.basis.rows[1][0],
|
(GLfloat)tr.basis.rows[1][0],
|
||||||
(GLfloat)tr.basis.rows[2][0],
|
(GLfloat)tr.basis.rows[2][0],
|
||||||
@ -411,25 +363,16 @@ def build_gles3_header(
|
|||||||
(GLfloat)tr.origin.y,
|
(GLfloat)tr.origin.y,
|
||||||
(GLfloat)tr.origin.z,
|
(GLfloat)tr.origin.z,
|
||||||
(GLfloat)1
|
(GLfloat)1
|
||||||
};
|
}};
|
||||||
|
|
||||||
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
||||||
|
}}
|
||||||
|
|
||||||
}
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform2D &p_transform, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
"""_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform2D& p_transform,RID p_version,ShaderVariant p_variant"""
|
|
||||||
+ defvariant
|
|
||||||
+ """,uint64_t p_specialization="""
|
|
||||||
+ str(defspec)
|
|
||||||
+ """) { _FU
|
|
||||||
|
|
||||||
const Transform2D &tr = p_transform;
|
const Transform2D &tr = p_transform;
|
||||||
|
|
||||||
GLfloat matrix[16]={ /* build a 16x16 matrix */
|
GLfloat matrix[16] = {{ /* build a 16x16 matrix */
|
||||||
(GLfloat)tr.columns[0][0],
|
(GLfloat)tr.columns[0][0],
|
||||||
(GLfloat)tr.columns[0][1],
|
(GLfloat)tr.columns[0][1],
|
||||||
(GLfloat)0,
|
(GLfloat)0,
|
||||||
@ -446,142 +389,132 @@ def build_gles3_header(
|
|||||||
(GLfloat)tr.columns[2][1],
|
(GLfloat)tr.columns[2][1],
|
||||||
(GLfloat)0,
|
(GLfloat)0,
|
||||||
(GLfloat)1
|
(GLfloat)1
|
||||||
};
|
}};
|
||||||
|
|
||||||
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
||||||
|
}}
|
||||||
|
|
||||||
}
|
_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection &p_matrix, RID p_version, ShaderVariant p_variant{defvariant}, uint64_t p_specialization = {defspec}) {{
|
||||||
|
TRY_GET_UNIFORM;
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
"""_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection& p_matrix, RID p_version, ShaderVariant p_variant"""
|
|
||||||
+ defvariant
|
|
||||||
+ """,uint64_t p_specialization="""
|
|
||||||
+ str(defspec)
|
|
||||||
+ """) { _FU
|
|
||||||
|
|
||||||
GLfloat matrix[16];
|
GLfloat matrix[16];
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {{
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {{
|
||||||
matrix[i * 4 + j] = p_matrix.columns[i][j];
|
matrix[i * 4 + j] = p_matrix.columns[i][j];
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
|
|
||||||
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
|
||||||
}"""
|
}}
|
||||||
)
|
|
||||||
|
|
||||||
fd.write("\n\n#undef _FU\n\n\n")
|
#undef TRY_GET_UNIFORM
|
||||||
|
|
||||||
fd.write("protected:\n\n")
|
""")
|
||||||
|
|
||||||
fd.write("\tvirtual void _init() override {\n\n")
|
file.write("""\
|
||||||
|
protected:
|
||||||
|
virtual void _init() override {
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.uniforms:
|
if header_data.uniforms:
|
||||||
fd.write("\t\tstatic const char* _uniform_strings[]={\n")
|
uniforms = ",\n\t\t\t".join(f'"{uniform}"' for uniform in header_data.uniforms)
|
||||||
if header_data.uniforms:
|
file.write(f"""\
|
||||||
for x in header_data.uniforms:
|
static const char *_uniform_strings[] = {{
|
||||||
fd.write('\t\t\t"' + x + '",\n')
|
{uniforms}
|
||||||
fd.write("\t\t};\n\n")
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write("\t\tstatic const char **_uniform_strings=nullptr;\n")
|
file.write("""\
|
||||||
|
static const char **_uniform_strings = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
variant_count = 1
|
if header_data.variant_defines:
|
||||||
if len(header_data.variant_defines) > 0:
|
|
||||||
fd.write("\t\tstatic const char* _variant_defines[]={\n")
|
|
||||||
for x in header_data.variant_defines:
|
|
||||||
fd.write('\t\t\t"' + x + '",\n')
|
|
||||||
fd.write("\t\t};\n\n")
|
|
||||||
variant_count = len(header_data.variant_defines)
|
variant_count = len(header_data.variant_defines)
|
||||||
|
variant_defines = ",\n\t\t\t".join(f'"{define}"' for define in header_data.variant_defines)
|
||||||
|
file.write(f"""\
|
||||||
|
static const char *_variant_defines[] = {{
|
||||||
|
{variant_defines},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write('\t\tstatic const char **_variant_defines[]={" "};\n')
|
variant_count = 1
|
||||||
|
file.write("""\
|
||||||
|
static const char **_variant_defines[] = {" "};
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.texunits:
|
if header_data.texunits:
|
||||||
fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
|
texunits = ",\n\t\t\t".join(f'{{ "{name}", {texunit} }}' for name, texunit in header_data.texunits)
|
||||||
for x in header_data.texunits:
|
file.write(f"""\
|
||||||
fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
|
static TexUnitPair _texunit_pairs[] = {{
|
||||||
fd.write("\t\t};\n\n")
|
{texunits},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write("\t\tstatic TexUnitPair *_texunit_pairs=nullptr;\n")
|
file.write("""\
|
||||||
|
static TexUnitPair *_texunit_pairs = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
if header_data.ubos:
|
if header_data.ubos:
|
||||||
fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
|
ubos = ",\n\t\t\t".join(f'{{ "{name}", {ubo} }}' for name, ubo in header_data.ubos)
|
||||||
for x in header_data.ubos:
|
file.write(f"""\
|
||||||
fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
|
static UBOPair _ubo_pairs[] = {{
|
||||||
fd.write("\t\t};\n\n")
|
{ubos},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
fd.write("\t\tstatic UBOPair *_ubo_pairs=nullptr;\n")
|
file.write("""\
|
||||||
|
static UBOPair *_ubo_pairs = nullptr;
|
||||||
specializations_found = []
|
""")
|
||||||
|
|
||||||
if header_data.specialization_names:
|
if header_data.specialization_names:
|
||||||
fd.write("\t\tstatic Specialization _spec_pairs[]={\n")
|
specializations = ",\n\t\t\t".join(
|
||||||
for i in range(len(header_data.specialization_names)):
|
f'{{ "{name}", {"true" if header_data.specialization_values[index].strip().upper() in ["TRUE", "1"] else "false"} }}'
|
||||||
defval = header_data.specialization_values[i].strip()
|
for index, name in enumerate(header_data.specialization_names)
|
||||||
if defval.upper() == "TRUE" or defval == "1":
|
)
|
||||||
defval = "true"
|
file.write(f"""\
|
||||||
|
static Specialization _spec_pairs[] = {{
|
||||||
|
{specializations},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
defval = "false"
|
file.write("""\
|
||||||
|
static Specialization *_spec_pairs = nullptr;
|
||||||
fd.write('\t\t\t{"' + header_data.specialization_names[i] + '",' + defval + "},\n")
|
""")
|
||||||
specializations_found.append(header_data.specialization_names[i])
|
|
||||||
fd.write("\t\t};\n\n")
|
|
||||||
else:
|
|
||||||
fd.write("\t\tstatic Specialization *_spec_pairs=nullptr;\n")
|
|
||||||
|
|
||||||
feedback_count = 0
|
|
||||||
|
|
||||||
if header_data.feedbacks:
|
if header_data.feedbacks:
|
||||||
fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
|
feedbacks = ",\n\t\t\t".join(
|
||||||
for x in header_data.feedbacks:
|
f'{{ "{name}", {0 if spec not in header_data.specialization_names else (1 << header_data.specialization_names.index(spec))} }}'
|
||||||
name = x[0]
|
for name, spec in header_data.feedbacks
|
||||||
spec = x[1]
|
|
||||||
if spec in specializations_found:
|
|
||||||
fd.write('\t\t\t{"' + name + '",' + str(1 << specializations_found.index(spec)) + "},\n")
|
|
||||||
else:
|
|
||||||
fd.write('\t\t\t{"' + name + '",0},\n')
|
|
||||||
|
|
||||||
feedback_count += 1
|
|
||||||
|
|
||||||
fd.write("\t\t};\n\n")
|
|
||||||
else:
|
|
||||||
fd.write("\t\tstatic const Feedback* _feedbacks=nullptr;\n")
|
|
||||||
|
|
||||||
fd.write("\t\tstatic const char _vertex_code[]={\n")
|
|
||||||
fd.write(to_raw_cstring(header_data.vertex_lines))
|
|
||||||
fd.write("\n\t\t};\n\n")
|
|
||||||
|
|
||||||
fd.write("\t\tstatic const char _fragment_code[]={\n")
|
|
||||||
fd.write(to_raw_cstring(header_data.fragment_lines))
|
|
||||||
fd.write("\n\t\t};\n\n")
|
|
||||||
|
|
||||||
fd.write(
|
|
||||||
'\t\t_setup(_vertex_code,_fragment_code,"'
|
|
||||||
+ out_file_class
|
|
||||||
+ '",'
|
|
||||||
+ str(len(header_data.uniforms))
|
|
||||||
+ ",_uniform_strings,"
|
|
||||||
+ str(len(header_data.ubos))
|
|
||||||
+ ",_ubo_pairs,"
|
|
||||||
+ str(feedback_count)
|
|
||||||
+ ",_feedbacks,"
|
|
||||||
+ str(len(header_data.texunits))
|
|
||||||
+ ",_texunit_pairs,"
|
|
||||||
+ str(len(header_data.specialization_names))
|
|
||||||
+ ",_spec_pairs,"
|
|
||||||
+ str(variant_count)
|
|
||||||
+ ",_variant_defines);\n"
|
|
||||||
)
|
)
|
||||||
|
file.write(f"""\
|
||||||
|
static const Feedback _feedbacks[] = {{
|
||||||
|
{feedbacks},
|
||||||
|
}};
|
||||||
|
""")
|
||||||
|
else:
|
||||||
|
file.write("""\
|
||||||
|
static const Feedback *_feedbacks = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
fd.write("\t}\n\n")
|
file.write(f"""\
|
||||||
|
static const char _vertex_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.vertex_lines)}
|
||||||
|
}};
|
||||||
|
|
||||||
fd.write("};\n")
|
static const char _fragment_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.fragment_lines)}
|
||||||
|
}};
|
||||||
|
|
||||||
|
_setup(_vertex_code, _fragment_code, "{out_file_class}",
|
||||||
|
{len(header_data.uniforms)}, _uniform_strings, {len(header_data.ubos)}, _ubo_pairs,
|
||||||
|
{len(header_data.feedbacks)}, _feedbacks, {len(header_data.texunits)}, _texunit_pairs,
|
||||||
|
{len(header_data.specialization_names)}, _spec_pairs, {variant_count}, _variant_defines);
|
||||||
|
}}
|
||||||
|
}};
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
def build_gles3_headers(target, source, env):
|
def build_gles3_headers(target, source, env):
|
||||||
env.NoCache(target)
|
env.NoCache(target)
|
||||||
for x in source:
|
for src in source:
|
||||||
build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")
|
build_gles3_header(f"{src}.gen.h", str(src))
|
||||||
|
109
glsl_builders.py
109
glsl_builders.py
@ -1,9 +1,8 @@
|
|||||||
"""Functions used to generate source files during build time"""
|
"""Functions used to generate source files during build time"""
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from methods import print_error, to_raw_cstring
|
from methods import generated_wrapper, print_error, to_raw_cstring
|
||||||
|
|
||||||
|
|
||||||
class RDHeaderStruct:
|
class RDHeaderStruct:
|
||||||
@ -92,61 +91,49 @@ def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth:
|
|||||||
return header_data
|
return header_data
|
||||||
|
|
||||||
|
|
||||||
def build_rd_header(
|
def build_rd_header(filename: str, shader: str) -> None:
|
||||||
filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RDHeaderStruct] = None
|
include_file_in_rd_header(shader, header_data := RDHeaderStruct(), 0)
|
||||||
) -> None:
|
class_name = os.path.basename(shader).replace(".glsl", "").title().replace("_", "").replace(".", "") + "ShaderRD"
|
||||||
header_data = header_data or RDHeaderStruct()
|
|
||||||
include_file_in_rd_header(filename, header_data, 0)
|
|
||||||
|
|
||||||
if optional_output_filename is None:
|
|
||||||
out_file = filename + ".gen.h"
|
|
||||||
else:
|
|
||||||
out_file = optional_output_filename
|
|
||||||
|
|
||||||
out_file_base = out_file
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
|
||||||
out_file_class = out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "ShaderRD"
|
|
||||||
|
|
||||||
if header_data.compute_lines:
|
|
||||||
body_parts = [
|
|
||||||
"static const char _compute_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.compute_lines),
|
|
||||||
f'setup(nullptr, nullptr, _compute_code, "{out_file_class}");',
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
body_parts = [
|
|
||||||
"static const char _vertex_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.vertex_lines),
|
|
||||||
"static const char _fragment_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.fragment_lines),
|
|
||||||
f'setup(_vertex_code, _fragment_code, nullptr, "{out_file_class}");',
|
|
||||||
]
|
|
||||||
|
|
||||||
body_content = "\n\t\t".join(body_parts)
|
|
||||||
|
|
||||||
# Intended curly brackets are doubled so f-string doesn't eat them up.
|
|
||||||
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
with generated_wrapper(filename) as file:
|
||||||
|
file.write(f"""\
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
class {out_file_class} : public ShaderRD {{
|
class {class_name} : public ShaderRD {{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
{class_name}() {{
|
||||||
|
""")
|
||||||
|
|
||||||
{out_file_class}() {{
|
if header_data.compute_lines:
|
||||||
|
file.write(f"""\
|
||||||
|
static const char *_vertex_code = nullptr;
|
||||||
|
static const char *_fragment_code = nullptr;
|
||||||
|
static const char _compute_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.compute_lines)}
|
||||||
|
}};
|
||||||
|
""")
|
||||||
|
else:
|
||||||
|
file.write(f"""\
|
||||||
|
static const char _vertex_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.vertex_lines)}
|
||||||
|
}};
|
||||||
|
static const char _fragment_code[] = {{
|
||||||
|
{to_raw_cstring(header_data.fragment_lines)}
|
||||||
|
}};
|
||||||
|
static const char *_compute_code = nullptr;
|
||||||
|
""")
|
||||||
|
|
||||||
{body_content}
|
file.write(f"""\
|
||||||
|
setup(_vertex_code, _fragment_code, _compute_code, "{class_name}");
|
||||||
}}
|
}}
|
||||||
}};
|
}};
|
||||||
"""
|
""")
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
|
|
||||||
fd.write(shader_template)
|
|
||||||
|
|
||||||
|
|
||||||
def build_rd_headers(target, source, env):
|
def build_rd_headers(target, source, env):
|
||||||
env.NoCache(target)
|
env.NoCache(target)
|
||||||
for x in source:
|
for src in source:
|
||||||
build_rd_header(filename=str(x))
|
build_rd_header(f"{src}.gen.h", str(src))
|
||||||
|
|
||||||
|
|
||||||
class RAWHeaderStruct:
|
class RAWHeaderStruct:
|
||||||
@ -171,34 +158,18 @@ def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, dept
|
|||||||
line = fs.readline()
|
line = fs.readline()
|
||||||
|
|
||||||
|
|
||||||
def build_raw_header(
|
def build_raw_header(filename: str, shader: str) -> None:
|
||||||
filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RAWHeaderStruct] = None
|
include_file_in_raw_header(shader, header_data := RAWHeaderStruct(), 0)
|
||||||
):
|
|
||||||
header_data = header_data or RAWHeaderStruct()
|
|
||||||
include_file_in_raw_header(filename, header_data, 0)
|
|
||||||
|
|
||||||
if optional_output_filename is None:
|
with generated_wrapper(filename) as file:
|
||||||
out_file = filename + ".gen.h"
|
file.write(f"""\
|
||||||
else:
|
static const char {os.path.basename(shader).replace(".glsl", "_shader_glsl")}[] = {{
|
||||||
out_file = optional_output_filename
|
|
||||||
|
|
||||||
out_file_base = out_file.replace(".glsl.gen.h", "_shader_glsl")
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
|
|
||||||
out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
|
|
||||||
|
|
||||||
shader_template = f"""/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
static const char {out_file_base}[] = {{
|
|
||||||
{to_raw_cstring(header_data.code)}
|
{to_raw_cstring(header_data.code)}
|
||||||
}};
|
}};
|
||||||
"""
|
""")
|
||||||
|
|
||||||
with open(out_file, "w", encoding="utf-8", newline="\n") as f:
|
|
||||||
f.write(shader_template)
|
|
||||||
|
|
||||||
|
|
||||||
def build_raw_headers(target, source, env):
|
def build_raw_headers(target, source, env):
|
||||||
env.NoCache(target)
|
env.NoCache(target)
|
||||||
for x in source:
|
for src in source:
|
||||||
build_raw_header(filename=str(x))
|
build_raw_header(f"{src}.gen.h", str(src))
|
||||||
|
@ -1503,13 +1503,13 @@ def generated_wrapper(
|
|||||||
unassigned, the value is determined by file extension.
|
unassigned, the value is determined by file extension.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if guard is None:
|
|
||||||
guard = path.endswith((".h", ".hh", ".hpp", ".hxx", ".inc"))
|
|
||||||
|
|
||||||
with open(path, "wt", encoding="utf-8", newline="\n") as file:
|
with open(path, "wt", encoding="utf-8", newline="\n") as file:
|
||||||
|
if not path.endswith(".out"): # For test output, we only care about the content.
|
||||||
file.write(generate_copyright_header(path))
|
file.write(generate_copyright_header(path))
|
||||||
file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
|
file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
|
||||||
|
|
||||||
|
if guard is None:
|
||||||
|
guard = path.endswith((".h", ".hh", ".hpp", ".hxx", ".inc"))
|
||||||
if guard:
|
if guard:
|
||||||
file.write("#pragma once\n\n")
|
file.write("#pragma once\n\n")
|
||||||
|
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "drivers/gles3/shader_gles3.h"
|
#include "drivers/gles3/shader_gles3.h"
|
||||||
|
|
||||||
|
|
||||||
class VertexFragmentShaderGLES3 : public ShaderGLES3 {
|
class VertexFragmentShaderGLES3 : public ShaderGLES3 {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum ShaderVariant {
|
enum ShaderVariant {
|
||||||
MODE_NINEPATCH,
|
MODE_NINEPATCH,
|
||||||
};
|
};
|
||||||
@ -17,23 +10,21 @@ public:
|
|||||||
DISABLE_LIGHTING = 1,
|
DISABLE_LIGHTING = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant,uint64_t p_specialization=0) { return _version_bind_shader(p_version,p_variant,p_specialization); }
|
_FORCE_INLINE_ bool version_bind_shader(RID p_version, ShaderVariant p_variant, uint64_t p_specialization = 0) {
|
||||||
|
return _version_bind_shader(p_version, p_variant, p_specialization);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void _init() override {
|
virtual void _init() override {
|
||||||
|
|
||||||
static const char **_uniform_strings = nullptr;
|
static const char **_uniform_strings = nullptr;
|
||||||
static const char *_variant_defines[] = {
|
static const char *_variant_defines[] = {
|
||||||
"#define USE_NINEPATCH",
|
"#define USE_NINEPATCH",
|
||||||
};
|
};
|
||||||
|
|
||||||
static TexUnitPair *_texunit_pairs = nullptr;
|
static TexUnitPair *_texunit_pairs = nullptr;
|
||||||
static UBOPair *_ubo_pairs = nullptr;
|
static UBOPair *_ubo_pairs = nullptr;
|
||||||
static Specialization _spec_pairs[] = {
|
static Specialization _spec_pairs[] = {
|
||||||
{ "DISABLE_LIGHTING", false },
|
{ "DISABLE_LIGHTING", false },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const Feedback *_feedbacks = nullptr;
|
static const Feedback *_feedbacks = nullptr;
|
||||||
static const char _vertex_code[] = {
|
static const char _vertex_code[] = {
|
||||||
R"<!>(
|
R"<!>(
|
||||||
@ -65,7 +56,9 @@ void main() {
|
|||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
|
|
||||||
_setup(_vertex_code,_fragment_code,"VertexFragmentShaderGLES3",0,_uniform_strings,0,_ubo_pairs,0,_feedbacks,0,_texunit_pairs,1,_spec_pairs,1,_variant_defines);
|
_setup(_vertex_code, _fragment_code, "VertexFragmentShaderGLES3",
|
||||||
|
0, _uniform_strings, 0, _ubo_pairs,
|
||||||
|
0, _feedbacks, 0, _texunit_pairs,
|
||||||
|
1, _spec_pairs, 1, _variant_defines);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
static const char compute_shader_glsl[] = {
|
static const char compute_shader_glsl[] = {
|
||||||
R"<!>(#[compute]
|
R"<!>(#[compute]
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
static const char vertex_fragment_shader_glsl[] = {
|
static const char vertex_fragment_shader_glsl[] = {
|
||||||
R"<!>(#[versions]
|
R"<!>(#[versions]
|
||||||
|
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
class ComputeShaderRD : public ShaderRD {
|
class ComputeShaderRD : public ShaderRD {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ComputeShaderRD() {
|
ComputeShaderRD() {
|
||||||
|
static const char *_vertex_code = nullptr;
|
||||||
|
static const char *_fragment_code = nullptr;
|
||||||
static const char _compute_code[] = {
|
static const char _compute_code[] = {
|
||||||
R"<!>(
|
R"<!>(
|
||||||
#version 450
|
#version 450
|
||||||
@ -24,6 +20,6 @@ void main() {
|
|||||||
}
|
}
|
||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
setup(nullptr, nullptr, _compute_code, "ComputeShaderRD");
|
setup(_vertex_code, _fragment_code, _compute_code, "ComputeShaderRD");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "servers/rendering/renderer_rd/shader_rd.h"
|
#include "servers/rendering/renderer_rd/shader_rd.h"
|
||||||
|
|
||||||
class VertexFragmentShaderRD : public ShaderRD {
|
class VertexFragmentShaderRD : public ShaderRD {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VertexFragmentShaderRD() {
|
VertexFragmentShaderRD() {
|
||||||
|
|
||||||
static const char _vertex_code[] = {
|
static const char _vertex_code[] = {
|
||||||
R"<!>(
|
R"<!>(
|
||||||
#version 450
|
#version 450
|
||||||
@ -38,6 +32,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
)<!>"
|
)<!>"
|
||||||
};
|
};
|
||||||
setup(_vertex_code, _fragment_code, nullptr, "VertexFragmentShaderRD");
|
static const char *_compute_code = nullptr;
|
||||||
|
setup(_vertex_code, _fragment_code, _compute_code, "VertexFragmentShaderRD");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user