update code,because of line space
Signed-off-by: tyBrave <tianyong13@huawei.com>
This commit is contained in:
parent
d18694a96e
commit
a241953878
|
@ -49,9 +49,7 @@ static napi_value Add(napi_env env, napi_callback_info info)
|
||||||
|
|
||||||
napi_value sum;
|
napi_value sum;
|
||||||
napi_create_double(env, value0 + value1, &sum);
|
napi_create_double(env, value0 + value1, &sum);
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static napi_value Init(napi_env env, napi_value exports)
|
static napi_value Init(napi_env env, napi_value exports)
|
||||||
|
|
|
@ -404,7 +404,6 @@ void EGLRender::Init()
|
||||||
if (!m_IsGLContextReady) {
|
if (!m_IsGLContextReady) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &m_ImageTextureId); // 生成纹理名称
|
glGenTextures(1, &m_ImageTextureId); // 生成纹理名称
|
||||||
glBindTexture(GL_TEXTURE_2D, 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_S, GL_REPEAT);
|
||||||
|
@ -420,15 +419,12 @@ void EGLRender::Init()
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||||
|
|
||||||
m_ProgramObj = GLUtils::CreateProgram(vShaderStr, fShaderStr0, m_VertexShader,
|
m_ProgramObj = GLUtils::CreateProgram(vShaderStr, fShaderStr0, m_VertexShader,
|
||||||
m_FragmentShader);
|
m_FragmentShader);
|
||||||
if (!m_ProgramObj) {
|
if (!m_ProgramObj) {
|
||||||
GLUtils::CheckGLError("Create Program");
|
GLUtils::CheckGLError("Create Program");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate VBO Ids and load the VBOs width data
|
|
||||||
glGenBuffers(DEFAULT_THREE, m_VboIds);
|
glGenBuffers(DEFAULT_THREE, m_VboIds);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]);
|
glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vVertices), vVertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vVertices), vVertices, GL_STATIC_DRAW);
|
||||||
|
@ -438,11 +434,7 @@ void EGLRender::Init()
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VboIds[DEFAULT_TWO]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_VboIds[DEFAULT_TWO]);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
// Generate VAO Ids
|
|
||||||
glGenVertexArrays(DEFAULT_ONE, m_VaoIds);
|
glGenVertexArrays(DEFAULT_ONE, m_VaoIds);
|
||||||
|
|
||||||
// FBO off screen rendering VAO
|
|
||||||
glBindVertexArray(m_VaoIds[DEFAULT_ZERO]);
|
glBindVertexArray(m_VaoIds[DEFAULT_ZERO]);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]);
|
glBindBuffer(GL_ARRAY_BUFFER, m_VboIds[DEFAULT_ZERO]);
|
||||||
|
@ -470,8 +462,7 @@ void EGLRender::Init()
|
||||||
|
|
||||||
int EGLRender::CreateGlEnv()
|
int EGLRender::CreateGlEnv()
|
||||||
{
|
{
|
||||||
const EGLint confAttr[] =
|
const EGLint confAttr[] = {
|
||||||
{
|
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
|
||||||
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
||||||
EGL_RED_SIZE, 8,
|
EGL_RED_SIZE, 8,
|
||||||
|
@ -482,15 +473,11 @@ int EGLRender::CreateGlEnv()
|
||||||
EGL_STENCIL_SIZE, 8,
|
EGL_STENCIL_SIZE, 8,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
// EGL context attributes
|
const EGLint ctxAttr[] = {
|
||||||
const EGLint ctxAttr[] =
|
|
||||||
{
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
const EGLint surfaceAttr[] = {
|
||||||
const EGLint surfaceAttr[] =
|
|
||||||
{
|
|
||||||
EGL_WIDTH, 1,
|
EGL_WIDTH, 1,
|
||||||
EGL_HEIGHT, 1,
|
EGL_HEIGHT, 1,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
|
@ -504,64 +491,37 @@ int EGLRender::CreateGlEnv()
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化 egl 方法
|
// 初始化 egl 方法
|
||||||
if (!eglInitialize(m_eglDisplay, &eglMajVers, &eglMinVers)) {
|
if (!eglInitialize(m_eglDisplay, &eglMajVers, &eglMinVers)) {
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取 EGLConfig 对象,确定渲染表面的配置信息
|
// 获取 EGLConfig 对象,确定渲染表面的配置信息
|
||||||
if (!eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, 1, &numConfigs)) {
|
if (!eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, 1, &numConfigs)) {
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建渲染表面 EGLSurface 使用 eglCreateBufferSurface 创建屏幕外渲染区域
|
// 创建渲染表面 EGLSurface 使用 eglCreateBufferSurface 创建屏幕外渲染区域
|
||||||
m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
|
m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
|
||||||
if (m_eglSurface == EGL_NO_SURFACE) {
|
if (m_eglSurface == EGL_NO_SURFACE) {
|
||||||
switch(eglGetError()) {
|
|
||||||
case EGL_BAD_ALLOC:
|
|
||||||
LOGI("gl-->::CreateGlesEnv Not enough resources available");
|
|
||||||
break;
|
|
||||||
case EGL_BAD_CONFIG:
|
|
||||||
LOGI("gl-->::CreateGlesEnv provided EGLConfig is invalid");
|
|
||||||
break;
|
|
||||||
case EGL_BAD_PARAMETER:
|
|
||||||
LOGI("gl-->::CreateGlesEnv provided EGL_WIDTH and EGL_HEIGHT is invalid");
|
|
||||||
break;
|
|
||||||
case EGL_BAD_MATCH:
|
|
||||||
LOGI("gl-->::CreateGlesEnv Check window and EGLConfig attributes");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOGI("gl-->::CreateGlesEnv happen default error");
|
LOGI("gl-->::CreateGlesEnv happen default error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 创建渲染上下文 EGLContext
|
// 创建渲染上下文 EGLContext
|
||||||
m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
|
m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
|
||||||
if (m_eglCtx == EGL_NO_CONTEXT) {
|
if (m_eglCtx == EGL_NO_CONTEXT) {
|
||||||
EGLint error = eglGetError();
|
EGLint error = eglGetError();
|
||||||
if (error == EGL_BAD_CONFIG) {
|
if (error == EGL_BAD_CONFIG) {
|
||||||
LOGI("gl-->::CreateGlesEnv EGL_BAD_CONFIG");
|
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绑定上下文
|
// 绑定上下文
|
||||||
if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx)) {
|
if (!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx)) {
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LOGI("gl-->::CreateGlesEnv initialize success");
|
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
if (resultCode != 0) {
|
|
||||||
LOGI("gl-->::CreateGlesEnv fail");
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultCode;
|
return resultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,7 +643,6 @@ void EGLRender::SetIntParams(int paramType, int param)
|
||||||
vShader[0] = vShaderStr;
|
vShader[0] = vShaderStr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ProgramObj = GLUtils::CreateProgram(vShader[0], fShader[0], m_VertexShader,
|
m_ProgramObj = GLUtils::CreateProgram(vShader[0], fShader[0], m_VertexShader,
|
||||||
m_FragmentShader);
|
m_FragmentShader);
|
||||||
if (!m_ProgramObj) {
|
if (!m_ProgramObj) {
|
||||||
|
@ -691,7 +650,6 @@ void EGLRender::SetIntParams(int paramType, int param)
|
||||||
LOGI("gl--> EGLRender::SetIntParams Could not create program.");
|
LOGI("gl--> EGLRender::SetIntParams Could not create program.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_SamplerLoc = glGetUniformLocation(m_ProgramObj, "s_TextureMap");
|
m_SamplerLoc = glGetUniformLocation(m_ProgramObj, "s_TextureMap");
|
||||||
m_TexSizeLoc = glGetUniformLocation(m_ProgramObj, "u_texSize");
|
m_TexSizeLoc = glGetUniformLocation(m_ProgramObj, "u_texSize");
|
||||||
}
|
}
|
||||||
|
@ -704,7 +662,9 @@ void EGLRender::SetIntParams(int paramType, int param)
|
||||||
|
|
||||||
void EGLRender::UseProgram()
|
void EGLRender::UseProgram()
|
||||||
{
|
{
|
||||||
if (m_ProgramObj == GL_NONE) return;
|
if (m_ProgramObj == GL_NONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,7 @@ public:
|
||||||
|
|
||||||
static EGLRender* GetInstance()
|
static EGLRender* GetInstance()
|
||||||
{
|
{
|
||||||
if(sInstance == nullptr)
|
if (sInstance == nullptr) {
|
||||||
{
|
|
||||||
sInstance = new EGLRender();
|
sInstance = new EGLRender();
|
||||||
}
|
}
|
||||||
return sInstance;
|
return sInstance;
|
||||||
|
@ -46,8 +45,7 @@ public:
|
||||||
|
|
||||||
static void DestroyRender()
|
static void DestroyRender()
|
||||||
{
|
{
|
||||||
if (sInstance)
|
if (sInstance) {
|
||||||
{
|
|
||||||
delete sInstance;
|
delete sInstance;
|
||||||
sInstance = nullptr;
|
sInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue