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.state.GLIntegerProperty;
     20 import com.android.ide.eclipse.gltrace.state.GLStateType;
     21 import com.android.ide.eclipse.gltrace.state.IGLProperty;
     22 
     23 /**
     24  * The {@link TextureUnitPropertyAccessor} provides the ability to access a
     25  * texture unit property that is indexed based on the run time value of the
     26  * {@link GLStateType#ACTIVE_TEXTURE_UNIT} property.
     27  */
     28 public class TextureUnitPropertyAccessor implements IGLPropertyAccessor {
     29     private final int mContextId;
     30     private final IGLPropertyAccessor mActiveTextureAccessor;
     31     private final GLStateType mTargetType;
     32 
     33     public TextureUnitPropertyAccessor(int contextId, GLStateType targetPropertyType) {
     34         mContextId = contextId;
     35         mTargetType = targetPropertyType;
     36 
     37         mActiveTextureAccessor = GLPropertyAccessor.makeAccessor(mContextId,
     38                 GLStateType.TEXTURE_STATE,
     39                 GLStateType.ACTIVE_TEXTURE_UNIT);
     40     }
     41 
     42     @Override
     43     public IGLProperty getProperty(IGLProperty state) {
     44         // first extract the current active texture unit
     45         IGLProperty activeTextureProperty = mActiveTextureAccessor.getProperty(state);
     46         if (!(activeTextureProperty instanceof GLIntegerProperty)) {
     47             return null;
     48         }
     49         Integer activeTexture = (Integer) activeTextureProperty.getValue();
     50 
     51         // extract the required property for the current texture unit
     52         IGLPropertyAccessor targetAccessor = GLPropertyAccessor.makeAccessor(mContextId,
     53                 GLStateType.TEXTURE_STATE,
     54                 GLStateType.TEXTURE_UNITS,
     55                 activeTexture,
     56                 mTargetType);
     57         return targetAccessor.getProperty(state);
     58     }
     59 
     60     @Override
     61     public String getPath() {
     62         return String.format("TEXTURE_STATE/TEXTURE_UNITS/${activeTextureUnit}/%s", mTargetType);
     63     }
     64 }
     65