Home | History | Annotate | Download | only in transforms
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.gltrace.state.transforms;
     18 
     19 import com.android.ide.eclipse.gltrace.GLEnum;
     20 import com.android.ide.eclipse.gltrace.state.GLIntegerProperty;
     21 import com.android.ide.eclipse.gltrace.state.GLStateType;
     22 import com.android.ide.eclipse.gltrace.state.IGLProperty;
     23 
     24 /**
     25  * An {@link IGLPropertyAccessor} that retrieves the requested property in the
     26  * currently bound {@link GLEnum#GL_ARRAY_BUFFER} or {@link GLEnum#GL_ELEMENT_ARRAY_BUFFER}.
     27  */
     28 public class CurrentVboPropertyAccessor implements IGLPropertyAccessor {
     29     private final int mContextId;
     30     private final IGLPropertyAccessor mVboBindingAccessor;
     31     private final GLStateType mVboProperty;
     32 
     33     public CurrentVboPropertyAccessor(int contextId, GLEnum target, GLStateType vboProperty) {
     34         mContextId = contextId;
     35         mVboProperty = vboProperty;
     36 
     37         GLStateType vboType;
     38         if (target == GLEnum.GL_ARRAY_BUFFER) {
     39             vboType = GLStateType.ARRAY_BUFFER_BINDING;
     40         } else {
     41             vboType = GLStateType.ELEMENT_ARRAY_BUFFER_BINDING;
     42         }
     43 
     44         mVboBindingAccessor = GLPropertyAccessor.makeAccessor(contextId,
     45                 GLStateType.VERTEX_ARRAY_DATA,
     46                 GLStateType.BUFFER_BINDINGS,
     47                 vboType);
     48     }
     49 
     50     @Override
     51     public IGLProperty getProperty(IGLProperty state) {
     52         // obtain the current bound buffer
     53         IGLProperty currentBinding = mVboBindingAccessor.getProperty(state);
     54         if (!(currentBinding instanceof GLIntegerProperty)) {
     55             return null;
     56         }
     57 
     58         Integer buffer = (Integer) currentBinding.getValue();
     59 
     60         return GLPropertyAccessor.makeAccessor(mContextId,
     61                                                GLStateType.VERTEX_ARRAY_DATA,
     62                                                GLStateType.VBO,
     63                                                buffer,
     64                                                mVboProperty).getProperty(state);
     65     }
     66 
     67     @Override
     68     public String getPath() {
     69         return String.format("VERTEX_ARRAY_DATA/VBO/${currentBuffer}/%s", mVboProperty);
     70     }
     71 }
     72