Project

General

Profile

« Previous | Next » 

Revision 8337fa41

Added by Leszek Koltunski over 7 years ago

Fix issues with the DEPTH attachment to DistortedFramebuffer.

View differences:

src/main/java/org/distorted/library/DistortedFramebuffer.java
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
65 65
// Must be called from a thread holding OpenGL Context
66 66

  
67
  boolean createFBO()
67
  void createFBO()
68 68
    {
69 69
    if( colorIds[0]==NOT_CREATED_YET )
70 70
      {
71 71
      GLES20.glGenTextures(1, colorIds, 0);
72 72
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, colorIds[0]);
73
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
74
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
75 73
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
76 74
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
75
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
76
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
77 77
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
78 78

  
79 79
      GLES20.glGenFramebuffers(1, fboIds, 0);
80 80
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
81 81
      GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, colorIds[0], 0);
82 82

  
83
      int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
84

  
85
      if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
86
        {
87
        android.util.Log.e("DistortedFramebuffer", "failed to create framebuffer, error="+status);
88
        GLES20.glDeleteTextures(1, colorIds, 0);
89
        GLES20.glDeleteFramebuffers(1, fboIds, 0);
90
        fboIds[0]   = 0;
91
        colorIds[0] = FAILED_TO_CREATE;
92
        return false;
93
        }
83
      checkStatus("color");
94 84

  
95 85
      mList.add(this);
96
      //android.util.Log.e("FBO", "created ("+mWidth+","+mHeight+") "+fboIds[0]);
97 86
      }
98 87

  
99 88
    if(  mDepthWanted && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment
......
104 93
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
105 94
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
106 95
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
107
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_DEPTH_COMPONENT, mWidth, mHeight, 0, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_FLOAT, null);
96
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_DEPTH_COMPONENT, mWidth, mHeight, 0, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_UNSIGNED_SHORT, null);
108 97

  
109 98
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
110 99
      GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_TEXTURE_2D, depthIds[0], 0);
111 100

  
112
      int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
113

  
114
      if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
115
        {
116
        android.util.Log.e("DistortedFramebuffer", "failed to create depth, error="+status);
117
        GLES20.glDeleteTextures(1, colorIds, 0);
118
        GLES20.glDeleteFramebuffers(1, fboIds, 0);
119
        fboIds[0]   = 0;
120
        depthIds[0] = FAILED_TO_CREATE;
121
        return false;
122
        }
101
      checkStatus("depth");
123 102
      }
124 103
    if( !mDepthWanted && depthIds[0]!=NOT_CREATED_YET ) // we need to detach and destroy the DEPTH attachment.
125 104
      {
126 105
      GLES20.glDeleteTextures(1, depthIds, 0);
127 106
      depthIds[0]=NOT_CREATED_YET;
128 107
      }
108
    }
109

  
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

  
112
  private boolean checkStatus(String message)
113
    {
114
    int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
115

  
116
    if(status != GLES20.GL_FRAMEBUFFER_COMPLETE)
117
      {
118
      android.util.Log.e("DistortedFramebuffer", "FRAMEBUFFER INCOMPLETE, "+message+" error="+status);
119

  
120
      GLES20.glDeleteTextures(1, colorIds, 0);
121
      GLES20.glDeleteTextures(1, depthIds, 0);
122
      GLES20.glDeleteFramebuffers(1, fboIds, 0);
123
      fboIds[0]   = 0;
124
      colorIds[0] = FAILED_TO_CREATE;
125
      depthIds[0] = FAILED_TO_CREATE;
126

  
127
      return false;
128
      }
129 129

  
130 130
    return true;
131 131
    }

Also available in: Unified diff