Home | History | Annotate | Download | only in rs
      1 /*
      2  * Copyright (C) 2011 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 #ifndef ANDROID_RS_PROGRAM_H
     18 #define ANDROID_RS_PROGRAM_H
     19 
     20 #include "rsProgramBase.h"
     21 #include "rsElement.h"
     22 
     23 // ---------------------------------------------------------------------------
     24 namespace android {
     25 namespace renderscript {
     26 
     27 #define RS_SHADER_INTERNAL "//rs_shader_internal\n"
     28 #define RS_SHADER_ATTR "ATTRIB_"
     29 #define RS_SHADER_UNI "UNI_"
     30 
     31 class Program : public ProgramBase {
     32 public:
     33     struct Hal {
     34         mutable void *drv;
     35 
     36         struct State {
     37             // The difference between Textures and Constants is how they are accessed
     38             // Texture lookups go though a sampler which in effect converts normalized
     39             // coordinates into type specific.  Multiple samples may also be taken
     40             // and filtered.
     41             //
     42             // Constants are strictly accessed by the shader code
     43             Allocation **textures;
     44             RsTextureTarget *textureTargets;
     45             uint32_t texturesCount;
     46 
     47             Sampler **samplers;
     48             uint32_t samplersCount;
     49 
     50             Allocation **constants;
     51             Type **constantTypes;
     52             uint32_t constantsCount;
     53 
     54             Element **inputElements;
     55             uint32_t inputElementsCount;
     56         };
     57         State state;
     58     };
     59     Hal mHal;
     60 
     61     Program(Context *, const char * shaderText, uint32_t shaderLength,
     62                        const uint32_t * params, uint32_t paramLength);
     63     virtual ~Program();
     64     virtual bool freeChildren();
     65 
     66     void bindAllocation(Context *, Allocation *, uint32_t slot);
     67 
     68     bool isUserProgram() const {return !mIsInternal;}
     69 
     70     void bindTexture(Context *, uint32_t slot, Allocation *);
     71     void bindSampler(Context *, uint32_t slot, Sampler *);
     72 
     73 protected:
     74     ObjectBaseRef<Allocation> *mTextures;
     75     ObjectBaseRef<Sampler> *mSamplers;
     76     ObjectBaseRef<Allocation> *mConstants;
     77     ObjectBaseRef<Type> *mConstantTypes;
     78     ObjectBaseRef<Element> *mInputElements;
     79 
     80     bool mIsInternal;
     81     String8 mUserShader;
     82     void initMemberVars();
     83 };
     84 
     85 }
     86 }
     87 #endif // ANDROID_RS_PROGRAM_H
     88 
     89 
     90 
     91