Skip to content

Commit 1847e41

Browse files
Copilotwysaid
andcommitted
Replace GL_TRIANGLE_FAN with GL_TRIANGLE_STRIP for better performance
Co-authored-by: wysaid <[email protected]>
1 parent a8137d4 commit 1847e41

21 files changed

+43
-43
lines changed

library/src/main/java/org/wysaid/common/TextureDrawer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class TextureDrawer {
3333
" gl_FragColor = texture2D(inputImageTexture, texCoord);\n" +
3434
"}";
3535

36-
public static final float[] vertices = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f};
37-
public static final int DRAW_FUNCTION = GLES20.GL_TRIANGLE_FAN;
36+
public static final float[] vertices = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
37+
public static final int DRAW_FUNCTION = GLES20.GL_TRIANGLE_STRIP;
3838

3939
protected ProgramObject mProgram;
4040
protected int mVertBuffer;

library/src/main/java/org/wysaid/gpuCodec/TextureDrawerI420ToRGB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void drawTextures() {
6262
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertBuffer);
6363
GLES20.glEnableVertexAttribArray(0);
6464
GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 0, 0);
65-
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4);
65+
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
6666
}
6767

6868
public void drawTextures(int texY, int texU, int texV) {

library/src/main/java/org/wysaid/gpuCodec/TextureDrawerNV21ToRGB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void drawTextures() {
5959
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertBuffer);
6060
GLES20.glEnableVertexAttribArray(0);
6161
GLES20.glVertexAttribPointer(0, 2, GLES20.GL_FLOAT, false, 0, 0);
62-
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4);
62+
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
6363
}
6464

6565
public void drawTextures(int texY, int texUV) {

library/src/main/java/org/wysaid/texUtils/TextureRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public Viewport(int _x, int _y, int _width, int _height) {
7777
protected static final String FLIPSCALE_NAME = "flipScale";
7878
protected static final String TRANSFORM_NAME = "transform";
7979

80-
public static final float[] vertices = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f};
81-
public static final int DRAW_FUNCTION = GLES20.GL_TRIANGLE_FAN;
80+
public static final float[] vertices = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
81+
public static final int DRAW_FUNCTION = GLES20.GL_TRIANGLE_STRIP;
8282

8383
protected int TEXTURE_2D_BINDABLE;
8484

library/src/main/jni/cge/common/cgeGlobal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool g_shouldUsePBO = true;
3030
int CGEGlobalConfig::viewWidth = 1024;
3131
int CGEGlobalConfig::viewHeight = 768;
3232
GLuint CGEGlobalConfig::sVertexBufferCommon = 0;
33-
float CGEGlobalConfig::sVertexDataCommon[8] = { -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f };
33+
float CGEGlobalConfig::sVertexDataCommon[8] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f };
3434

3535
void cgeInitFilterStatus()
3636
{

library/src/main/jni/cge/common/cgeImageFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void CGEImageFilterInterface::render2Texture(CGEImageHandlerInterface* handler,
177177
if (m_uniformParam != nullptr)
178178
m_uniformParam->assignUniforms(handler, m_program.programID());
179179

180-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
180+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
181181
cgeCheckGLError("glDrawArrays");
182182
}
183183

library/src/main/jni/cge/common/cgeTextureUtils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void TextureDrawer::drawTexture(GLuint src)
419419
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
420420

421421
m_program.bind();
422-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
422+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
423423
}
424424

425425
void TextureDrawer::setRotation(float rad)
@@ -590,7 +590,7 @@ void TextureDrawer4ExtOES::drawTexture(GLuint src)
590590
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
591591

592592
m_program.bind();
593-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
593+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
594594
}
595595
#endif
596596

@@ -622,7 +622,7 @@ void TextureDrawerYUV::drawTextures()
622622
glBindBuffer(GL_ARRAY_BUFFER, m_vertBuffer);
623623
glEnableVertexAttribArray(0);
624624
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
625-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
625+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
626626
}
627627

628628
CGEConstString TextureDrawerYUV::getFragmentShaderString()
@@ -765,7 +765,7 @@ void CGELerpBlurUtil::calcWithTexture(GLuint texture, int width, int height, GLu
765765
m_framebuffer.bindTexture2D(m_texCache[0].texID);
766766
glBindTexture(GL_TEXTURE_2D, texture);
767767
glViewport(0, 0, m_texCache[0].size.width, m_texCache[0].size.height);
768-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
768+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
769769
glFlush();
770770

771771
// down scale
@@ -776,7 +776,7 @@ void CGELerpBlurUtil::calcWithTexture(GLuint texture, int width, int height, GLu
776776
glViewport(0, 0, texCache.size.width, texCache.size.height);
777777

778778
glBindTexture(GL_TEXTURE_2D, m_texCache[i - 1].texID);
779-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
779+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
780780
glFlush();
781781
}
782782

@@ -788,7 +788,7 @@ void CGELerpBlurUtil::calcWithTexture(GLuint texture, int width, int height, GLu
788788
glViewport(0, 0, texCache.size.width, texCache.size.height);
789789

790790
glBindTexture(GL_TEXTURE_2D, m_texCache[i].texID);
791-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
791+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
792792
glFlush();
793793
}
794794

@@ -797,7 +797,7 @@ void CGELerpBlurUtil::calcWithTexture(GLuint texture, int width, int height, GLu
797797
m_framebuffer.bindTexture2D(target);
798798
glViewport(0, 0, targetWidth, targetHeight);
799799
glBindTexture(GL_TEXTURE_2D, m_texCache[0].texID);
800-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
800+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
801801
}
802802
}
803803

@@ -809,7 +809,7 @@ void CGELerpBlurUtil::drawTexture(GLuint texID)
809809
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
810810
glActiveTexture(GL_TEXTURE0);
811811
glBindTexture(GL_TEXTURE_2D, texID);
812-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
812+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
813813
}
814814

815815
void CGELerpBlurUtil::_clearMipmaps()

library/src/main/jni/cge/filters/cgeAdvancedEffectsCommon.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void CGEAdvancedEffectOneStepFilterHelper::render2Texture(CGEImageHandlerInterfa
2828
CGESizei sz = handler->getOutputFBOSize();
2929
m_program.sendUniformf(paramStepsName, 1.0f / sz.width, 1.0f / sz.height);
3030
}
31-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
31+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
3232
cgeCheckGLError("glDrawArrays");
3333
}
3434

@@ -51,7 +51,7 @@ void CGEAdvancedEffectTwoStepFilterHelper::render2Texture(CGEImageHandlerInterfa
5151
glBindTexture(GL_TEXTURE_2D, srcTexture);
5252

5353
m_program.sendUniformf(paramStepsName, 0.0f, 1.0f / sz.height);
54-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
54+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
5555
}
5656
// Pass Two
5757
handler->swapBufferFBO();
@@ -61,7 +61,7 @@ void CGEAdvancedEffectTwoStepFilterHelper::render2Texture(CGEImageHandlerInterfa
6161
glBindTexture(GL_TEXTURE_2D, handler->getBufferTextureID());
6262

6363
m_program.sendUniformf(paramStepsName, 1.0f / sz.width, 0.0f);
64-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
64+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
6565
}
6666

6767
} // namespace CGE

library/src/main/jni/cge/filters/cgeBlendFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ void CGEBlendTileFilter::render2Texture(CGEImageHandlerInterface* handler, GLuin
921921

922922
if (m_uniformParam != nullptr)
923923
m_uniformParam->assignUniforms(handler, m_program.programID());
924-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
924+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
925925
cgeCheckGLError("glDrawArrays");
926926
}
927927

library/src/main/jni/cge/filters/cgeDynamicWaveFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void CGEDynamicWaveFilter::render2Texture(CGEImageHandlerInterface* handler, GLu
6868
if (m_uniformParam != nullptr)
6969
m_uniformParam->assignUniforms(handler, m_program.programID());
7070

71-
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
71+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
7272
cgeCheckGLError("glDrawArrays");
7373
}
7474

0 commit comments

Comments
 (0)