2016-11-10 134 views
1

我有一個關於我正在寫的小型Unity插件的問題。Unity插件不能在OpenGL 4.1中工作,使用OpenGL 2.1

該插件採用Unity3D Texture2D並嘗試更新它,編譯後的插件在運行Unity3D時運行於-force-opengl(在OpenGL 2.1中運行),但在正常模式(OpenGL 4.1)下運行時不起作用。有什麼我失蹤的?

該插件應更新內部OpenGL紋理並設置其數據。該插件不會崩潰的遊戲或任何東西,但在2.1上運行時的質感做更新,只是顯示在4.1

灰色紋理團結自己的樣品他們正在使用GLEW用於初始化OpenGL上下文(https://bitbucket.org/Unity-Technologies/graphicsdemos/src/548c5251ddbe82129b2584992a0f50caa4c34c6c/NativeRenderingPlugin/PluginSource/source/RenderAPI_OpenGLCoreES.cpp?at=default&fileviewer=file-view-default) 但是插件中不應該存在OpenGL上下文嗎?有關OpenGL版本有沒有區別?

我在OSX El Capitan上運行。

下面是相關的代碼片段:

Ç插件代碼

#include <stdio.h> 
#include <inttypes.h> 

#include <OpenGL/gl.h> 
#include <OpenGL/glu.h> 

#include "unity/IUnityInterface.h" 

#include "debug.c" 

void RenderTexture (void* texId, int time) { 
    GLuint gltex = (GLuint)(size_t)(texId); 

    int id, i, j; 
    GLubyte img[64 * 64 * 4]; 

    for (i = 0; i < 64; i++) { 
     for (j = 0; j < 64; j++) { 
      id = (4 * j) + (4 * 64 * i); 
      img[id] = (GLubyte) time % 255; 
      img[id + 1] = (GLubyte) time % 255; 
      img[id + 2] = (GLubyte) (255 - time) % 255; 
      img[id + 3] = (GLubyte) (255 - time) % 255; 
     } 
    } 

    glBindTexture(GL_TEXTURE_2D, gltex); 
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 64, 64, GL_RGBA, GL_UNSIGNED_BYTE, img); 
} 

C#統一代碼

using UnityEngine; 
using System.Collections; 
using System.Runtime.InteropServices; 
using System; 
using System.IO; 

public class TestBehaviour : MonoBehaviour { 

    [DllImport("main")] 
    private static extern void RenderTexture (IntPtr ptrTexture, int time); 

    Texture2D tex; 

    void Start() { 
     tex = new Texture2D (64, 64, TextureFormat.ARGB32, false); 
     tex.Apply(); 

     GetComponent<Renderer>().material.SetTexture ("_MainTex", tex); 
    } 

    void Update() { 
     RenderTexture (tex.GetNativeTexturePtr(), (int)Time.realtimeSinceStartup * 10); 
    } 

} 
+0

「它不工作」Segfault?內核恐慌?刪除你的主目錄? – genpfault

+0

對不起,我確實沒有真正添加「不工作」的正確描述,我已經更新了這個問題。基本上我希望紋理更新它在OpenGL 2.1上的數據,但不是在4.1上運行時(它只顯示灰色紋理) –

回答

2

看着the docs,似乎使用-force-opengl使用Unity使用傳統的OpenGL。試用-force-glcore,看看你是否得到不同的結果。

0

如果你把該命令在有條件的,像

if (version <= 2.1) then  -force-opengl 

所以,它不會在新的OpenGL執行

0

我不會假裝真正的幫助,但我不能評論,所以。首先要做的事情:如何在你的C#代碼中使用ARGB格式,如何在C代碼中使用RGBA,真的很奇怪。錯誤還是我錯了?

第二件事 - 你甚至不試圖去理解實際上出了什麼問題。
使用GLenum error = glGetError();獲取OpenGL狀態機中發生的最新可能錯誤,然後檢查glTexSubimage2d documentation以查看可能的錯誤及其原因的列表。遵循這些簡單的步驟可能會幫助您瞭解您做錯了什麼,如果您沒有做錯任何事情,那麼這是Unity的問題。

事實上,這個問題有很多可能的原因,沒有glError信息只是讓你沒有希望進一步調查。