GLES10RenderEngine.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <GLES/gl.h>
  17. #include <cutils/compiler.h>
  18. #include "GLES10RenderEngine.h"
  19. // ---------------------------------------------------------------------------
  20. namespace android {
  21. // ---------------------------------------------------------------------------
  22. GLES10RenderEngine::~GLES10RenderEngine() {
  23. }
  24. void GLES10RenderEngine::setupLayerBlending(
  25. bool premultipliedAlpha, bool opaque, int alpha) {
  26. // OpenGL ES 1.0 doesn't support texture combiners.
  27. // This path doesn't properly handle opaque layers that have non-opaque
  28. // alpha values. The alpha channel will be copied into the framebuffer or
  29. // screenshot, so if the framebuffer or screenshot is blended on top of
  30. // something else, whatever is below the window will incorrectly show
  31. // through.
  32. if (CC_UNLIKELY(alpha < 0xFF)) {
  33. GLfloat floatAlpha = alpha * (1.0f / 255.0f);
  34. if (premultipliedAlpha) {
  35. glColor4f(floatAlpha, floatAlpha, floatAlpha, floatAlpha);
  36. } else {
  37. glColor4f(1.0f, 1.0f, 1.0f, floatAlpha);
  38. }
  39. glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  40. } else {
  41. glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  42. }
  43. if (alpha < 0xFF || !opaque) {
  44. glEnable(GL_BLEND);
  45. glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA,
  46. GL_ONE_MINUS_SRC_ALPHA);
  47. } else {
  48. glDisable(GL_BLEND);
  49. }
  50. }
  51. // ---------------------------------------------------------------------------
  52. }; // namespace android
  53. // ---------------------------------------------------------------------------