rsProgram.h 2.7 KB

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