简体   繁体   English

Android:GLES 2.0打破三星S2?

[英]Android: GLES 2.0 broken on Samsung S2?

I have some very simple shader code that is failing on the S2 and only the S2. 我有一些非常简单的着色器代码在S2上失败,只有S2失败。

precision highp float;
varying vec4 v_colour;
uniform mat4 proj_cam;
uniform mat4 trans;
attribute vec4 vp; //vertex xyz from buffer.
attribute vec4 vc; //vertex colour, from buffer. Standard 32bit value.
void main()
{
  v_colour = vc;
  gl_Position = proj_cam * (trans * vp);
};

precision mediump float;
varying vec4 v_colour;
void main()
{
    gl_FragColor = v_colour;
}

On the S2 this fails to render any output. 在S2上,这无法呈现任何输出。 If I remove the colour part of the pipe line or remove the separate view and model matrices and combine them it works. 如果我删除管道的颜色部分或删除单独的视图和模型矩阵并将它们组合起来就可以了。 Even worse, with the same shader code only using one matrix that works I then add the "uniform mat4 trans;" 更糟糕的是,使用相同的着色器代码只使用一个有效的矩阵,然后添加“uniform mat4 trans”; line but don't use it that is enough for the rendering to fail. 但不要使用足以使渲染失败的行。 GL output's no errors. GL输出没有错误。 I'm doing this in Java, I may recode it all in C/C++ to see if that works but I don't think it will. 我在Java中这样做,我可以用C / C ++重新编写它,看看它是否有效,但我认为不会。

This code works on other phones including my old 2.2 ZT-180 tablet! 此代码适用于其他手机,包括我的旧2.2 ZT-180平板电脑!

I may add that some games fail badly on my S2, others work fine. 我可以补充说,有些游戏在我的S2上严重失败,其他游戏工作正常。

I've been coding GLES 2.0 for a few years now and this phone has me stumped. 我已经编写了GLES 2.0几年了,这款手机让我很难过。 I've resorted to shouting at it! 我一直在大喊大叫! ;) ;)

And I have finally found MY bug, I was using 'glBindAttribLocation' incorrectly. 我终于发现了我的错误,我错误地使用了'glBindAttribLocation'。

In using my old C/C++ GLES 2.0 code I've written over the years as reference I had failed to notice that I had been calling glBindAttribLocation before linking the shader. 在使用我多年来编写的旧C / C ++ GLES 2.0代码作为参考时,我没有注意到在链接着色器之前我一直在调用glBindAttribLocation。 Has to be done after compiling but before linking. 必须在编译之后但在链接之前完成。

After going through my code line by line and reading the docs for each function I found this. 在逐行浏览我的代码并阅读每个函数的文档后,我发现了这一点。 Just goes to show, even an experienced coder can slip up. 只是去展示,即使是经验丰富的编码员也可以滑倒。 :) :)

Would have been nice to have. 本来不错的。 Had an error from GL Question is, why did it work on the other phones I tried it?....... 如果GL问题出现错误,为什么它在我试过的其他手机上有效呢?.......

Have you checked your AndroidManifest.xml? 你检查过你的AndroidManifest.xml吗? I have met a similar situation and fix it by using declaration below 我遇到了类似的情况,并使用下面的声明来修复它

<uses-feature android:glEsVersion="0x00020000"/>

And please make sure it's not 请确保不是

android:glEsVersion="2" //Wrong

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM