- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在个人项目中试验 Native Activity 和 GLES 3.0,直到遇到这个障碍:着色器不会加载和/或编译,我不太确定,因为 OPENGL 的日志不存在.
这是我的两个着色器:
static const char glVertexShader[] =
"#version 300 es\n"
"in vec4 vPosition;\n"
"void main()\n"
"{\n"
" gl_Position = vPosition;\n"
"}\n\0";
static const char glFragmentShader[] =
"#version 300 es\n"
"precision mediump float;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n\0";
这是我的着色器加载和程序创建函数:
GLuint loadShader(GLenum shaderType, const char* shaderSource)
{
GLuint shader = glCreateShader(shaderType);
if (shader)
{
glShaderSource(shader, 1, &shaderSource, NULL);
glCompileShader(shader);
GLint compiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if (!compiled)
{
GLint infoLen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if (infoLen)
{
char * buf = new char[infoLen];
if (buf)
{
glGetShaderInfoLog(shader, infoLen, NULL, buf);
log.log_error("Could not Compile Shader %d:\n%s\n", shaderType, buf);
delete[] buf;
}
glDeleteShader(shader);
shader = 0;
}
}
}
return shader;
}
GLuint createProgram(const char* vertexSource, const char * fragmentSource)
{
log.log_info("Loading vertex shader");
GLuint vertexShader = loadShader(GL_VERTEX_SHADER, vertexSource);
if (!vertexShader)
{
log.log_info("Vertex shader load failure!");
return 0;
}
log.log_info("Loading fragment shader");
GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentSource);
if (!fragmentShader)
{
log.log_info("Fragment shader load failure!");
return 0;
}
GLuint program = glCreateProgram();
if (program)
{
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glLinkProgram(program);
GLint linkStatus = GL_FALSE;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
if (linkStatus != GL_TRUE)
{
GLint bufLength = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
if (bufLength)
{
char* buf = new char[bufLength];
if (buf)
{
glGetProgramInfoLog(program, bufLength, NULL, buf);
log.log_error("Could not link program:\n%s\n", buf);
delete[] buf;
}
}
glDeleteProgram(program);
program = 0;
}
}
return program;
}
我还将在下面包含我的设置代码和绘图代码:
设置代码:
GLuint simpleTriangleProgram;
GLuint vPosition;
bool setupGraphics(int w, int h)
{
simpleTriangleProgram = createProgram(glVertexShader, glFragmentShader);
if (!simpleTriangleProgram)
{
log.log_error("Could not create program");
return false;
}
vPosition = glGetAttribLocation(simpleTriangleProgram, "vPosition");
glViewport(0, 0, w, h);
return true;
}
绘图代码:
//-------------------------------
const GLfloat triangleVertices[] = {
0.0f, 1.0f,
-1.0f, -1.0f,
1.0f, -1.0f
};
//-------------------------------
/**
* Just the current frame in the display.
*/
static void engine_draw_frame(struct engine* engine) {
if (engine->display == NULL) {
// No display.
return;
}
// Just fill the screen with a color.
glClearColor(((float)engine->state.x) / engine->width, engine->state.angle,
((float)engine->state.y) / engine->height, 1);
glClear(GL_COLOR_BUFFER_BIT);
//---------------------------------------------------
glUseProgram(simpleTriangleProgram);
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, triangleVertices);
glEnableVertexAttribArray(vPosition);
glDrawArrays(GL_TRIANGLES, 0, 3);
//---------------------------------------------------
eglSwapBuffers(engine->display, engine->surface);
}
是的,GLES 上下文已正确创建。
但如果我也应该发布该代码,请告诉我。
这是我的上下文创建代码:
/**
* Initialize an EGL context for the current display.
*/
static int engine_init_display(struct engine* engine) {
// initialize OpenGL ES and EGL
/*
* Here specify the attributes of the desired configuration.
* Below, we select an EGLConfig with at least 8 bits per color
* component compatible with on-screen windows
*/
const EGLint attribs[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};
EGLint w, h, format;
EGLint numConfigs;
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, 0, 0);
/* Here, the application chooses the configuration it desires.
* find the best match if possible, otherwise use the very first one
*/
eglChooseConfig(display, attribs, NULL, 0, &numConfigs);
std::unique_ptr<EGLConfig[]> supportedConfigs(new EGLConfig[numConfigs]);
assert(supportedConfigs);
eglChooseConfig(display, attribs, supportedConfigs.get(), numConfigs, &numConfigs);
assert(numConfigs);
auto i = 0;
for (; i < numConfigs; i++) {
auto& cfg = supportedConfigs[i];
EGLint r, g, b, d;
if (eglGetConfigAttrib(display, cfg, EGL_RED_SIZE, &r) &&
eglGetConfigAttrib(display, cfg, EGL_GREEN_SIZE, &g) &&
eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b) &&
eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d) &&
r == 8 && g == 8 && b == 8 && d == 0) {
config = supportedConfigs[i];
break;
}
}
if (i == numConfigs) {
config = supportedConfigs[0];
}
EGLint AttribList[] =
{
EGL_CONTEXT_CLIENT_VERSION, 3,
EGL_NONE
};
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
context = eglCreateContext(display, config, NULL, AttribList);
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
log.log_warning("Unable to eglMakeCurrent");
return -1;
}
eglQuerySurface(display, surface, EGL_WIDTH, &w);
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
engine->display = display;
engine->context = context;
engine->surface = surface;
engine->width = w;
engine->height = h;
engine->state.angle = 0;
// Check openGL on the system
auto opengl_info = { GL_VENDOR, GL_RENDERER, GL_VERSION, GL_EXTENSIONS };
for (auto name : opengl_info) {
auto info = glGetString(name);
log.log_info("OpenGL Info: %s", info);
}
// Initialize GL state.
// glEnable(GL_CULL_FACE);
// glEnable(GL_DEPTH_TEST);
return 0;
}
完整日志: Log pic
注意:我的记录器类只是 __android_log_vprint()
的包装器。我没有包括它,因为它一点也不相关。
最佳答案
这个:
#version 300 es
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
... 不是合法的 ESSL 版本 300 着色器,因此您应该得到编译器在您的平台上返回的编译错误日志。你从你的 log_info 日志 channel 没有得到任何东西吗?
要使着色器合法,请将 attribute
替换为 in
。
关于Android native Activity ,GLES 3.0 着色器编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47381609/
在这种情况下,我们在应用程序中同时使用react-native-gesture-handler Touchable和react-native Touchable。 (通过Touchables,我的意思
我有一个 MainFooter包含页脚和迷你播放器的组件,单击时动画显示为全 View 。我有一个问题,每当我们点击一个页脚选项卡时,播放器最大化然后卡在那里,没有响应。 此外,播放器内部的向下箭
我在 native react 之上使用 native 基础组件,我想知道如何在 UI 中使卡片呈圆形而不是矩形。有圆形的 Prop 吗? 最佳答案 好吧,实际上没有人能回答这个问题,但幸运的是我在
我在 native react 之上使用 native 基础组件,我想知道如何在 UI 中使卡片呈圆形而不是矩形。有圆形的 Prop 吗? 最佳答案 好吧,实际上没有人能回答这个问题,但幸运的是我在
我是 react-native 的新手,所以我认为“HTML”而不是“native”可能有点太多了,所以我的问题看起来很愚蠢。 我使用 react-native-router-flux 进行路由,并使
当我使用这个例子在我的应用程序上实现 Image-slider 时,我遇到了这个错误。 import React,{Component} from 'react' import {View,T
我正在为我们的产品使用“Native Base”组件,并且效果很好, 但我有一点被卡住了,它是关于将 Items 放入 Nativebase Picker 的问题。我的代码是这样的 渲染方法代码 -
正如文档中所建议的,我将一些长的数据获取代码移动到 native 模块中以释放 JS 线程,但我观察到这仍然阻塞了 UI。为什么会这样,我能做些什么来避免这种情况? 从 JS 调用 native 模块
我正在使用一个名为 react-native-svg 的框架在 React Native View 中绘制 SVG 元素。 我的目标是,当我点击 View 时(我在全局 View 上使用 PanRes
在 IOS 中发现错误 Native Module cannot be null 我不使用 react-native-push-notification 最佳答案 这通常发生在您未能将第三个库链接到您
当应用程序关闭时,我可以获得由 Linking.getInitialURL() 点击的深层链接网址。 .当应用程序处于后台状态时,则不会安装任何内容。所以,我什至无法通过 Linking.addEve
1) 说原生库是什么意思?什么样的图书馆?那些将用作 gradle 依赖项? 2)如何链接这些?我在使用 link 或 rnpm 时遇到了麻烦。 最佳答案 链接 native 库意味着您要将已经实现的
我需要帮助来构建我的 react 原生项目。我尝试过react-native run-android,但出现以下错误: react-native : The term 'react-native' i
我需要帮助来构建我的 react 原生项目。我尝试过react-native run-android,但出现以下错误: react-native : The term 'react-native' i
我是 React-Native 的新手,到目前为止我很喜欢它。我正在尝试创建一个屏幕(用于跨平台应用程序),右上角有一个菜单图标,单击时,我想打开一个菜单,希望使用 react-native-menu
RN doco 和其他示例展示了如何从 native iOS View Controller 启动 React-Native View ,但反之则不然。谁能解释一下我该怎么做? 最佳答案 我能够弄清楚
对于 react-native - WebStorm 用户: 我正在使用 Jet Brains IDE WebStorm 开始一个带有 React Native 的项目。 在项目 => node_mo
在升级过去的 react-native 0.60 之后......我被警告我应该取消链接所有手动链接的第 3 方库(因为 RN 现在通过自动链接处理它)。 但是,当我运行 react-native u
你可以使用像 https://github.com/tolu360/react-native-google-places 这样的库吗?在世博项目中?我假设任何 npm 库都可以添加,但是像这个 goo
我主要喜欢 React Native。自 0.22 以来一直在使用它。目前为 0.35。 但是为什么链接原生库就像抽奖一样呢?我很少在第一次拍摄时让它发挥作用,而破裂的东西通常是完全不同的东西。 每个
我是一名优秀的程序员,十分优秀!