浏览代码

disable multithreaded rendering

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
ed333b83
共有 4 个文件被更改,包括 50 次插入177 次删除
  1. 49
      Samples/UIWidgetsSamples_2019_4/Assets/ANT.cs
  2. 2
      Samples/UIWidgetsSamples_2019_4/Assets/ANT.unity
  3. 2
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  4. 174
      engine/src/shell/platform/unity/android/unity_surface_manager.cc

49
Samples/UIWidgetsSamples_2019_4/Assets/ANT.cs


public class ANT : MonoBehaviour
{
[DllImport(NativeBindings.dllName)]
private static extern void SetTextureFromUnity(System.IntPtr texture, int w, int h);
#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR
[DllImport ("__Internal")]
#else
[DllImport ("libUIWidgets_d")]
#endif
private static extern void SetTextureFromUnity2(System.IntPtr texture, int w, int h);
[DllImport(NativeBindings.dllName)]
#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR
[DllImport ("__Internal")]
#else
[DllImport ("libUIWidgets_d")]
#endif
void Start()
IEnumerator Start()
yield return StartCoroutine("CallPluginAtEndOfFrames");
// Create a texture
Texture2D tex = new Texture2D(20, 20, TextureFormat.ARGB32, false);
Texture2D tex = new Texture2D(256,256,TextureFormat.ARGB32,false);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
tex.SetPixel(i, j, Color.magenta);
}
}
tex.Apply();
// Set texture onto our material
GetComponent<Renderer>().material.mainTexture = tex;

SetTextureFromUnity (tex.GetNativeTexturePtr(), tex.width, tex.height);
SetTextureFromUnity2 (tex.GetNativeTexturePtr(), tex.width, tex.height);
// Update is called once per frame
void Update()
private IEnumerator CallPluginAtEndOfFrames()
while (true)
{
// Wait until all frame rendering is done
yield return new WaitForEndOfFrame();
var tex = (Texture2D)GetComponent<Renderer>().material.mainTexture;
Debug.Log("update");
draw_xxx();
Debug.Log("22");
tex.Apply();
Debug.Log("apply");
draw_xxx();
}
}
}

2
Samples/UIWidgetsSamples_2019_4/Assets/ANT.unity


m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 1c3f3f83b433c4572af5252129faaa72, type: 2}
- {fileID: 10302, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

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


UIWIDGETS_API(void)
SetTextureFromUnity(void* tex, int w, int h) { UnitySurfaceManager::SetTextureFromUnity(tex, w, h); }
SetTextureFromUnity2(void* tex, int w, int h) { UnitySurfaceManager::SetTextureFromUnity(tex, w, h); }
UIWIDGETS_API(void)

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


g_TextureHandle = tex;
wi = w;
he = h;
// egl_display_s = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// FML_CHECK(egl_display_s != EGL_NO_DISPLAY)
// << "Renderer type is invalid";
// state = glGetError();
// // Initialize the display connection.
// FML_CHECK(eglInitialize(egl_display_s, nullptr, nullptr) == EGL_TRUE)
// << "Renderer type is invalid";
// state = glGetError();
// bool success = false;
// std::tie(success, egl_config_s) = ChooseEGLConfiguration(egl_display_s);
// FML_CHECK(success) << "Could not choose an EGL configuration.";
// // state = glGetError();
// EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
// egl_context_s = eglCreateContext(egl_display_s, egl_config_s, EGL_NO_CONTEXT, attributes);
// // state = glGetError();
// int k = 0;
{
GLuint gltex = (GLuint)(size_t)(g_TextureHandle);
glBindTexture(GL_TEXTURE_2D, gltex);
state = glGetError();
auto check = state == GL_INVALID_FRAMEBUFFER_OPERATION;
{
int width = wi;
int height = he;
int rowPitch = wi * 4;
unsigned char *data = new unsigned char[rowPitch * he];
int rowPitch = width * 4;
void *data = new unsigned char[rowPitch * height];
// // glGetTexImage(gltex, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
unsigned char *dst = (unsigned char *)data;
unsigned char *dst = (unsigned char *)data;
for (int y = 0; y < he; ++y)
for (int y = 0; y < height; ++y)
{
unsigned char *ptr = dst;
for (int x = 0; x < width; ++x)
unsigned char *ptr = dst;
for (int x = 0; x < wi; ++x)
{
// Simple "plasma effect": several combined sine waves
int vv = 244;
// Write the texture pixel
ptr[0] = vv;
ptr[1] = vv;
ptr[2] = vv;
ptr[3] = vv;
// Simple "plasma effect": several combined sine waves
int vv = 244;
// To next pixel (our pixels are 4 bpp)
ptr += 4;
}
// Write the texture pixel
ptr[0] = vv;
ptr[1] = (x+y)%244;
ptr[2] = (x*y)%244;
ptr[3] = vv;
// To next image row
dst += rowPitch;
// To next pixel (our pixels are 4 bpp)
ptr += 4;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, wi, he, GL_RGBA, GL_UNSIGNED_BYTE, data);
state = eglGetError();
delete[](unsigned char *) data;
// auto ss = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE,
// egl_context_s) == GL_TRUE;
// state = glGetError();
// if (!inited)
// {
// unsigned int fbo = 0;
// glGenFramebuffers(1, &fbo);
// state = glGetError();
// glBindFramebuffer(GL_FRAMEBUFFER, fbo);
// state = glGetError();
// GLuint gltex = (GLuint)(size_t)(g_TextureHandle);
// // glBindTexture(GL_TEXTURE_2D, gltex);
// // state = glGetError();
// unsigned int texture;
// glGenTextures(1, &texture);
// glBindTexture(GL_TEXTURE_2D, texture);
// int rowPitch = 20 * 4;
// unsigned char *data = new unsigned char[rowPitch * 20];
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 20, 20, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
// state = glGetError();
// To next image row
dst += rowPitch;
}
GLuint gltex = (GLuint)(size_t)(g_TextureHandle);
glBindTexture(GL_TEXTURE_2D, gltex);
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
// state = glGetError();
// // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// if (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
// {
// int i = 0;
// }
// else
// {
// int j = 0;
// }
// inited = true;
// }
// else
// {
// state = glGetError();
// auto xxxxx = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// if (xxxxx == GL_FRAMEBUFFER_COMPLETE)
// {
// int i = 0;
// }
// else
// {
// int j = 0;
// }
// GLuint gltex = (GLuint)(size_t)(g_TextureHandle);
// glBindTexture(GL_TEXTURE_2D, gltex);
// state = glGetError();
// auto check = state == GL_INVALID_FRAMEBUFFER_OPERATION;
// int rowPitch = wi * 4;
// unsigned char *data = new unsigned char[rowPitch * he];
// // // glGetTexImage(gltex, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
// unsigned char *dst = (unsigned char *)data;
// for (int y = 0; y < he; ++y)
// {
// unsigned char *ptr = dst;
// for (int x = 0; x < wi; ++x)
// {
// // Simple "plasma effect": several combined sine waves
// int vv = 255;
// // Write the texture pixel
// ptr[0] = vv;
// // ptr[1] = vv;
// // ptr[2] = vv;
// ptr[3] = vv;
// // To next pixel (our pixels are 4 bpp)
// ptr += 4;
// }
// // To next image row
// dst += rowPitch;
// }
// glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, wi, he, GL_RGBA, GL_UNSIGNED_BYTE, data);
// state = eglGetError();
// delete[](unsigned char *) data;
// // glClearColor(1, 0, 0, 1.0);
// // glClear(GL_COLOR_BUFFER_BIT);
// state = eglGetError();
// }
// ss = eglMakeCurrent(egl_display_s, EGL_NO_SURFACE, EGL_NO_SURFACE,
// EGL_NO_CONTEXT) == GL_TRUE;
// state = glGetError();
// int kk = 0;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
delete[](unsigned char *) data;
}
} // namespace uiwidgets
正在加载...
取消
保存