update code,because of code check
Signed-off-by: tyBrave <tianyong13@huawei.com>
This commit is contained in:
parent
57d773e582
commit
83014e5457
|
@ -30,7 +30,7 @@
|
||||||
napi_get_last_error_info((env),&errorInfo); \
|
napi_get_last_error_info((env),&errorInfo); \
|
||||||
bool isPending = false; \
|
bool isPending = false; \
|
||||||
napi_is_exception_pending((env),&isPending); \
|
napi_is_exception_pending((env),&isPending); \
|
||||||
if(!isPending && errorInfo != nullptr) { \
|
if (!isPending && errorInfo != nullptr) { \
|
||||||
const char* errorMessage = \
|
const char* errorMessage = \
|
||||||
errorInfo->error_message != nullptr ? errorInfo->error_message : "empty error message"; \
|
errorInfo->error_message != nullptr ? errorInfo->error_message : "empty error message"; \
|
||||||
napi_throw_error((env),nullptr,errorMessage); \
|
napi_throw_error((env),nullptr,errorMessage); \
|
||||||
|
|
|
@ -115,8 +115,7 @@ const char v3x3ShaderStr[] =
|
||||||
"bottomRightTextureCoordinate = a_texCoord + widthHeightStep;\n"
|
"bottomRightTextureCoordinate = a_texCoord + widthHeightStep;\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
// kuwahara
|
||||||
//kuwahara
|
|
||||||
const char fShaderStr3[] =
|
const char fShaderStr3[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -201,8 +200,7 @@ const char fShaderStr3[] =
|
||||||
"}\n"
|
"}\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
// 旋转
|
||||||
//旋转
|
|
||||||
const char swirlFShaderStr[] =
|
const char swirlFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -228,8 +226,7 @@ const char swirlFShaderStr[] =
|
||||||
"outColor = texture(s_TextureMap, tc / u_texSize);\n"
|
"outColor = texture(s_TextureMap, tc / u_texSize);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
// 亮度
|
||||||
//亮度
|
|
||||||
const char brightFShaderStr[] =
|
const char brightFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -246,7 +243,7 @@ const char brightFShaderStr[] =
|
||||||
"outColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);\n"
|
"outColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//反转
|
// 反转
|
||||||
const char contrastFShaderStr[] =
|
const char contrastFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -263,7 +260,7 @@ const char contrastFShaderStr[] =
|
||||||
"outColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n"
|
"outColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//invert
|
// invert
|
||||||
const char invertFShaderStr[] =
|
const char invertFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -279,7 +276,7 @@ const char invertFShaderStr[] =
|
||||||
"outColor = vec4((1.0 - textureColor.rgb), textureColor.w);\n"
|
"outColor = vec4((1.0 - textureColor.rgb), textureColor.w);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//pixel
|
// pixel
|
||||||
const char pixelFShaderStr[] =
|
const char pixelFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -300,7 +297,7 @@ const char pixelFShaderStr[] =
|
||||||
"outColor = vec4(tc, 1.0);\n"
|
"outColor = vec4(tc, 1.0);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//vignette
|
// vignette
|
||||||
const char vignetteFShaderStr[] =
|
const char vignetteFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -326,8 +323,7 @@ const char vignetteFShaderStr[] =
|
||||||
"outColor = vec4(mix(rgb2.x,vignetteColor.x,percent), mix(rgb2.y, vignetteColor.y, percent), mix(rgb2.z, vignetteColor.z, percent), 1.0);\n"
|
"outColor = vec4(mix(rgb2.x,vignetteColor.x,percent), mix(rgb2.y, vignetteColor.y, percent), mix(rgb2.z, vignetteColor.z, percent), 1.0);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
// ColorMatrix
|
||||||
//ColorMatrix
|
|
||||||
const char colorMatrixFShaderStr[] =
|
const char colorMatrixFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -344,8 +340,7 @@ const char colorMatrixFShaderStr[] =
|
||||||
"outColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor);\n"
|
"outColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
// toon
|
||||||
//toon
|
|
||||||
const char toonFShaderStr[] =
|
const char toonFShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -386,9 +381,7 @@ const char toonFShaderStr[] =
|
||||||
"outColor = vec4(posterizedImageColor * thresholdTest, textureColor.a);\n"
|
"outColor = vec4(posterizedImageColor * thresholdTest, textureColor.a);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
// grayScale
|
||||||
|
|
||||||
//grayScale
|
|
||||||
const char grayScaleShaderStr[] =
|
const char grayScaleShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -403,7 +396,7 @@ const char grayScaleShaderStr[] =
|
||||||
"outColor = vec4(vec3(luminance), textureColor.a);\n"
|
"outColor = vec4(vec3(luminance), textureColor.a);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//sketch
|
// sketch
|
||||||
const char sketchShaderStr[] =
|
const char sketchShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -438,7 +431,7 @@ const char sketchShaderStr[] =
|
||||||
"outColor = vec4(vec3(mag), 1.0);\n"
|
"outColor = vec4(vec3(mag), 1.0);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//blur
|
// blur
|
||||||
const char blurShaderStr[] =
|
const char blurShaderStr[] =
|
||||||
"#version 300 es\n"
|
"#version 300 es\n"
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
|
@ -480,4 +473,4 @@ const char blurShaderStr[] =
|
||||||
"outColor = vec4(finalColor, sourceColor.a);\n"
|
"outColor = vec4(finalColor, sourceColor.a);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
#endif //GPU_ImageETS_constant_shape_H
|
#endif // GPU_ImageETS_constant_shape_H
|
||||||
|
|
|
@ -63,7 +63,6 @@ static napi_value Init(napi_env env, napi_value exports) {
|
||||||
DECLARE_NAPI_FUNCTION("EglIsInit",EGLRender:: EGLIsInit),
|
DECLARE_NAPI_FUNCTION("EglIsInit",EGLRender:: EGLIsInit),
|
||||||
DECLARE_NAPI_FUNCTION("EglDestroy",EGLRender:: DestroyGlesEnv),
|
DECLARE_NAPI_FUNCTION("EglDestroy",EGLRender:: DestroyGlesEnv),
|
||||||
|
|
||||||
|
|
||||||
DECLARE_NAPI_FUNCTION("EglUseProgram",EGLRender:: StartUseProgram),
|
DECLARE_NAPI_FUNCTION("EglUseProgram",EGLRender:: StartUseProgram),
|
||||||
DECLARE_NAPI_FUNCTION("EglRendering",EGLRender:: Rendering),
|
DECLARE_NAPI_FUNCTION("EglRendering",EGLRender:: Rendering),
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
#include "EGLRender.h"
|
#include "EGLRender.h"
|
||||||
|
|
||||||
#include "native_common.h"
|
|
||||||
#include <js_native_api.h>
|
#include <js_native_api.h>
|
||||||
#include <napi/native_api.h>
|
#include <napi/native_api.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -30,6 +29,7 @@
|
||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <js_native_api_types.h>
|
#include <js_native_api_types.h>
|
||||||
|
#include "native_common.h"
|
||||||
#include "DebugLog.h"
|
#include "DebugLog.h"
|
||||||
#include "constant/constant_shape.h"
|
#include "constant/constant_shape.h"
|
||||||
#include "GLUtils.h"
|
#include "GLUtils.h"
|
||||||
|
@ -44,34 +44,35 @@ const int TEXTURE_POS_LOC = 1;
|
||||||
const int32_t STR_DEFAULT_SIZE = 1024;
|
const int32_t STR_DEFAULT_SIZE = 1024;
|
||||||
EGLRender *EGLRender::sInstance = nullptr;
|
EGLRender *EGLRender::sInstance = nullptr;
|
||||||
|
|
||||||
//顶点坐标
|
// 顶点坐标
|
||||||
const GLfloat vVertices[] = {
|
const GLfloat vVertices[] = {
|
||||||
-1.0f, -1.0f, 0.0f, //bottom left
|
-1.0f, -1.0f, 0.0f, // bottom left
|
||||||
1.0f, -1.0f, 0.0f, //bottom right
|
1.0f, -1.0f, 0.0f, // bottom right
|
||||||
-1.0f, 1.0f, 0.0f, //top left
|
-1.0f, 1.0f, 0.0f, // top left
|
||||||
1.0f, 1.0f, 0.0f, //top right
|
1.0f, 1.0f, 0.0f, // top right
|
||||||
};
|
};
|
||||||
|
|
||||||
//正常纹理坐标
|
// 正常纹理坐标
|
||||||
const GLfloat vTexCoors[] = {
|
const GLfloat vTexCoors[] = {
|
||||||
0.0f, 1.0f, //bottom left
|
0.0f, 1.0f, // bottom left
|
||||||
1.0f, 1.0f, //bottom right
|
1.0f, 1.0f, // bottom right
|
||||||
0.0f, 0.0f, //top left
|
0.0f, 0.0f, // top left
|
||||||
1.0f, 0.0f, //top right
|
1.0f, 0.0f, // top right
|
||||||
};
|
};
|
||||||
|
|
||||||
//fbo 纹理坐标与正常纹理方向不同(上下镜像)
|
// fbo 纹理坐标与正常纹理方向不同(上下镜像)
|
||||||
const GLfloat vFboTexCoors[] = {
|
const GLfloat vFboTexCoors[] = {
|
||||||
0.0f, 0.0f, //bottom left
|
0.0f, 0.0f, // bottom left
|
||||||
1.0f, 0.0f, //bottom right
|
1.0f, 0.0f, // bottom right
|
||||||
0.0f, 1.0f, //top left
|
0.0f, 1.0f, // top left
|
||||||
1.0f, 1.0f, //top right
|
1.0f, 1.0f, // top right
|
||||||
};
|
};
|
||||||
|
|
||||||
const GLushort indices[] = { 0, 1, 2, 1, 3, 2 };
|
const GLushort indices[] = { 0, 1, 2, 1, 3, 2 };
|
||||||
|
|
||||||
|
|
||||||
napi_value EGLRender::RenderInit(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::RenderInit(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
napi_value exports;
|
napi_value exports;
|
||||||
|
|
||||||
NAPI_CALL(env, napi_create_object(env, &exports));
|
NAPI_CALL(env, napi_create_object(env, &exports));
|
||||||
|
@ -85,7 +86,8 @@ napi_value EGLRender::RenderInit(napi_env env, napi_callback_info info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
napi_value EGLRender::RenderSetData(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::RenderSetData(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
size_t argc = 3;
|
size_t argc = 3;
|
||||||
napi_value args[3] = { nullptr };
|
napi_value args[3] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
@ -93,19 +95,22 @@ napi_value EGLRender::RenderSetData(napi_env env, napi_callback_info info) {
|
||||||
void* buffer;
|
void* buffer;
|
||||||
size_t bufferLength;
|
size_t bufferLength;
|
||||||
napi_status buffStatus = napi_get_arraybuffer_info(env, args[0], &buffer, &bufferLength);
|
napi_status buffStatus = napi_get_arraybuffer_info(env, args[0], &buffer, &bufferLength);
|
||||||
if (buffStatus != napi_ok) {
|
if (buffStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* uint8_buf = reinterpret_cast<uint8_t *>(buffer);
|
uint8_t* uint8_buf = reinterpret_cast<uint8_t *>(buffer);
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
napi_status wStatus = napi_get_value_uint32(env, args[1], &width);
|
napi_status wStatus = napi_get_value_uint32(env, args[1], &width);
|
||||||
if (wStatus != napi_ok) {
|
if (wStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
napi_status hStatus = napi_get_value_uint32(env, args[2], &height);
|
napi_status hStatus = napi_get_value_uint32(env, args[2], &height);
|
||||||
if (hStatus != napi_ok) {
|
if (hStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +118,8 @@ napi_value EGLRender::RenderSetData(napi_env env, napi_callback_info info) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::RenderSetIntParams(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::RenderSetIntParams(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
LOGI("gl--> RenderSetIntParams start");
|
LOGI("gl--> RenderSetIntParams start");
|
||||||
size_t argc = 2;
|
size_t argc = 2;
|
||||||
napi_value args[2] = { nullptr };
|
napi_value args[2] = { nullptr };
|
||||||
|
@ -121,44 +127,51 @@ napi_value EGLRender::RenderSetIntParams(napi_env env, napi_callback_info info)
|
||||||
|
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
napi_status tStatus = napi_get_value_uint32(env, args[0], &type);
|
napi_status tStatus = napi_get_value_uint32(env, args[0], &type);
|
||||||
if (tStatus != napi_ok) {
|
if (tStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
uint32_t param;
|
uint32_t param;
|
||||||
napi_status pStatus = napi_get_value_uint32(env, args[1], ¶m);
|
napi_status pStatus = napi_get_value_uint32(env, args[1], ¶m);
|
||||||
if (pStatus != napi_ok) {
|
if (pStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
EGLRender::GetInstance() -> SetIntParams(type, param);
|
EGLRender::GetInstance() -> SetIntParams(type, param);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::GetPixelMapOfSurface(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::GetPixelMapOfSurface(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
size_t argc = 4;
|
size_t argc = 4;
|
||||||
napi_value args[4] = { nullptr };
|
napi_value args[4] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
napi_status xStatus = napi_get_value_uint32(env, args[0], &x);
|
napi_status xStatus = napi_get_value_uint32(env, args[0], &x);
|
||||||
if (xStatus != napi_ok) {
|
if (xStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
napi_status yStatus = napi_get_value_uint32(env, args[1], &y);
|
napi_status yStatus = napi_get_value_uint32(env, args[1], &y);
|
||||||
if (yStatus != napi_ok) {
|
if (yStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t surfaceWidth;
|
uint32_t surfaceWidth;
|
||||||
napi_status swStatus = napi_get_value_uint32(env, args[2], &surfaceWidth);
|
napi_status swStatus = napi_get_value_uint32(env, args[2], &surfaceWidth);
|
||||||
if (swStatus != napi_ok) {
|
if (swStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t surfaceHeight;
|
uint32_t surfaceHeight;
|
||||||
napi_status shStatus = napi_get_value_uint32(env, args[3], &surfaceHeight);
|
napi_status shStatus = napi_get_value_uint32(env, args[3], &surfaceHeight);
|
||||||
if (shStatus != napi_ok) {
|
if (shStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,47 +183,55 @@ napi_value EGLRender::GetPixelMapOfSurface(napi_env env, napi_callback_info info
|
||||||
NativeImageUtil::flip(&pixels, surfaceWidth, surfaceHeight);
|
NativeImageUtil::flip(&pixels, surfaceWidth, surfaceHeight);
|
||||||
napi_value array;
|
napi_value array;
|
||||||
int byte_length = surfaceWidth * surfaceHeight * DEFAULT_FOUR;
|
int byte_length = surfaceWidth * surfaceHeight * DEFAULT_FOUR;
|
||||||
if (!NativeImageUtil::CreateArrayBuffer(env, pixels, byte_length, &array)) {
|
if (!NativeImageUtil::CreateArrayBuffer(env, pixels, byte_length, &array))
|
||||||
|
{
|
||||||
LOGI("gl--> GetPixelMapOfSurface error");
|
LOGI("gl--> GetPixelMapOfSurface error");
|
||||||
}
|
}
|
||||||
free(pixels);
|
free(pixels);
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::EGLIsInit(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::EGLIsInit(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
napi_value isInit;
|
napi_value isInit;
|
||||||
int32_t value;
|
int32_t value;
|
||||||
if (EGLRender::GetInstance() -> m_IsGLContextReady) {
|
if (EGLRender::GetInstance() -> m_IsGLContextReady)
|
||||||
|
{
|
||||||
value = 1;
|
value = 1;
|
||||||
}else {
|
}else {
|
||||||
value = 0;
|
value = 0;
|
||||||
}
|
}
|
||||||
napi_status status = napi_create_int32(env, value, &isInit);
|
napi_status status = napi_create_int32(env, value, &isInit);
|
||||||
if (status != napi_ok) {
|
if (status != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return isInit;
|
return isInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::DestroyGlesEnv(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::DestroyGlesEnv(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
EGLRender::GetInstance() -> UnInit();
|
EGLRender::GetInstance() -> UnInit();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::StartUseProgram(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::StartUseProgram(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
EGLRender::GetInstance() -> UseProgram();
|
EGLRender::GetInstance() -> UseProgram();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::Rendering(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::Rendering(napi_env env, napi_callback_info info)
|
||||||
//7 . 渲染
|
{
|
||||||
|
// 渲染
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const void *)0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const void *)0);
|
||||||
glBindVertexArray(GL_NONE);
|
glBindVertexArray(GL_NONE);
|
||||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
|
||||||
size_t argc = 3;
|
size_t argc = 3;
|
||||||
napi_value args[3] = { nullptr };
|
napi_value args[3] = { nullptr };
|
||||||
|
@ -231,7 +252,8 @@ napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
||||||
size_t bufferLength;
|
size_t bufferLength;
|
||||||
size_t byte_offset;
|
size_t byte_offset;
|
||||||
napi_status buffStatus = napi_get_typedarray_info(env, args[2], &dataType, &bufferLength, &buffer, &args[2], &byte_offset);
|
napi_status buffStatus = napi_get_typedarray_info(env, args[2], &dataType, &bufferLength, &buffer, &args[2], &byte_offset);
|
||||||
if (buffStatus != napi_ok){
|
if (buffStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,15 +261,20 @@ napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
||||||
|
|
||||||
int uniformType;
|
int uniformType;
|
||||||
|
|
||||||
if (strcmp(key, "glUniform2fv") == 0) {
|
if (strcmp(key, "glUniform2fv") == 0)
|
||||||
|
{
|
||||||
uniformType = UNIFORM_TYPE_2FV;
|
uniformType = UNIFORM_TYPE_2FV;
|
||||||
}else if (strcmp(key, "glUniform3fv") == 0) {
|
}else if (strcmp(key, "glUniform3fv") == 0)
|
||||||
|
{
|
||||||
uniformType = UNIFORM_TYPE_3FV;
|
uniformType = UNIFORM_TYPE_3FV;
|
||||||
}else if (strcmp(key, "glUniform4fv") == 0) {
|
}else if (strcmp(key, "glUniform4fv") == 0)
|
||||||
|
{
|
||||||
uniformType = UNIFORM_TYPE_4FV;
|
uniformType = UNIFORM_TYPE_4FV;
|
||||||
}else if (strcmp(key, "glUniform1fv") == 0) {
|
}else if (strcmp(key, "glUniform1fv") == 0)
|
||||||
|
{
|
||||||
uniformType = UNIFORM_TYPE_FV;
|
uniformType = UNIFORM_TYPE_FV;
|
||||||
}else if (strcmp(key, "glUniform2f") == 0) {
|
}else if (strcmp(key, "glUniform2f") == 0)
|
||||||
|
{
|
||||||
uniformType = UNIFORM_TYPE_2F;
|
uniformType = UNIFORM_TYPE_2F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +282,8 @@ napi_value EGLRender::setTypeArrayOfFloat(napi_env env, napi_callback_info info)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::setTypeArrayOfMatrix3f(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::setTypeArrayOfMatrix3f(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
size_t argc = 2;
|
size_t argc = 2;
|
||||||
napi_value args[2] = { nullptr };
|
napi_value args[2] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
@ -270,7 +298,8 @@ napi_value EGLRender::setTypeArrayOfMatrix3f(napi_env env, napi_callback_info in
|
||||||
size_t bufferLength;
|
size_t bufferLength;
|
||||||
size_t byte_offset;
|
size_t byte_offset;
|
||||||
napi_status buffStatus = napi_get_typedarray_info(env, args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
napi_status buffStatus = napi_get_typedarray_info(env, args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
||||||
if (buffStatus != napi_ok){
|
if (buffStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +310,8 @@ napi_value EGLRender::setTypeArrayOfMatrix3f(napi_env env, napi_callback_info in
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::setTypeArrayOfMatrix4f(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::setTypeArrayOfMatrix4f(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
size_t argc = 2;
|
size_t argc = 2;
|
||||||
napi_value args[2] = { nullptr };
|
napi_value args[2] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
@ -296,7 +326,8 @@ napi_value EGLRender::setTypeArrayOfMatrix4f(napi_env env, napi_callback_info in
|
||||||
size_t bufferLength;
|
size_t bufferLength;
|
||||||
size_t byte_offset;
|
size_t byte_offset;
|
||||||
napi_status buffStatus = napi_get_typedarray_info(env, args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
napi_status buffStatus = napi_get_typedarray_info(env, args[1], &dataType, &bufferLength, &buffer, &args[1], &byte_offset);
|
||||||
if (buffStatus != napi_ok){
|
if (buffStatus != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,8 +337,9 @@ napi_value EGLRender::setTypeArrayOfMatrix4f(napi_env env, napi_callback_info in
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::RenderGlUniform1i(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::RenderGlUniform1i(napi_env env, napi_callback_info info)
|
||||||
//int
|
{
|
||||||
|
// int
|
||||||
size_t argc = 2;
|
size_t argc = 2;
|
||||||
napi_value args[2] = { nullptr };
|
napi_value args[2] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
@ -316,15 +348,17 @@ napi_value EGLRender::RenderGlUniform1i(napi_env env, napi_callback_info info) {
|
||||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
napi_status status = napi_get_value_uint32(env, args[1], &value);
|
napi_status status = napi_get_value_uint32(env, args[1], &value);
|
||||||
if (status != napi_ok) {
|
if (status != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
EGLRender::GetInstance() -> GlUniform((char*)content.c_str(), value, UNIFORM_TYPE_ZERO);
|
EGLRender::GetInstance() -> GlUniform((char*)content.c_str(), value, UNIFORM_TYPE_ZERO);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::RenderGlUniform1f(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::RenderGlUniform1f(napi_env env, napi_callback_info info)
|
||||||
//float
|
{
|
||||||
|
// float
|
||||||
size_t argc = 2;
|
size_t argc = 2;
|
||||||
napi_value args[2] = { nullptr };
|
napi_value args[2] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
@ -333,15 +367,17 @@ napi_value EGLRender::RenderGlUniform1f(napi_env env, napi_callback_info info) {
|
||||||
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
NapiUtil::JsValueToString(env, args[0], STR_DEFAULT_SIZE, content);
|
||||||
double value;
|
double value;
|
||||||
napi_status status = napi_get_value_double(env, args[1], &value);
|
napi_status status = napi_get_value_double(env, args[1], &value);
|
||||||
if (status != napi_ok) {
|
if (status != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
EGLRender::GetInstance() -> GlUniform((char*)content.c_str(), value, UNIFORM_TYPE_ONE);
|
EGLRender::GetInstance() -> GlUniform((char*)content.c_str(), value, UNIFORM_TYPE_ONE);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value EGLRender::RenderGlUniform2fv(napi_env env, napi_callback_info info) {
|
napi_value EGLRender::RenderGlUniform2fv(napi_env env, napi_callback_info info)
|
||||||
//float 数组
|
{
|
||||||
|
// float 数组
|
||||||
size_t argc = 3;
|
size_t argc = 3;
|
||||||
napi_value args[3] = { nullptr };
|
napi_value args[3] = { nullptr };
|
||||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||||
|
@ -351,12 +387,14 @@ napi_value EGLRender::RenderGlUniform2fv(napi_env env, napi_callback_info info)
|
||||||
|
|
||||||
double value;
|
double value;
|
||||||
napi_status status = napi_get_value_double(env, args[1], &value);
|
napi_status status = napi_get_value_double(env, args[1], &value);
|
||||||
if (status != napi_ok) {
|
if (status != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
double value2;
|
double value2;
|
||||||
napi_status status2 = napi_get_value_double(env, args[2], &value2);
|
napi_status status2 = napi_get_value_double(env, args[2], &value2);
|
||||||
if (status2 != napi_ok) {
|
if (status2 != napi_ok)
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +405,8 @@ napi_value EGLRender::RenderGlUniform2fv(napi_env env, napi_callback_info info)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLRender::EGLRender() {
|
EGLRender::EGLRender()
|
||||||
|
{
|
||||||
m_ImageTextureId = GL_NONE;
|
m_ImageTextureId = GL_NONE;
|
||||||
m_FboTextureId = GL_NONE;
|
m_FboTextureId = GL_NONE;
|
||||||
m_SamplerLoc = GL_NONE;
|
m_SamplerLoc = GL_NONE;
|
||||||
|
@ -382,19 +421,22 @@ EGLRender::EGLRender() {
|
||||||
m_ShaderIndex = 0;
|
m_ShaderIndex = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
EGLRender::~EGLRender() {
|
EGLRender::~EGLRender()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
void EGLRender::Init() {
|
void EGLRender::Init()
|
||||||
|
{
|
||||||
if (CreateGlEnv() == 0)
|
if (CreateGlEnv() == 0)
|
||||||
{
|
{
|
||||||
m_IsGLContextReady = true;
|
m_IsGLContextReady = true;
|
||||||
}
|
}
|
||||||
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);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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_MIN_FILTER, GL_LINEAR);
|
||||||
|
@ -412,7 +454,8 @@ void EGLRender::Init() {
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -448,7 +491,8 @@ void EGLRender::Init() {
|
||||||
glBindVertexArray(GL_NONE);
|
glBindVertexArray(GL_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
@ -480,26 +524,30 @@ int EGLRender::CreateGlEnv() {
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
if (m_eglDisplay == EGL_NO_DISPLAY) {
|
if (m_eglDisplay == EGL_NO_DISPLAY)
|
||||||
|
{
|
||||||
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())
|
switch(eglGetError())
|
||||||
{
|
{
|
||||||
case EGL_BAD_ALLOC:
|
case EGL_BAD_ALLOC:
|
||||||
|
@ -525,7 +573,7 @@ int EGLRender::CreateGlEnv() {
|
||||||
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");
|
LOGI("gl-->::CreateGlesEnv EGL_BAD_CONFIG");
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
|
@ -533,8 +581,8 @@ int EGLRender::CreateGlEnv() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//绑定上下文
|
// 绑定上下文
|
||||||
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;
|
||||||
|
@ -542,7 +590,7 @@ int EGLRender::CreateGlEnv() {
|
||||||
LOGI("gl-->::CreateGlesEnv initialize success");
|
LOGI("gl-->::CreateGlesEnv initialize success");
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
if(resultCode != 0)
|
if (resultCode != 0)
|
||||||
{
|
{
|
||||||
LOGI("gl-->::CreateGlesEnv fail");
|
LOGI("gl-->::CreateGlesEnv fail");
|
||||||
}
|
}
|
||||||
|
@ -550,7 +598,8 @@ int EGLRender::CreateGlEnv() {
|
||||||
return resultCode;
|
return resultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLRender::SetImageData(uint8_t *pData, int width, int height) {
|
void EGLRender::SetImageData(uint8_t *pData, int width, int height)
|
||||||
|
{
|
||||||
if (pData && m_IsGLContextReady)
|
if (pData && m_IsGLContextReady)
|
||||||
{
|
{
|
||||||
if (m_RenderImage.ppPlane[0])
|
if (m_RenderImage.ppPlane[0])
|
||||||
|
@ -576,7 +625,8 @@ void EGLRender::SetImageData(uint8_t *pData, int width, int height) {
|
||||||
glBindTexture(GL_TEXTURE_2D, m_FboTextureId);
|
glBindTexture(GL_TEXTURE_2D, m_FboTextureId);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_FboTextureId, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_FboTextureId, 0);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_RenderImage.width, m_RenderImage.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_RenderImage.width, m_RenderImage.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
{
|
||||||
LOGI("gl--> EGLRender ::SetImageData glCheckFramebufferStatus status != GL_FRAMEBUFFER_COMPLETE");
|
LOGI("gl--> EGLRender ::SetImageData glCheckFramebufferStatus status != GL_FRAMEBUFFER_COMPLETE");
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||||
|
@ -586,7 +636,8 @@ void EGLRender::SetImageData(uint8_t *pData, int width, int height) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLRender::SetIntParams(int paramType, int param) {
|
void EGLRender::SetIntParams(int paramType, int param)
|
||||||
|
{
|
||||||
LOGI("gl--> EGLRender::SetIntParams paramType = %{public}d,param = %{public}d", paramType, param);
|
LOGI("gl--> EGLRender::SetIntParams paramType = %{public}d,param = %{public}d", paramType, param);
|
||||||
switch(paramType)
|
switch(paramType)
|
||||||
{
|
{
|
||||||
|
@ -690,14 +741,15 @@ 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);
|
||||||
|
|
||||||
glViewport(0, 0, m_RenderImage.width, m_RenderImage.height);
|
glViewport(0, 0, m_RenderImage.width, m_RenderImage.height);
|
||||||
|
|
||||||
//DO FBO off screen rendering
|
// DO FBO off screen rendering
|
||||||
glUseProgram(m_ProgramObj);
|
glUseProgram(m_ProgramObj);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_FboId);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_FboId);
|
||||||
|
|
||||||
|
@ -706,7 +758,8 @@ void EGLRender::UseProgram() {
|
||||||
glBindTexture(GL_TEXTURE_2D, m_ImageTextureId);
|
glBindTexture(GL_TEXTURE_2D, m_ImageTextureId);
|
||||||
glUniform1i(m_SamplerLoc, 0);
|
glUniform1i(m_SamplerLoc, 0);
|
||||||
|
|
||||||
if (m_TexSizeLoc > -1) {
|
if (m_TexSizeLoc > -1)
|
||||||
|
{
|
||||||
GLfloat size[2];
|
GLfloat size[2];
|
||||||
size[0] = m_RenderImage.width;
|
size[0] = m_RenderImage.width;
|
||||||
size[1] = m_RenderImage.height;
|
size[1] = m_RenderImage.height;
|
||||||
|
@ -714,7 +767,8 @@ void EGLRender::UseProgram() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLRender::GlUniform(char* location, float value, int unType) {
|
void EGLRender::GlUniform(char* location, float value, int unType)
|
||||||
|
{
|
||||||
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
||||||
switch(unType)
|
switch(unType)
|
||||||
{
|
{
|
||||||
|
@ -729,7 +783,8 @@ void EGLRender::GlUniform(char* location, float value, int unType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLRender::GlUniformArray(char* location, float* value, int unType) {
|
void EGLRender::GlUniformArray(char* location, float* value, int unType)
|
||||||
|
{
|
||||||
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
||||||
switch(unType)
|
switch(unType)
|
||||||
{
|
{
|
||||||
|
@ -759,7 +814,8 @@ void EGLRender::GlUniformArray(char* location, float* value, int unType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLRender::GlUniformMatrix(char* location, float* value, int unType) {
|
void EGLRender::GlUniformMatrix(char* location, float* value, int unType)
|
||||||
|
{
|
||||||
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
GLint ll = glGetUniformLocation(m_ProgramObj, location);
|
||||||
switch(unType)
|
switch(unType)
|
||||||
{
|
{
|
||||||
|
@ -774,14 +830,15 @@ void EGLRender::GlUniformMatrix(char* location, float* value, int unType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EGLRender::UnInit() {
|
void EGLRender::UnInit()
|
||||||
|
{
|
||||||
if (m_ProgramObj)
|
if (m_ProgramObj)
|
||||||
{
|
{
|
||||||
glDeleteProgram(m_ProgramObj);
|
glDeleteProgram(m_ProgramObj);
|
||||||
m_ProgramObj = GL_NONE;
|
m_ProgramObj = GL_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_ImageTextureId)
|
if (m_ImageTextureId)
|
||||||
{
|
{
|
||||||
glDeleteTextures(DEFAULT_ONE, &m_ImageTextureId);
|
glDeleteTextures(DEFAULT_ONE, &m_ImageTextureId);
|
||||||
m_ImageTextureId = GL_NONE;
|
m_ImageTextureId = GL_NONE;
|
||||||
|
@ -818,9 +875,11 @@ void EGLRender::UnInit() {
|
||||||
m_IsGLContextReady = false;
|
m_IsGLContextReady = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void EGLRender::DestroyGl() {
|
void EGLRender::DestroyGl()
|
||||||
//释放 EGL 环境
|
{
|
||||||
if (m_eglDisplay != EGL_NO_DISPLAY) {
|
// 释放 EGL 环境
|
||||||
|
if (m_eglDisplay != EGL_NO_DISPLAY)
|
||||||
|
{
|
||||||
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
eglDestroyContext(m_eglDisplay, m_eglCtx);
|
eglDestroyContext(m_eglDisplay, m_eglCtx);
|
||||||
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
||||||
|
|
|
@ -117,4 +117,4 @@ class EGLRender {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GPU_ImageETS_EGLRender_H
|
#endif // GPU_ImageETS_EGLRender_H
|
||||||
|
|
|
@ -29,4 +29,4 @@
|
||||||
#define LOGW(...)((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "OH_GPU_LOG", __VA_ARGS__))
|
#define LOGW(...)((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "OH_GPU_LOG", __VA_ARGS__))
|
||||||
#define LOGE(...)((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "OH_GPU_LOG", __VA_ARGS__))
|
#define LOGE(...)((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "OH_GPU_LOG", __VA_ARGS__))
|
||||||
|
|
||||||
#endif //GPU_ImageETS_DebugLog_H
|
#endif // GPU_ImageETS_DebugLog_H
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
||||||
// please include "napi/native_api.h".
|
// please include "napi/native_api.h".
|
||||||
|
|
||||||
#include "GLUtils.h"
|
|
||||||
#include "DebugLog.h"
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "GLUtils.h"
|
||||||
|
#include "DebugLog.h"
|
||||||
|
|
||||||
GLuint GLUtils::LoadShader(GLenum shaderType, const char *pSource)
|
GLuint GLUtils::LoadShader(GLenum shaderType, const char *pSource)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,8 @@ GLuint GLUtils::LoadShader(GLenum shaderType, const char *pSource)
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
GLint compiled = 0;
|
GLint compiled = 0;
|
||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||||
if (!compiled) {
|
if (!compiled)
|
||||||
|
{
|
||||||
GLint infoLen = 0;
|
GLint infoLen = 0;
|
||||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
|
||||||
if (infoLen)
|
if (infoLen)
|
||||||
|
@ -62,7 +63,7 @@ GLuint GLUtils::CreateProgram(const char *pVertexShaderSource, const char *pFrag
|
||||||
if (!fragShaderHandle) return program;
|
if (!fragShaderHandle) return program;
|
||||||
|
|
||||||
program = glCreateProgram();
|
program = glCreateProgram();
|
||||||
if(program)
|
if (program)
|
||||||
{
|
{
|
||||||
glAttachShader(program, vertexShaderHandle);
|
glAttachShader(program, vertexShaderHandle);
|
||||||
CheckGLError("glAttachShader");
|
CheckGLError("glAttachShader");
|
||||||
|
@ -79,7 +80,7 @@ GLuint GLUtils::CreateProgram(const char *pVertexShaderSource, const char *pFrag
|
||||||
glDeleteShader(fragShaderHandle);
|
glDeleteShader(fragShaderHandle);
|
||||||
fragShaderHandle = 0;
|
fragShaderHandle = 0;
|
||||||
|
|
||||||
if(linkStatus != GL_TRUE)
|
if (linkStatus != GL_TRUE)
|
||||||
{
|
{
|
||||||
GLint bufLength = 0;
|
GLint bufLength = 0;
|
||||||
glGetProgramiv(program,GL_INFO_LOG_LENGTH, &bufLength);
|
glGetProgramiv(program,GL_INFO_LOG_LENGTH, &bufLength);
|
||||||
|
@ -101,9 +102,8 @@ GLuint GLUtils::CreateProgram(const char *pVertexShaderSource, const char *pFrag
|
||||||
|
|
||||||
void GLUtils::CheckGLError(const char *pGLOperation)
|
void GLUtils::CheckGLError(const char *pGLOperation)
|
||||||
{
|
{
|
||||||
for(GLint error = glGetError(); error; error = glGetError())
|
for (GLint error = glGetError(); error; error = glGetError())
|
||||||
{
|
{
|
||||||
LOGI("GLUtils::CheckGLError GL Operation %{public}s() glError (0x%x)\n", pGLOperation, error);
|
LOGI("GLUtils::CheckGLError GL Operation %{public}s() glError (0x%x)\n", pGLOperation, error);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,4 @@ class GLUtils {
|
||||||
static void CheckGLError(const char *pGLOperation);
|
static void CheckGLError(const char *pGLOperation);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GPU_ImageETS_GLUtils_H
|
#endif // GPU_ImageETS_GLUtils_H
|
||||||
|
|
|
@ -20,18 +20,20 @@
|
||||||
// please include "napi/native_api.h".
|
// please include "napi/native_api.h".
|
||||||
|
|
||||||
#include "NapiUtil.h"
|
#include "NapiUtil.h"
|
||||||
#include "DebugLog.h"
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "DebugLog.h"
|
||||||
|
|
||||||
const int32_t MAX_STR_LENGTH = 1024;
|
const int32_t MAX_STR_LENGTH = 1024;
|
||||||
|
|
||||||
void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, const int32_t bufLen, std::string &target)
|
void NapiUtil::JsValueToString(const napi_env &env, const napi_value &value, const int32_t bufLen, std::string &target)
|
||||||
{
|
{
|
||||||
if (bufLen <= 0 || bufLen > MAX_STR_LENGTH) {
|
if (bufLen <= 0 || bufLen > MAX_STR_LENGTH)
|
||||||
|
{
|
||||||
LOGI("%s string too long malloc failed",__func__);
|
LOGI("%s string too long malloc failed",__func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,4 +32,4 @@ class NapiUtil {
|
||||||
std::string &target);
|
std::string &target);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GPU_ImageETS_NapiUtil_H
|
#endif // GPU_ImageETS_NapiUtil_H
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#include <js_native_api_types.h>
|
#include <js_native_api_types.h>
|
||||||
#include <node_api.h>
|
#include <node_api.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "DebugLog.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "DebugLog.h"
|
||||||
#include "constant/constant_shape.h"
|
#include "constant/constant_shape.h"
|
||||||
|
|
||||||
#define IMAGE_FORMAT_RGBA 0x01
|
#define IMAGE_FORMAT_RGBA 0x01
|
||||||
|
@ -133,11 +133,13 @@ class NativeImageUtil
|
||||||
|
|
||||||
static bool CreateArrayBuffer(napi_env env, void* src, size_t srcLen, napi_value *res)
|
static bool CreateArrayBuffer(napi_env env, void* src, size_t srcLen, napi_value *res)
|
||||||
{
|
{
|
||||||
if (src == nullptr || srcLen == DEFAULT_ZERO) {
|
if (src == nullptr || srcLen == DEFAULT_ZERO)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void *nativePtr = nullptr;
|
void *nativePtr = nullptr;
|
||||||
if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr) {
|
if (napi_create_arraybuffer(env, srcLen, &nativePtr, res) != napi_ok || nativePtr == nullptr)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memcpy(nativePtr, src, srcLen);
|
memcpy(nativePtr, src, srcLen);
|
||||||
|
@ -151,7 +153,8 @@ class NativeImageUtil
|
||||||
uint8_t* tmp = (uint8_t*)malloc(totalLength);
|
uint8_t* tmp = (uint8_t*)malloc(totalLength);
|
||||||
memcpy(tmp, *buf, totalLength);
|
memcpy(tmp, *buf, totalLength);
|
||||||
memset(*buf, DEFAULT_ZERO, sizeof(uint8_t)*totalLength);
|
memset(*buf, DEFAULT_ZERO, sizeof(uint8_t)*totalLength);
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++)
|
||||||
|
{
|
||||||
memcpy(*buf + oneLineLength * i, tmp + totalLength - oneLineLength * (i+1), oneLineLength);
|
memcpy(*buf + oneLineLength * i, tmp + totalLength - oneLineLength * (i+1), oneLineLength);
|
||||||
}
|
}
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
Loading…
Reference in New Issue