2009-05-22 14:03:28 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_RS_PROGRAM_H
|
|
|
|
#define ANDROID_RS_PROGRAM_H
|
|
|
|
|
|
|
|
#include "rsObjectBase.h"
|
|
|
|
#include "rsElement.h"
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace android {
|
|
|
|
namespace renderscript {
|
2009-11-25 13:22:07 -08:00
|
|
|
class ShaderCache;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2010-09-14 09:50:43 -07:00
|
|
|
#define RS_SHADER_INTERNAL "//rs_shader_internal\n"
|
2010-09-29 09:49:13 -07:00
|
|
|
#define RS_SHADER_ATTR "ATTRIB_"
|
|
|
|
#define RS_SHADER_UNI "UNI_"
|
2010-09-14 09:50:43 -07:00
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
class Program : public ObjectBase {
|
2009-05-22 14:03:28 -07:00
|
|
|
public:
|
2009-11-25 13:22:07 -08:00
|
|
|
|
2009-12-15 12:58:36 -08:00
|
|
|
Program(Context *);
|
|
|
|
Program(Context *, const char * shaderText, uint32_t shaderLength,
|
|
|
|
const uint32_t * params, uint32_t paramLength);
|
2009-05-22 14:03:28 -07:00
|
|
|
virtual ~Program();
|
|
|
|
|
2010-09-23 16:16:33 -07:00
|
|
|
void bindAllocation(Context *, Allocation *, uint32_t slot);
|
2009-11-25 13:22:07 -08:00
|
|
|
virtual void createShader();
|
|
|
|
|
2010-09-14 09:50:43 -07:00
|
|
|
bool isUserProgram() const {return !mIsInternal;}
|
2010-01-06 11:57:52 -08:00
|
|
|
|
2010-09-23 16:16:33 -07:00
|
|
|
void bindTexture(Context *, uint32_t slot, Allocation *);
|
|
|
|
void bindSampler(Context *, uint32_t slot, Sampler *);
|
2009-12-17 16:55:08 -08:00
|
|
|
|
2009-11-25 13:22:07 -08:00
|
|
|
uint32_t getShaderID() const {return mShaderID;}
|
2009-11-30 14:49:55 -08:00
|
|
|
void setShader(const char *, uint32_t len);
|
2009-11-25 13:22:07 -08:00
|
|
|
|
|
|
|
uint32_t getAttribCount() const {return mAttribCount;}
|
|
|
|
uint32_t getUniformCount() const {return mUniformCount;}
|
|
|
|
const String8 & getAttribName(uint32_t i) const {return mAttribNames[i];}
|
|
|
|
const String8 & getUniformName(uint32_t i) const {return mUniformNames[i];}
|
2010-11-08 15:10:52 -08:00
|
|
|
uint32_t getUniformArraySize(uint32_t i) const {return mUniformArraySizes[i];}
|
2009-08-05 13:57:03 -07:00
|
|
|
|
2010-01-04 16:52:27 -08:00
|
|
|
String8 getGLSLInputString() const;
|
|
|
|
String8 getGLSLOutputString() const;
|
|
|
|
String8 getGLSLConstantString() const;
|
|
|
|
|
2010-03-03 13:03:18 -08:00
|
|
|
bool isValid() const {return mIsValid;}
|
2010-11-08 15:10:52 -08:00
|
|
|
void forceDirty() const {mDirty = true;}
|
2010-03-03 13:03:18 -08:00
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
protected:
|
|
|
|
// Components not listed in "in" will be passed though
|
|
|
|
// unless overwritten by components in out.
|
2009-12-15 12:58:36 -08:00
|
|
|
ObjectBaseRef<Element> *mInputElements;
|
|
|
|
ObjectBaseRef<Element> *mOutputElements;
|
|
|
|
ObjectBaseRef<Type> *mConstantTypes;
|
2010-11-08 15:10:52 -08:00
|
|
|
ObjectBaseRef<Allocation> *mConstants;
|
2009-12-15 12:58:36 -08:00
|
|
|
uint32_t mInputCount;
|
|
|
|
uint32_t mOutputCount;
|
|
|
|
uint32_t mConstantCount;
|
2010-03-03 13:03:18 -08:00
|
|
|
bool mIsValid;
|
2010-09-14 09:50:43 -07:00
|
|
|
bool mIsInternal;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2010-08-31 12:02:01 -07:00
|
|
|
// Applies to vertex and fragment shaders only
|
|
|
|
void appendUserConstants();
|
2010-09-23 16:16:33 -07:00
|
|
|
void setupUserConstants(Context *rsc, ShaderCache *sc, bool isFragment);
|
2010-11-08 15:10:52 -08:00
|
|
|
void initAddUserElement(const Element *e, String8 *names, uint32_t *arrayLengths, uint32_t *count, const char *prefix);
|
2010-08-31 12:02:01 -07:00
|
|
|
|
2010-11-08 15:10:52 -08:00
|
|
|
void initAttribAndUniformArray();
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2009-08-05 13:57:03 -07:00
|
|
|
mutable bool mDirty;
|
2009-11-25 13:22:07 -08:00
|
|
|
String8 mShader;
|
2009-11-30 14:49:55 -08:00
|
|
|
String8 mUserShader;
|
2009-11-25 13:22:07 -08:00
|
|
|
uint32_t mShaderID;
|
|
|
|
|
2009-12-15 13:27:04 -08:00
|
|
|
uint32_t mTextureCount;
|
2009-11-25 13:22:07 -08:00
|
|
|
uint32_t mAttribCount;
|
|
|
|
uint32_t mUniformCount;
|
2010-11-08 15:10:52 -08:00
|
|
|
String8 *mAttribNames;
|
|
|
|
String8 *mUniformNames;
|
|
|
|
uint32_t *mUniformArraySizes;
|
|
|
|
|
|
|
|
void logUniform(const Element *field, const float *fd, uint32_t arraySize );
|
|
|
|
void setUniform(Context *rsc, const Element *field, const float *fd, int32_t slot, uint32_t arraySize );
|
|
|
|
void initMemberVars();
|
2009-10-15 18:45:45 -07:00
|
|
|
|
2009-12-17 16:55:08 -08:00
|
|
|
// The difference between Textures and Constants is how they are accessed
|
|
|
|
// Texture lookups go though a sampler which in effect converts normalized
|
|
|
|
// coordinates into type specific. Multiple samples may also be taken
|
|
|
|
// and filtered.
|
|
|
|
//
|
|
|
|
// Constants are strictly accessed by programetic loads.
|
2010-09-23 16:16:33 -07:00
|
|
|
ObjectBaseRef<Allocation> *mTextures;
|
|
|
|
ObjectBaseRef<Sampler> *mSamplers;
|
2010-11-18 15:22:43 -08:00
|
|
|
RsTextureTarget *mTextureTargets;
|
2009-12-15 19:10:11 -08:00
|
|
|
bool loadShader(Context *, uint32_t type);
|
2009-05-22 14:03:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|