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 TexturePropertyAccessor} provides the ability to access a
     25  * texture property. Texture properties are accessed by first identifying the active
     26  * texture unit ({@link GLStateType#ACTIVE_TEXTURE_UNIT}), and then identifying the texture
     27  * that is bound to that unit.
     28  */
     29 public class TexturePropertyAccessor implements IGLPropertyAccessor {
     30     private final int mContextId;
     31     private final GLStateType mTargetUnitType;
     32     private final int mMipmapLevel;
     33     private final GLStateType mTextureType;
     34     private TextureUnitPropertyAccessor mTextureUnitPropertyAccessor;
     35 
     36     public TexturePropertyAccessor(int contextId, GLStateType textureUnitTarget, int level,
     37             GLStateType textureTargetName) {
     38         mContextId = contextId;
     39         mTargetUnitType = textureUnitTarget;
     40         mMipmapLevel = level;
     41         mTextureType = textureTargetName;
     42         mTextureUnitPropertyAccessor = new TextureUnitPropertyAccessor(mContextId,
     43                 mTargetUnitType);
     44     }
     45 
     46     public TexturePropertyAccessor(int contextId, GLStateType textureUnitTarget,
     47             GLStateType textureTargetName) {
     48         this(contextId, textureUnitTarget, -1, textureTargetName);
     49     }
     50 
     51     @Override
     52     public IGLProperty getProperty(IGLProperty state) {
     53         // identify the texture that is bound in the current active texture unit
     54         IGLProperty targetTexture = mTextureUnitPropertyAccessor.getProperty(state);
     55         if (!(targetTexture instanceof GLIntegerProperty)) {
     56             return null;
     57         }
     58         Integer textureId = (Integer) targetTexture.getValue();
     59 
     60         // now extract the required property from the selected texture
     61         IGLPropertyAccessor textureAccessor;
     62         if (mMipmapLevel >= 0) {
     63             textureAccessor = GLPropertyAccessor.makeAccessor(mContextId,
     64                     GLStateType.TEXTURE_STATE,
     65                     GLStateType.TEXTURES,
     66                     textureId,
     67                     GLStateType.TEXTURE_MIPMAPS,
     68                     Integer.valueOf(mMipmapLevel),
     69                     mTextureType);
     70         } else {
     71             textureAccessor = GLPropertyAccessor.makeAccessor(mContextId,
     72                     GLStateType.TEXTURE_STATE,
     73                     GLStateType.TEXTURES,
     74                     textureId,
     75                     mTextureType);
     76         }
     77 
     78         return textureAccessor.getProperty(state);
     79     }
     80 
     81     @Override
     82     public String getPath() {
     83         return String.format("TEXTURE_STATE/TEXTURES/${activeTexture}/%s", mTextureType);
     84     }
     85 
     86 }
     87