Description.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include <stdint.h>
  17. #include <string.h>
  18. #include <utils/TypeHelpers.h>
  19. #include <GLES2/gl2.h>
  20. #include <GLES2/gl2ext.h>
  21. #include "Description.h"
  22. namespace android {
  23. Description::Description() :
  24. mUniformsDirty(true) {
  25. mPlaneAlpha = 1.0f;
  26. mPremultipliedAlpha = false;
  27. mOpaque = true;
  28. mTextureEnabled = false;
  29. mColorMatrixEnabled = false;
  30. mMaskTextureEnabled = false;
  31. mMaskAlphaThreshold = 0.0f;
  32. memset(mColor, 0, sizeof(mColor));
  33. }
  34. Description::~Description() {
  35. }
  36. void Description::setPlaneAlpha(GLclampf planeAlpha) {
  37. if (planeAlpha != mPlaneAlpha) {
  38. mUniformsDirty = true;
  39. mPlaneAlpha = planeAlpha;
  40. }
  41. }
  42. void Description::setPremultipliedAlpha(bool premultipliedAlpha) {
  43. if (premultipliedAlpha != mPremultipliedAlpha) {
  44. mPremultipliedAlpha = premultipliedAlpha;
  45. }
  46. }
  47. void Description::setOpaque(bool opaque) {
  48. if (opaque != mOpaque) {
  49. mOpaque = opaque;
  50. }
  51. }
  52. void Description::setTexture(const Texture& texture) {
  53. mTexture = texture;
  54. mTextureEnabled = true;
  55. mUniformsDirty = true;
  56. }
  57. void Description::disableTexture() {
  58. mTextureEnabled = false;
  59. }
  60. void Description::setColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
  61. mColor[0] = red;
  62. mColor[1] = green;
  63. mColor[2] = blue;
  64. mColor[3] = alpha;
  65. mUniformsDirty = true;
  66. }
  67. void Description::setProjectionMatrix(const mat4& mtx) {
  68. mProjectionMatrix = mtx;
  69. mUniformsDirty = true;
  70. }
  71. void Description::setColorMatrix(const mat4& mtx) {
  72. const mat4 identity;
  73. mColorMatrix = mtx;
  74. mColorMatrixEnabled = (mtx != identity);
  75. }
  76. const mat4& Description::getColorMatrix() const {
  77. return mColorMatrix;
  78. }
  79. void Description::setMasking(const Texture& maskTexture, float alphaThreshold) {
  80. mMaskTexture = maskTexture;
  81. mMaskTextureEnabled = true;
  82. mMaskAlphaThreshold = alphaThreshold;
  83. }
  84. void Description::disableMasking() {
  85. mMaskTextureEnabled = false;
  86. }
  87. } /* namespace android */