Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
support opengl es 3.0 on iOS (#53)
Browse files Browse the repository at this point in the history
* version @ v0.3.5
* add opengl es 2.0 vs 3.0 definitions for planar and biplanar texture formats

```
#if defined(OGLES_GPGPU_OPENGL_ES3)
#  define OGLES_GPGPU_PLANAR_INTERNAL_FORMAT GL_R8
#  define OGLES_GPGPU_PLANAR_FORMAT GL_RED
#  define OGLES_GPGPU_BIPLANAR_INTERNAL_FORMAT GL_RG8
#  define OGLES_GPGPU_BIPLANAR_FORMAT GL_RG
#else
#  define OGLES_GPGPU_PLANAR_INTERNAL_FORMAT GL_LUMINANCE
#  define OGLES_GPGPU_PLANAR_FORMAT GL_LUMINANCE
#  define OGLES_GPGPU_BIPLANAR_INTERNAL_FORMAT GL_LUMINANCE_ALPHA
#  define OGLES_GPGPU_BIPLANAR_FORMAT GL_LUMINANCE_ALPHA
#endif
```

* update cmake/sugar to support platform optimizations (memtransfer_ios.{h,cpp}) on iOS when `OGLES_GPGPU_OPENGL_ES3 == ON`
* toggle between `kRG` (ES 3.0) and `kLA` (ES 2.0) shader  types for internal Yuv2RgbProc instantiation
* removed unused include
* disable platform optimized memtransfer for android, since the required system dlopen/dlsym calls are prohibited in recent android releases and PBO transfers are a fairl efficient generic option available in OpenGL es 3.0
  • Loading branch information
headupinclouds committed Sep 12, 2018
1 parent c1f1112 commit 0ed7d00
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 42 deletions.
12 changes: 3 additions & 9 deletions ogles_gpgpu/common/gl/memtransfer_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
#include "../core.h"

// clang-off
#if defined(OGLES_GPGPU_IOS) && !defined(OGLES_GPGPU_OPENGL_ES3)
#if defined(OGLES_GPGPU_IOS)
# include "../../platform/ios/memtransfer_ios.h"
#elif defined(OGLES_GPGPU_ANDROID) && !defined(OGLES_GPGPU_OPENGL_ES3)
# include "../../platform/android/memtransfer_android.h"
#else
# include "../../platform/opengl/memtransfer_generic.h"
#endif
Expand All @@ -28,10 +26,8 @@ std::unique_ptr<MemTransfer> MemTransferFactory::createInstance() {
std::unique_ptr<MemTransfer> instance;

if (usePlatformOptimizations) { // create specialized instance
#if defined(OGLES_GPGPU_IOS) && !defined(OGLES_GPGPU_OPENGL_ES3)
#if defined(OGLES_GPGPU_IOS)
instance = std::unique_ptr<MemTransfer>(new MemTransferIOS);
#elif defined(OGLES_GPGPU_ANDROID) && !defined(OGLES_GPGPU_OPENGL_ES3)
instance = std::unique_ptr<MemTransfer>(new MemTransferAndroid);
#else
instance = std::unique_ptr<MemTransfer>(new MemTransfer);
#endif
Expand All @@ -45,10 +41,8 @@ std::unique_ptr<MemTransfer> MemTransferFactory::createInstance() {
}

bool MemTransferFactory::tryEnablePlatformOptimizations() {
#if defined(OGLES_GPGPU_IOS) && !defined(OGLES_GPGPU_OPENGL_ES3)
#if defined(OGLES_GPGPU_IOS)
usePlatformOptimizations = MemTransferIOS::initPlatformOptimizations();
#elif defined(OGLES_GPGPU_ANDROID) && !defined(OGLES_GPGPU_OPENGL_ES3)
usePlatformOptimizations = MemTransferAndroid::initPlatformOptimizations();
#else
usePlatformOptimizations = false;
#endif
Expand Down
8 changes: 7 additions & 1 deletion ogles_gpgpu/common/proc/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#include "yuv2rgb.h"
#include <ogles_gpgpu/common/gl/memtransfer_optimized.h>

#if defined(OGLES_GPGPU_OPENGL_ES3)
# define OGLES_GPGPU_BIPLANAR_CHANNEL_KIND Yuv2RgbProc::kRG
#else
# define OGLES_GPGPU_BIPLANAR_CHANNEL_KIND Yuv2RgbProc::kLA
#endif

using namespace ogles_gpgpu;

VideoSource::VideoSource(void* glContext) {
Expand Down Expand Up @@ -44,7 +50,7 @@ GLuint VideoSource::getInputTexId() {
void VideoSource::configurePipeline(const Size2d& size, GLenum inputPixFormat) {
if (inputPixFormat == 0) { // 0 == NV{12,21}
if (!yuv2RgbProc) {
yuv2RgbProc = std::make_shared<ogles_gpgpu::Yuv2RgbProc>();
yuv2RgbProc = std::make_shared<ogles_gpgpu::Yuv2RgbProc>(Yuv2RgbProc::k601VideoRange, OGLES_GPGPU_BIPLANAR_CHANNEL_KIND);
yuv2RgbProc->setExternalInputDataFormat(inputPixFormat);
yuv2RgbProc->init(size.width, size.height, 0, true);
frameSize = size;
Expand Down
10 changes: 4 additions & 6 deletions ogles_gpgpu/platform/ios/memtransfer_ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include "../../common/core.h"

#include "../../common/proc/yuv2rgb.h"

/**
* Most code as from http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/
*/
Expand Down Expand Up @@ -280,10 +278,10 @@ GLuint MemTransferIOS::prepareInput(int inTexW, int inTexH, GLenum inputPxFormat
bufRef,
NULL,
GL_TEXTURE_2D,
GL_LUMINANCE,
OGLES_GPGPU_PLANAR_INTERNAL_FORMAT,
inputW,
inputH,
GL_LUMINANCE,
OGLES_GPGPU_PLANAR_FORMAT,
GL_UNSIGNED_BYTE,
0,
&luminanceTextureRef);
Expand All @@ -305,10 +303,10 @@ GLuint MemTransferIOS::prepareInput(int inTexW, int inTexH, GLenum inputPxFormat
bufRef,
NULL,
GL_TEXTURE_2D,
GL_LUMINANCE_ALPHA,
OGLES_GPGPU_BIPLANAR_INTERNAL_FORMAT,
inputW / 2,
inputH / 2,
GL_LUMINANCE_ALPHA,
OGLES_GPGPU_BIPLANAR_FORMAT,
GL_UNSIGNED_BYTE,
1,
&chrominanceTextureRef);
Expand Down
4 changes: 0 additions & 4 deletions ogles_gpgpu/platform/ios/memtransfer_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

namespace ogles_gpgpu {

class Yuv2RgbProc; // forward declaration

/**
* MemTransferIOS is a platform specific implementation for fast texture access on iOS platforms.
* It uses CoreVideo's TextureCache API as explained at
Expand Down Expand Up @@ -142,8 +140,6 @@ class MemTransferIOS : public MemTransfer, public MemTransferOptimized {

size_t inputPixelBufferSize; // input pixel buffer size in bytes
size_t outputPixelBufferSize; // output pixel buffer size in bytes

std::shared_ptr<Yuv2RgbProc> yuv2rgb;
};
}
#endif
12 changes: 12 additions & 0 deletions ogles_gpgpu/platform/opengl/gl_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
#else
# define OGLES_GPGPU_TEXTURE_FORMAT GL_BGRA
#endif

#if defined(OGLES_GPGPU_OPENGL_ES3)
# define OGLES_GPGPU_PLANAR_INTERNAL_FORMAT GL_R8
# define OGLES_GPGPU_PLANAR_FORMAT GL_RED
# define OGLES_GPGPU_BIPLANAR_INTERNAL_FORMAT GL_RG8
# define OGLES_GPGPU_BIPLANAR_FORMAT GL_RG
#else
# define OGLES_GPGPU_PLANAR_INTERNAL_FORMAT GL_LUMINANCE
# define OGLES_GPGPU_PLANAR_FORMAT GL_LUMINANCE
# define OGLES_GPGPU_BIPLANAR_INTERNAL_FORMAT GL_LUMINANCE_ALPHA
# define OGLES_GPGPU_BIPLANAR_FORMAT GL_LUMINANCE_ALPHA
#endif
// clang-format off

#endif // OGLES_GPGPU_OPENGL_GL_INCLUDES
28 changes: 6 additions & 22 deletions ogles_gpgpu/platform/sugar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,12 @@ endif()

include(sugar_include)

if(ANDROID OR IOS)
set(ogles_gpgpu_is_mobile TRUE)
# We drop support for sugar_include(android) due to platforms
# specific extensions that require dlopen() based system lib
# access, since dlopen() calls are blocked in recent versions
# of Android.
if(IOS)
sugar_include(ios)
else()
set(ogles_gpgpu_is_mobile FALSE)
endif()

# We will use the vanilla OpenGL implementation in case
# of standard OpenGL platforms (i.e., not OpenGL ES) or
# in cases where >= OpenGL ES 3.0 is available. On those
# platforms we can use PBO for efficient GPU->CPU reads.
# If we are using OpenGL ES 2.0 on mobile devices then
# we will use platform specific extensions to facilitate
# efficient DMA reads of OpenGL textures.
if(OGLES_GPGPU_OPENGL_ES3 OR NOT ${ogles_gpgpu_is_mobile})
sugar_include(opengl)
else()
if(IOS)
sugar_include(ios)
elseif(ANDROID)
sugar_include(android )
endif()
endif()



0 comments on commit 0ed7d00

Please sign in to comment.