[Tizen] Support MultiSampling FrameBuffer
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-extensions.cpp
index 553a570..062af6b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/internal/graphics/gles/gl-extensions.h>
 
 // EXTERNAL INCLUDES
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
+#include <dali/internal/graphics/common/egl-include.h>
 
+// INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace Adaptor
 {
-
-namespace ECoreX
-{
-
 GlExtensions::GlExtensions()
 :
 #ifdef GL_EXT_discard_framebuffer
-  mGlDiscardFramebuffer( NULL ),
+  mGlDiscardFramebuffer(nullptr),
 #endif
 #ifdef GL_OES_get_program_binary
-  mGlGetProgramBinaryOES( NULL ),
-  mGlProgramBinaryOES( NULL ),
+  mGlGetProgramBinaryOES(nullptr),
+  mGlProgramBinaryOES(nullptr),
+#endif
+#ifdef GL_KHR_blend_equation_advanced
+  mBlendBarrierKHR(nullptr),
 #endif
-  mInitialized( false )
+#ifdef GL_EXT_multisampled_render_to_texture
+  mGlRenderbufferStorageMultisampleEXT(nullptr),
+  mGlFramebufferTexture2DMultisampleEXT(nullptr),
+#endif
+  mInitialized(false)
 {
 }
 
@@ -53,17 +54,17 @@ GlExtensions::~GlExtensions()
 {
 }
 
-void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
+void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, const GLenumattachments)
 {
   // initialize extension on first use as on some hw platforms a context
   // has to be bound for the extensions to return correct pointer
-  if( !mInitialized )
+  if(DALI_UNLIKELY(!mInitialized))
   {
     Initialize();
   }
 
 #ifdef GL_EXT_discard_framebuffer
-  if( mGlDiscardFramebuffer )
+  if(mGlDiscardFramebuffer)
   {
     mGlDiscardFramebuffer(target, numAttachments, attachments);
   }
@@ -74,17 +75,17 @@ void GlExtensions::DiscardFrameBuffer(GLenum target, GLsizei numAttachments, con
 #endif
 }
 
-void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary)
+void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
 {
   // initialize extension on first use as on some hw platforms a context
   // has to be bound for the extensions to return correct pointer
-  if( !mInitialized )
+  if(DALI_UNLIKELY(!mInitialized))
   {
     Initialize();
   }
 
 #ifdef GL_OES_get_program_binary
-  if (mGlGetProgramBinaryOES)
+  if(mGlGetProgramBinaryOES)
   {
     mGlGetProgramBinaryOES(program, bufSize, length, binaryFormat, binary);
   }
@@ -96,17 +97,17 @@ void GlExtensions::GetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei
 #endif
 }
 
-void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length)
+void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const GLvoidbinary, GLint length)
 {
   // initialize extension on first use as on some hw platforms a context
   // has to be bound for the extensions to return correct pointer
-  if( !mInitialized )
+  if(DALI_UNLIKELY(!mInitialized))
   {
     Initialize();
   }
 
 #ifdef GL_OES_get_program_binary
-  if (mGlProgramBinaryOES)
+  if(mGlProgramBinaryOES)
   {
     mGlProgramBinaryOES(program, binaryFormat, binary, length);
   }
@@ -118,21 +119,93 @@ void GlExtensions::ProgramBinaryOES(GLuint program, GLenum binaryFormat, const G
 #endif
 }
 
+bool GlExtensions::BlendBarrierKHR()
+{
+  // initialize extension on first use as on some hw platforms a context
+  // has to be bound for the extensions to return correct pointer
+  if(DALI_UNLIKELY(!mInitialized))
+  {
+    Initialize();
+  }
+
+#ifdef GL_KHR_blend_equation_advanced
+  if(mBlendBarrierKHR)
+  {
+    mBlendBarrierKHR();
+    return true;
+  }
+  return false;
+#endif
+
+  return false;
+}
+
+void GlExtensions::RenderbufferStorageMultisampleEXT(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
+{
+  // initialize extension on first use as on some hw platforms a context
+  // has to be bound for the extensions to return correct pointer
+  if(DALI_UNLIKELY(!mInitialized))
+  {
+    Initialize();
+  }
+
+#ifdef GL_EXT_multisampled_render_to_texture
+  if(mGlRenderbufferStorageMultisampleEXT)
+  {
+    mGlRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
+  }
+  else
+  {
+    DALI_LOG_ERROR("Error: glRenderbufferStorageMultisampleEXT extension is not available\n");
+    DALI_ASSERT_DEBUG(0);
+  }
+#endif
+}
+
+void GlExtensions::FramebufferTexture2DMultisampleEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples)
+{
+  // initialize extension on first use as on some hw platforms a context
+  // has to be bound for the extensions to return correct pointer
+  if(DALI_UNLIKELY(!mInitialized))
+  {
+    Initialize();
+  }
+
+#ifdef GL_EXT_multisampled_render_to_texture
+  if(mGlFramebufferTexture2DMultisampleEXT)
+  {
+    mGlFramebufferTexture2DMultisampleEXT(target, attachment, textarget, texture, level, samples);
+  }
+  else
+  {
+    DALI_LOG_ERROR("Error: glFramebufferTexture2DMultisampleEXT extension is not available\n");
+    DALI_ASSERT_DEBUG(0);
+  }
+#endif
+}
+
 void GlExtensions::Initialize()
 {
   mInitialized = true;
 
 #ifdef GL_EXT_discard_framebuffer
-  mGlDiscardFramebuffer = reinterpret_cast< PFNGLDISCARDFRAMEBUFFEREXTPROC >( eglGetProcAddress("glDiscardFramebufferEXT") );
+  mGlDiscardFramebuffer = reinterpret_cast<PFNGLDISCARDFRAMEBUFFEREXTPROC>(eglGetProcAddress("glDiscardFramebufferEXT"));
 #endif
 
 #ifdef GL_OES_get_program_binary
-  mGlGetProgramBinaryOES = reinterpret_cast< PFNGLGETPROGRAMBINARYOESPROC >( eglGetProcAddress("glGetProgramBinaryOES") );
-  mGlProgramBinaryOES = reinterpret_cast< PFNGLPROGRAMBINARYOESPROC >( eglGetProcAddress("glProgramBinaryOES") );
+  mGlGetProgramBinaryOES = reinterpret_cast<PFNGLGETPROGRAMBINARYOESPROC>(eglGetProcAddress("glGetProgramBinaryOES"));
+  mGlProgramBinaryOES    = reinterpret_cast<PFNGLPROGRAMBINARYOESPROC>(eglGetProcAddress("glProgramBinaryOES"));
 #endif
-}
 
-} // namespace ECoreX
+#ifdef GL_KHR_blend_equation_advanced
+  mBlendBarrierKHR = reinterpret_cast<PFNGLBLENDBARRIERKHRPROC>(eglGetProcAddress("glBlendBarrierKHR"));
+#endif
+
+#ifdef GL_EXT_multisampled_render_to_texture
+  mGlRenderbufferStorageMultisampleEXT  = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC>(eglGetProcAddress("glRenderbufferStorageMultisampleEXT"));
+  mGlFramebufferTexture2DMultisampleEXT = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC>(eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"));
+#endif
+}
 
 } // namespace Adaptor