浏览代码

try

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
c280e8e3
共有 4 个文件被更改,包括 111 次插入13 次删除
  1. 28
      Samples/UIWidgetsSamples_2019_4/Assets/ANT.cs
  2. 17
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  3. 77
      engine/src/shell/platform/unity/android/unity_surface_manager.cc
  4. 2
      engine/src/shell/platform/unity/android/unity_surface_manager.h

28
Samples/UIWidgetsSamples_2019_4/Assets/ANT.cs


#else
[DllImport ("libUIWidgets_d")]
#endif
private static extern void SetTextureFromUnity2(System.IntPtr texture, int w, int h);
private static extern System.IntPtr SetTextureFromUnity2(System.IntPtr texture, int w, int h);
#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR
[DllImport ("__Internal")]

private static extern void draw_xxx();
#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR
[DllImport ("__Internal")]
#else
[DllImport ("libUIWidgets_d")]
#endif
private static extern System.IntPtr GetRenderEventFunc();
// Start is called before the first frame update
IEnumerator Start()

private void CreateTextureAndPassToPlugin()
{
Texture2D tex = new Texture2D(256,256,TextureFormat.ARGB32,false);
var width = 256;
var height = 256;
Texture2D tex = new Texture2D(width,height,TextureFormat.ARGB32,false);
// Set point filtering just so we can see the pixels clearly
tex.filterMode = FilterMode.Point;
// Call Apply() so it's actually uploaded to the GPU

GetComponent<Renderer>().material.mainTexture = tex;
#if !UNITY_EDITOR
// Pass texture pointer to the plugin
SetTextureFromUnity2 (tex.GetNativeTexturePtr(), tex.width, tex.height);
#endif
// #if !UNITY_EDITOR
// // Pass texture pointer to the plugin
System.IntPtr ptr = SetTextureFromUnity2 (tex.GetNativeTexturePtr(), tex.width, tex.height);
if (ptr != System.IntPtr.Zero)
{
var texEx = Texture2D.CreateExternalTexture(width, height, TextureFormat.BGRA32, false, true, ptr);
GetComponent<Renderer>().material.mainTexture = texEx;
}
GL.IssuePluginEvent(GetRenderEventFunc(), 1);
// #endif
}
private IEnumerator CallPluginAtEndOfFrames()

// Wait until all frame rendering is done
yield return new WaitForEndOfFrame();
#if !UNITY_EDITOR
// GL.IssuePluginEvent(GetRenderEventFunc(), 1);
draw_xxx();
#endif
}

17
engine/src/shell/platform/unity/android/uiwidgets_panel.cc


#include "shell/platform/embedder/embedder_engine.h"
#include "uiwidgets_system.h"
// #include "unity_external_texture_gl.h"
#include "third_party/Unity/IUnityGraphics.h"
namespace uiwidgets {

UIWidgetsPanel_onMouseLeave(UIWidgetsPanel* panel) { panel->OnMouseLeave(); }
UIWIDGETS_API(void)
SetTextureFromUnity2(void* tex, int w, int h) { UnitySurfaceManager::SetTextureFromUnity(tex, w, h); }
UIWIDGETS_API(void*)
SetTextureFromUnity2(void* tex, int w, int h) { return UnitySurfaceManager::SetTextureFromUnity(tex, w, h); }
static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
{
UnitySurfaceManager::drawxxx();
}
// --------------------------------------------------------------------------
// GetRenderEventFunc, an example function we export which is used to get a rendering event callback function.
UIWIDGETS_API(UnityRenderingEvent) GetRenderEventFunc()
{
return OnRenderEvent;
}
UIWIDGETS_API(void)
draw_xxx() { UnitySurfaceManager::drawxxx(); }

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


static EGLConfig egl_config_s;
static EGLSurface surfaces;
static EGLContext egl_context_s;
static EGLContext egl_context_s_old;
void UnitySurfaceManager::SetTextureFromUnity(void *tex, int w, int h)
void *UnitySurfaceManager::SetTextureFromUnity(void *tex, int w, int h)
// egl_display_s = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// FML_CHECK(egl_display_s != EGL_NO_DISPLAY)
// << "Renderer type is invalid";
// // Initialize the display connection.
// FML_CHECK(eglInitialize(egl_display_s, nullptr, nullptr) == EGL_TRUE)
// << "Renderer type is invalid";
// bool success = false;
// std::tie(success, egl_config_s) = ChooseEGLConfiguration(egl_display_s);
// FML_CHECK(success) << "Could not choose an EGL configuration.";
// EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
// egl_context_s = eglCreateContext(egl_display_s, egl_config_s, EGL_NO_CONTEXT, attributes);
// auto state = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_config_s) == GL_TRUE;
// int texture;
// glGenTextures()
// state = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == GL_TRUE;
return nullptr;
static void createContext()
{
if (egl_display_s != nullptr)
{
return;
}
egl_display_s = eglGetDisplay(EGL_DEFAULT_DISPLAY);
FML_CHECK(egl_display_s != EGL_NO_DISPLAY)
<< "Renderer type is invalid";
// Initialize the display connection.
FML_CHECK(eglInitialize(egl_display_s, nullptr, nullptr) == EGL_TRUE)
<< "Renderer type is invalid";
bool success = false;
std::tie(success, egl_config_s) = ChooseEGLConfiguration(egl_display_s);
FML_CHECK(success) << "Could not choose an EGL configuration.";
EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
egl_context_s_old = eglGetCurrentContext(); //????? for get context
egl_context_s = eglCreateContext(egl_display_s, egl_config_s, egl_context_s_old, attributes);
auto read = eglGetCurrentSurface(EGL_READ);
auto draw = eglGetCurrentSurface(EGL_DRAW);
auto state = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_s) == GL_TRUE;
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
int rowPitch = wi * 4;
unsigned char *data = new unsigned char[rowPitch * he];
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, wi, he, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
state = glGetError();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
state = glGetError();
state = eglMakeCurrent(egl_display_s, draw, read, egl_context_s_old) == GL_TRUE;
}
{
{
createContext();
int width = wi;
int height = he;

// Write the texture pixel
ptr[0] = vv;
ptr[1] = (x+y)%244;
ptr[2] = (x*y)%244;
ptr[1] = (x + y) % 244;
ptr[2] = (x * y) % 244;
ptr[3] = vv;
// To next pixel (our pixels are 4 bpp)

dst += rowPitch;
}
GLuint gltex = (GLuint)(size_t)(g_TextureHandle);
// auto read = eglGetCurrentSurface(EGL_READ);
// auto draw = eglGetCurrentSurface(EGL_DRAW);
auto state = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_s) == GL_TRUE;
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
state = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_s_old) == GL_TRUE;
delete[](unsigned char *) data;
}

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


{
public:
static UnitySurfaceManager instance;
static void SetTextureFromUnity(void* tex, int w, int h);
static void* SetTextureFromUnity(void* tex, int w, int h);
static void drawxxx();
UnitySurfaceManager(IUnityInterfaces *unity_interfaces);

正在加载...
取消
保存