浏览代码

release gl context

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
ee326de5
共有 3 个文件被更改,包括 18 次插入27 次删除
  1. 2
      Samples/UIWidgetsSamples_2019_4/Assets/AndroidWorkAround.cs
  2. 31
      engine/src/shell/platform/unity/android/unity_surface_manager.cc
  3. 12
      engine/src/shell/platform/unity/android/unity_surface_manager.h

2
Samples/UIWidgetsSamples_2019_4/Assets/AndroidWorkAround.cs


public class AndroidWorkAround : MonoBehaviour
{
public UIWidgetsPanel panel;
UIWidgetsPanel panel;
// Start is called before the first frame update
void Start()

31
engine/src/shell/platform/unity/android/unity_surface_manager.cc


#include "unity_surface_manager.h"
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include "src/shell/common/shell_io_manager.h"

using EGLResult = std::pair<bool, T>;
UnitySurfaceManager::UnitySurfaceManager(IUnityInterfaces *unity_interfaces)
: // egl_display_(EGL_NO_DISPLAY),
egl_context_(EGL_NO_CONTEXT),
egl_resource_context_(EGL_NO_CONTEXT)
: egl_context_(EGL_NO_CONTEXT),
egl_resource_context_(EGL_NO_CONTEXT)
{
initialize_succeeded_ = Initialize(unity_interfaces);
}

GLuint UnitySurfaceManager::CreateRenderSurface(void *native_texture_ptr)
{
auto read = eglGetCurrentSurface(EGL_READ);
auto draw = eglGetCurrentSurface(EGL_DRAW);
// auto state = eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_) == GL_TRUE;
GLint old_framebuffer_binding;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding);

FML_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding);
// eglMakeCurrent(egl_display_, draw, read, egl_unity_context_);
return fbo_;
}

return {context != EGL_NO_CONTEXT, context};
}
void UnitySurfaceManager::GetUnityContext(){
void UnitySurfaceManager::GetUnityContext()
{
egl_display_ = eglGetCurrentDisplay();
egl_unity_context_ = eglGetCurrentContext();
FML_CHECK(egl_display_ != EGL_NO_DISPLAY)

bool UnitySurfaceManager::Initialize(IUnityInterfaces *unity_interfaces)
{
// egl_display_ = eglGetCurrentDisplay();
// egl_resource_context_ = eglGetCurrentContext();
FML_CHECK(egl_display_ != EGL_NO_DISPLAY)
<< "Renderer type is invalid";

std::tie(success, egl_context_) = CreateContext(egl_display_, egl_config_, egl_unity_context_);
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_);
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_);
return success;
}

if (egl_display_ != EGL_NO_DISPLAY &&
egl_resource_context_ != EGL_NO_CONTEXT)
{
eglDestroyContext(egl_display_, egl_resource_context_);
egl_resource_context_ = EGL_NO_CONTEXT;
}
if (egl_display_ != EGL_NO_DISPLAY && egl_context_ != EGL_NO_CONTEXT)
{
eglDestroyContext(egl_display_, egl_context_);
egl_context_ = EGL_NO_CONTEXT;
}
}
} // namespace uiwidgets

12
engine/src/shell/platform/unity/android/unity_surface_manager.h


class UnitySurfaceManager
{
public:
static UnitySurfaceManager instance;
static void GetUnityContext();
UnitySurfaceManager(IUnityInterfaces *unity_interfaces);

bool MakeResourceCurrent();
// EGLDisplay GetEGLDisplay() const { return egl_display_; }
// ID3D11Device* GetD3D11Device() const { return d3d11_device_; }
FML_DISALLOW_COPY_AND_ASSIGN(UnitySurfaceManager);
private:

// GrBackendTexture m_backendTex;
// GrGLTextureInfo textureInfo;
// sk_sp<SkSurface> m_SkSurface;
// sk_sp<GrContext> gr_context_;
// EGLConfig egl_config_;
bool initialize_succeeded_;
GLuint fbo_ = 0;

正在加载...
取消
保存