Exemplo n.º 1
0
void FindBestDepthBias()
{
#ifdef ANDROID_EDITION
  int hardwareType = Android_JNI_GetHardwareType();
  Android_JNI_GetPolygonOffset(hardwareType, 1, &polygonOffsetFactor, &polygonOffsetUnits);
#else
  float f, bestz = 0.25f;
  int x;
  if (biasFactor) return;
  biasFactor = 64.0f; // default value
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_ALWAYS);
  glEnable(GL_POLYGON_OFFSET_FILL);
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glDisable(GL_BLEND);
  glDisable(GL_ALPHA_TEST);
  glColor4ub(255,255,255,255);
  glDepthMask(GL_TRUE);
  for (x=0, f=1.0f; f<=65536.0f; x+=4, f*=2.0f) {
    float z;
    glPolygonOffset(0, f);
    glBegin(GL_TRIANGLE_STRIP);
    glVertex3f(float(x+4 - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5);
    glVertex3f(float(x - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5);
    glVertex3f(float(x+4 - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5);
    glVertex3f(float(x - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5);
    glEnd();
    glReadPixels(x+2, 2+viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
    z -= 0.75f + 8e-6f;
    if (z<0.0f) z = -z;
    if (z > 0.01f) continue;
    if (z < bestz) {
      bestz = z;
      biasFactor = f;
    }
    //printf("f %g z %g\n", f, z);
  }
  //printf(" --> bias factor %g\n", biasFactor);
  glPopAttrib();
#endif
}
Exemplo n.º 2
0
void OGLRender::ApplyZBias(int bias)
{
    float f1 = bias > 0 ? -3.0f : 0.0f;  // z offset = -3.0 * max(abs(dz/dx),abs(dz/dy)) per pixel delta z slope
    float f2 = bias > 0 ? -3.0f : 0.0f;  // z offset += -3.0 * 1 bit

#ifdef PAULSCODE
    Android_JNI_GetPolygonOffset(hardwareType, bias, &f1, &f2);
#endif

    if (bias > 0)
    {
        glEnable(GL_POLYGON_OFFSET_FILL);  // enable z offsets
        OPENGL_CHECK_ERRORS;
    }
    else
    {
        glDisable(GL_POLYGON_OFFSET_FILL);  // disable z offsets
        OPENGL_CHECK_ERRORS;
    }
    glPolygonOffset(f1, f2);  // set bias functions
    OPENGL_CHECK_ERRORS;
}