From 9aac9ccc1e29c92307066e65f24a07e0686eeae0 Mon Sep 17 00:00:00 2001 From: tyBrave Date: Tue, 7 Feb 2023 17:40:35 +0800 Subject: [PATCH] update code because of function than 50 lines Signed-off-by: tyBrave --- .../src/main/cpp/render/EGLRender.cpp | 57 ++++++++----------- gpu_transform/src/main/cpp/render/EGLRender.h | 2 +- gpu_transform/src/main/cpp/util/GLUtils.cpp | 2 +- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/gpu_transform/src/main/cpp/render/EGLRender.cpp b/gpu_transform/src/main/cpp/render/EGLRender.cpp index fc9ee69..72a4eb4 100644 --- a/gpu_transform/src/main/cpp/render/EGLRender.cpp +++ b/gpu_transform/src/main/cpp/render/EGLRender.cpp @@ -396,6 +396,23 @@ EGLRender::EGLRender() EGLRender::~EGLRender() { } +void EGLRender::TexturesInit() +{ + glGenTextures(1, &m_ImageTextureId); // 生成纹理名称 + glBindTexture(GL_TEXTURE_2D, m_ImageTextureId); // 允许建立一个绑定到目标纹理的有名称的纹理 + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, GL_NONE); + glGenTextures(1, &m_FboTextureId); + glBindTexture(GL_TEXTURE_2D, m_FboTextureId); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, GL_NONE); +} void EGLRender::Init() { if (CreateGlEnv() == 0) { @@ -404,21 +421,7 @@ void EGLRender::Init() if (!m_IsGLContextReady) { return; } - glGenTextures(1, &m_ImageTextureId); // 生成纹理名称 - glBindTexture(GL_TEXTURE_2D, m_ImageTextureId); // 允许建立一个绑定到目标纹理的有名称的纹理 - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glBindTexture(GL_TEXTURE_2D, GL_NONE); - - glGenTextures(1, &m_FboTextureId); - glBindTexture(GL_TEXTURE_2D, m_FboTextureId); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glBindTexture(GL_TEXTURE_2D, GL_NONE); + EGLRender::GetInstance() -> TexturesInit(); m_ProgramObj = GLUtils::CreateProgram(vShaderStr, fShaderStr0, m_VertexShader, m_FragmentShader); if (!m_ProgramObj) { @@ -428,15 +431,12 @@ void EGLRender::Init() glGenBuffers(DEFAULT_THREE, m_VboIds); glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]); glBufferData(GL_ARRAY_BUFFER, sizeof(vVertices), vVertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ONE]); glBufferData(GL_ARRAY_BUFFER, sizeof(vFboTexCoors), vTexCoors, GL_STATIC_DRAW); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VboIds[DEFAULT_TWO]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glGenVertexArrays(DEFAULT_ONE, m_VaoIds); glBindVertexArray(m_VaoIds[DEFAULT_ZERO]); - glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]); glEnableVertexAttribArray(VERTEX_POS_LOC); glVertexAttribPointer(VERTEX_POS_LOC, @@ -445,7 +445,6 @@ void EGLRender::Init() DEFAULT_THREE * sizeof(GLfloat), (const void *)DEFAULT_ZERO); glBindBuffer(GL_ARRAY_BUFFER, GL_NONE); - glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ONE]); glEnableVertexAttribArray(TEXTURE_POS_LOC); glVertexAttribPointer(TEXTURE_POS_LOC, @@ -455,7 +454,6 @@ void EGLRender::Init() DEFAULT_TWO * sizeof(GLfloat), (const void *)DEFAULT_ZERO); glBindBuffer(GL_ARRAY_BUFFER, GL_NONE); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VboIds[DEFAULT_TWO]); glBindVertexArray(GL_NONE); } @@ -463,24 +461,15 @@ void EGLRender::Init() int EGLRender::CreateGlEnv() { const EGLint confAttr[] = { - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_STENCIL_SIZE, 8, - EGL_NONE + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 8, EGL_NONE }; const EGLint ctxAttr[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE + EGL_CONTEXT_CLIENT_VERSION, 2,EGL_NONE }; const EGLint surfaceAttr[] = { - EGL_WIDTH, 1, - EGL_HEIGHT, 1, - EGL_NONE + EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; EGLint eglMajVers, eglMinVers; EGLint numConfigs; diff --git a/gpu_transform/src/main/cpp/render/EGLRender.h b/gpu_transform/src/main/cpp/render/EGLRender.h index 4947f9b..411c397 100644 --- a/gpu_transform/src/main/cpp/render/EGLRender.h +++ b/gpu_transform/src/main/cpp/render/EGLRender.h @@ -71,7 +71,7 @@ public: static napi_value setTypeArrayOfMatrix4f(napi_env env, napi_callback_info info); void Init(); - + void TexturesInit(); int CreateGlEnv(); void SetImageData(uint8_t *pData, int width, int height); diff --git a/gpu_transform/src/main/cpp/util/GLUtils.cpp b/gpu_transform/src/main/cpp/util/GLUtils.cpp index fdeb4a5..9850f73 100644 --- a/gpu_transform/src/main/cpp/util/GLUtils.cpp +++ b/gpu_transform/src/main/cpp/util/GLUtils.cpp @@ -21,8 +21,8 @@ #include #include -#include "GLUtils.h" #include "DebugLog.h" +#include "GLUtils.h" GLuint GLUtils::LoadShader(GLenum shaderType, const char *pSource) {