Project

General

Profile

« Previous | Next » 

Revision 3d804c91

Added by Leszek Koltunski over 7 years ago

Minor stuff in DistortedProgram.

View differences:

src/main/java/org/distorted/library/program/DistortedProgram.java
42 42
  private int mNumAttributes;
43 43
  private int[] mAttribute;
44 44
  private String[] mAttributeName;
45
  private String mAttributeTmp;
46 45

  
47 46
///////////////////////////////////////////////////////////////////////////////////////////////////
48 47

  
......
89 88

  
90 89
///////////////////////////////////////////////////////////////////////////////////////////////////
91 90

  
92
  private void doAttributes(final String line)
91
  private String parseOutAttribute(final String line)
93 92
    {
94 93
    int len = line.length();
95 94
    int whiteSpace, semicolon, nameBegin;
......
122 121

  
123 122
          if( currChar==' ' || currChar=='\t' )
124 123
            {
125
            subline = subline.substring(nameBegin+1,subLen);
126
            //android.util.Log.d("program", "new attribute: "+subline);
127

  
128
            if( mAttributeTmp.length()>0 ) mAttributeTmp+=" ";
129
            mAttributeTmp += subline;
130 124
            mNumAttributes++;
131
            break;
125
            return subline.substring(nameBegin+1,subLen);
132 126
            }
133 127
          }
134 128
        }
135 129
      }
130

  
131
    return null;
136 132
    }
137 133

  
138 134
///////////////////////////////////////////////////////////////////////////////////////////////////
......
142 138
    final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
143 139
    final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
144 140

  
145
    String nextLine;
141
    String nextLine, attribute, attrList="";
146 142
    final StringBuilder body = new StringBuilder();
147 143

  
148 144
    try
......
152 148
        body.append(nextLine);
153 149
        body.append('\n');
154 150

  
155
        if( doAttributes ) doAttributes(nextLine);
151
        if( doAttributes )
152
          {
153
          attribute = parseOutAttribute(nextLine);
154

  
155
          if( attribute!=null )
156
            {
157
            //android.util.Log.d("program", "new attribute: "+attribute);
158
            if( attrList.length()>0 ) attrList+=" ";
159
            attrList += attribute;
160
            }
161
          }
156 162
        }
157 163
      }
158 164
    catch (IOException e)
......
163 169
    if( doAttributes )
164 170
      {
165 171
      mAttribute = new int[mNumAttributes];
166
      mAttributeName = mAttributeTmp.split(" ");
167
      mAttributeTmp = "";
168
/*
169
      int len = mAttributeName.length;
170

  
171
      for(int i=0; i<len; i++)
172
        {
173
        android.util.Log.e("program","ATTRIBUTE "+i+" :" + mAttributeName[i]);
174
        }
175

  
176
      android.util.Log.e("program","mNumAttributes: "+mNumAttributes);
177
*/
172
      mAttributeName = attrList.split(" ");
178 173
      }
179 174

  
180 175
    return body.toString();
......
274 269
                                      break;
275 270
     }
276 271

  
277
    //Log.d(TAG,""+header);
272
    //android.util.Log.d("program",""+header);
278 273

  
279 274
    return header;
280 275
    }
......
289 284
   *
290 285
   * @param vertex   InputStream containing the opened Resource file from where to read vertex shader code.
291 286
   * @param fragment InputStream containing the opened Resource file from where to read fragment shader code.
292
   *
287
   * @throws FragmentCompilationException
288
   * @throws VertexCompilationException
289
   * @throws VertexUniformsException
290
   * @throws FragmentUniformsException
291
   * @throws LinkingException
293 292
   */
294 293

  
295 294
  public DistortedProgram(final InputStream vertex, final InputStream fragment)
296 295
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
297 296
    {
298 297
    mNumAttributes = 0;
299
    mAttributeTmp  = "";
300 298

  
301 299
    final String vertexShader   = readTextFileFromRawResource(vertex  , true );
302 300
    final String fragmentShader = readTextFileFromRawResource(fragment, false);
......
310 308
    }
311 309

  
312 310
///////////////////////////////////////////////////////////////////////////////////////////////////
313

  
311
/**
312
 * Return the indexes off all attributes.
313
 */
314 314
  public int[] getAttributes()
315 315
    {
316 316
    return mAttribute;
317 317
    }
318 318

  
319 319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

  
320
/**
321
 * Return the names of all vertex attributes.
322
 */
321 323
  public String[] getAttributeNames()
322 324
    {
323 325
    return mAttributeName;
324 326
    }
325 327

  
326 328
///////////////////////////////////////////////////////////////////////////////////////////////////
327

  
329
/**
330
 * Return the handle of the created program so that we can later, say, call glUseProgram.
331
 */
328 332
  public int getProgramHandle()
329 333
    {
330 334
    return mProgramHandle;
331 335
    }
332 336

  
333 337
///////////////////////////////////////////////////////////////////////////////////////////////////
334
// glUseProgram first; needs to be called from a thread holding the OpenGL context
338
/**
339
 * Bind all vertex attributes and enable them.
340
 * <p>
341
 * This assumes Program is in use. Call glUseProgram first.
342
 * Needs to be called from a thread holding the OpenGL context.
343
 */
335 344

  
336 345
  public void bindAndEnableAttributes()
337 346
    {

Also available in: Unified diff