2011-12-21 155 views
0

我正在制作一个多平台游戏引擎(未来的开源),并且我正在制作一个基于它的游戏。在三星Galaxy S2(I9100B)上进行测试时,它可以完美运行,但是当我尝试在其他手机(Samsung Galaxy S)上运行时,情况变得很糟糕。OpenGL ES 2.0,与所有东西混合

这里是银河S2运行时的屏幕截图:

enter image description here

,这里是当我在Galaxy S的运行:

enter image description here

我设法减少数量三角形也在场景中,但即使在屏幕上有50个三角形,我也遇到了同样的问题。 禁用照明可以减少问题,但不会消除它。我认为这是我的手机内存问题,所以我尝试了另一个Galaxy S,但同样的问题发生。

有人知道我可以从哪里开始寻找?自动GC不频繁(每5秒约2次)。

三星Galaxy S2: 的Android 2.3.4版 内核:2.6.35.7-I9100UHKI2-CL553601 [email protected]#2

三星Galaxy S: 的Android版本2.3.3 Kernek: 2.6.35.7-I9000BVJJW4-CL240848 pescio @ bldhp-4#28

片段着色器代码: precision mediump float;

  uniform sampler2D uSampler; 

      uniform float uIsPoint; 
      uniform float uEnableLight; 
      uniform float uDisableTexture; 

      varying vec4 vColor; 
      varying vec2 vTextureCoord; 

      varying vec4 vPosition; 
      uniform vec3 uPointLightingColor; 

      varying vec3 vColorWeight; 

      void main(){ 

       if(uIsPoint >= 2.0) { 
        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); 
       }else{ 
        vec4 calcColor; 
        if(uEnableLight >= 2.0) 
         calcColor = vec4(vColor.rgb * vColorWeight, vColor.a); 
        else 
         calcColor = vColor; 
        vec4 texColor = vec4(1.0,1.0,1.0,1.0); 
        if(uDisableTexture < 2.0) 
         texColor = texture2D(uSampler, vTextureCoord); 
        gl_FragColor = vec4(texColor.rgb * calcColor.rgb, texColor.a*calcColor.a); 
       } 

      }  

的Vertex Shader代码:

  //Atributos 

      uniform mat4 uMVMatrix; //Model/View Matrix 
      uniform mat4 uPMatrix; //Model/View/Projection Matrix 
      uniform mat3 uNMatrix; //Normal Matrix 

      attribute vec3 aVertexPosition; 
      attribute vec4 aVertexColor; 
      attribute vec2 aTextureCoord; 
      attribute vec3 aNormal; 

      varying vec4 vColor; 
      varying vec2 vTextureCoord; 
      varying vec3 vNormal; 
      varying vec4 vPosition; 

      //Lighting 
      uniform vec3 uAmbientColor; 
      uniform vec3 uLightDir; 
      uniform vec3 uLightColor; 
      uniform vec3 uSpecLightColor; 
      uniform float uShine; 
      varying vec3 vColorWeight; 
      void main(){ 

       //Lighting 
       vec3 normal = normalize(uNMatrix * aNormal); 
       vec3 lightNorm = normalize(uLightDir); 
       float lightWeight = max(dot(aNormal,lightNorm),0.0); 
       vec3 halfVec = normalize(uLightDir - gl_Position.xyz); 
       float specWeight = pow(max(dot(normal,halfVec),0.0),uShine); 
       vColorWeight = uAmbientColor + (lightWeight * uLightColor) + (uSpecLightColor*specWeight); 
       //Others 

       vNormal  = uNMatrix * aNormal; 

       vPosition = uMVMatrix * vec4(aVertexPosition,1.0); 
       gl_Position = uPMatrix * vPosition; 

       vColor = aVertexColor; 
       gl_PointSize = 2.0; 
       vTextureCoord = aTextureCoord; 

      } 

回答

1

尝试增加你的深度缓冲精度。

http://www.opengl.org/wiki/Depth_Buffer_Precision

+0

当我读取深度缓冲区时精度由zFar和zNear规格在制作Perpective Matrix时给出。减少zFar和zNear之间的差异会增加深度缓冲区(如我所读)。我减少到最小值,我可以,为znar 2.5f和24.5f zFar,没有解决:/ - 也试过gl.glDepthFunc(GL10.GL_LEQUAL);但它只是使其工作非常缓慢。 – 2011-12-21 20:52:07

+0

如果你想测试问题是由深度缓冲区引起的,我建议彻底关闭它。 'glDisable(GL_DEPT_TEST);'做到这一点。但是你应该同时启用背面剔除,否则结果会显得很怪异。 – onitake 2011-12-23 16:26:36

0

这看起来像一个顶点顺序问题。 Galaxy S可能会默认开启背面剔除功能,因此它会移除所有不面向观看者的三角形。 哪些三角形朝前,可以glFrontFace()

确定你应该尝试顺时针和逆时针转动,看是否被剔除的和非扑杀三角形切换的地方。如果他们这样做,则必须关闭背面剔除或确保所有三角形的顶点顺序相同。