我有一個關於我正在寫的小型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);
}
}
「它不工作」Segfault?內核恐慌?刪除你的主目錄? – genpfault
對不起,我確實沒有真正添加「不工作」的正確描述,我已經更新了這個問題。基本上我希望紋理更新它在OpenGL 2.1上的數據,但不是在4.1上運行時(它只顯示灰色紋理) –