Program.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2013 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 SF_RENDER_ENGINE_PROGRAM_H
  17. #define SF_RENDER_ENGINE_PROGRAM_H
  18. #include <stdint.h>
  19. #include <GLES2/gl2.h>
  20. #include "Description.h"
  21. #include "ProgramCache.h"
  22. namespace android {
  23. class String8;
  24. /*
  25. * Abstracts a GLSL program comprising a vertex and fragment shader
  26. */
  27. class Program {
  28. public:
  29. // known locations for position and texture coordinates
  30. enum { position=0, texCoords=1 };
  31. Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment);
  32. ~Program();
  33. /* whether this object is usable */
  34. bool isValid() const;
  35. /* Binds this program to the GLES context */
  36. void use();
  37. /* Returns the location of the specified attribute */
  38. GLuint getAttrib(const char* name) const;
  39. /* Returns the location of the specified uniform */
  40. GLint getUniform(const char* name) const;
  41. /* set-up uniforms from the description */
  42. void setUniforms(const Description& desc);
  43. private:
  44. GLuint buildShader(const char* source, GLenum type);
  45. String8& dumpShader(String8& result, GLenum type);
  46. // whether the initialization succeeded
  47. bool mInitialized;
  48. // Name of the OpenGL program and shaders
  49. GLuint mProgram;
  50. GLuint mVertexShader;
  51. GLuint mFragmentShader;
  52. /* location of the projection matrix uniform */
  53. GLint mProjectionMatrixLoc;
  54. /* location of the color matrix uniform */
  55. GLint mColorMatrixLoc;
  56. /* location of the texture matrix uniform */
  57. GLint mTextureMatrixLoc;
  58. /* location of the sampler uniform */
  59. GLint mSamplerLoc;
  60. /* location of the alpha plane uniform */
  61. GLint mAlphaPlaneLoc;
  62. /* location of the color uniform */
  63. GLint mColorLoc;
  64. GLint mSamplerMaskLoc;
  65. GLint mMaskAlphaThresholdLoc;
  66. };
  67. } /* namespace android */
  68. #endif /* SF_RENDER_ENGINE_PROGRAM_H */