【发布时间】:2019-09-19 19:53:35
【问题描述】:
1.我需要将opengl中的shader移动到Opengles 2.0.所以我有一个问题,我不知道如何转移这个叫做UBO的结构。 2.如果转移成功,我应该给程序分配什么?
1.1 转入opengles2.0代码:
layout(binding = 0) uniform UniformBufferObject
{
mat4 model;
mat4 normal;
mat4 view;
mat4 proj;
vec3 eyepos;
material_struct material;
light_struct lights[8];
} ubo;
2.1 我想转换顶点数据。我应该如何将此 UBO 分配给程序?
//vertex
int mPositionHandle = GLES20.GetAttribLocation(_program, "vPosition");
GLES20.EnableVertexAttribArray(mPositionHandle);
GLES20.VertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, _buffer);
//color
int mColorHandle = GLES20.GetAttribLocation(_program, "aColor");
GLES20.EnableVertexAttribArray(mColorHandle);
GLES20.VertexAttribPointer(mColorHandle, 4, GLES20.GL_FLOAT, false, 0, _color);
//UBO???
目前顶点数据、索引、颜色都在,但是顶点数据太大了。我希望在(-1~1)之间切换。
【问题讨论】:
-
OpenGL ES 2.0 中不提供统一块。你必须使用单独的制服。
-
@Rabbid76 你能把这个评论转换成答案吗,所以这个问题显示为已回答。
-
@solidpixel 我把评论变成了答案。但我不确定它是否让我满意。
标签: opengl-es glsl shader opengl-es-2.0