mcst-linux-kernel/patches-2024.06.26/gl4es-1.1.4/0088-GLES2-added-gl_ClipVer...

73 lines
2.7 KiB
Diff

From 868354d900cae934130abbde1a05074067661ddc Mon Sep 17 00:00:00 2001
From: ptitSeb <sebastien.chev@gmail.com>
Date: Thu, 29 Oct 2020 17:32:18 +0100
Subject: [PATCH 088/233] [GLES2] added gl_ClipVertex handling even without use
clip planes (for #215)
---
src/gl/shader.c | 2 +-
src/gl/shader.h | 1 +
src/gl/shaderconv.c | 13 +++++++++++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/gl/shader.c b/src/gl/shader.c
index be1b0a10..7638b25d 100755
--- a/src/gl/shader.c
+++ b/src/gl/shader.c
@@ -195,8 +195,8 @@ void gl4es_glShaderSource(GLuint shader, GLsizei count, const GLchar * const *st
GO(mvpmatrix) \
GO(notexarray) \
GO(clean) \
+ GO(clipvertex) \
GO2(texs)
-// not testing need_clipvertex as this stay in vertexshader
void accumShaderNeeds(GLuint shader, shaderconv_need_t *need) {
CHECK_SHADER(void, shader)
diff --git a/src/gl/shader.h b/src/gl/shader.h
index 3d36dae3..2cac386f 100755
--- a/src/gl/shader.h
+++ b/src/gl/shader.h
@@ -15,6 +15,7 @@ typedef struct shaderconv_need_s {
int need_mvmatrix;
int need_mvpmatrix;
int need_clean; // this shader needs to stay "clean", no hack in here
+ int need_clipvertex;
uint32_t need_texs; // flags of what tex is needed
} shaderconv_need_t;
diff --git a/src/gl/shaderconv.c b/src/gl/shaderconv.c
index 2d2b7738..40b97d7c 100755
--- a/src/gl/shaderconv.c
+++ b/src/gl/shaderconv.c
@@ -269,6 +269,10 @@ static const char* gl4es_ClipVertex =
static const char* gl4es_ClipVertexSource =
"gl4es_ClipVertex";
+static const char* gl4es_ClipVertex_clip =
+"\nif(any(lessThanEqual(gl4es_ClipVertex.xyz, vec3(-gl4es_ClipVertex.w)))"
+" || any(greaterThanEqual(gl4es_ClipVertex.xyz, vec3(gl4es_ClipVertex.w)))) discard;\n";
+
static const char* gl_TexCoordSource = "gl_TexCoord[";
static const char* gl_TexMatrixSources[] = {
@@ -1085,6 +1089,15 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_ClipVertex, Tmp, &tmpsize);
headline+=CountLine(gl4es_ClipVertex);
Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ClipVertex", gl4es_ClipVertexSource);
+ need->need_clipvertex = 1;
+ } else if(isVertex && need && need->need_clipvertex) {
+ Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_ClipVertex, Tmp, &tmpsize);
+ headline+=CountLine(gl4es_ClipVertex);
+ char *p = strchr(FindStringNC(Tmp, "main"), '{'); // find the openning curly bracket of main
+ if(p) {
+ // add regular clipping at start of main
+ Tmp = InplaceInsert(p+1, gl4es_ClipVertex_clip, Tmp, &tmpsize);
+ }
}
//oldprogram uniforms...
if(FindString(Tmp, gl_ProgramEnv)) {
--
2.11.0