试图设置从Java插件纹理在Unity 4.6 [英] Trying to set a texture from Java plugin in Unity 4.6

查看:237
本文介绍了试图设置从Java插件纹理在Unity 4.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的:


  • 在使用Java插件的手机从拉SD卡的图像。

  • 统一通过一个纹理的ID插件。

  • 插件使用OpenGL的图像分配到通过ID在Unity质感。

  • 将(最终)被用于从统一手机播放视频片段,现在,它只是试图改变团结之外的质感。

我的问题:

当我调用该方法的插件,通过 texture.GetNativeTextureID()进去,质地不会改变。我目前只使用一个简单的黑色50×50的纹理进行测试,和原来的质地是一个平面白

我很担心,我已经错过了什么显著,因为这是我第一次与GL在Java调用工作。大部分的回答类似问题的涉及使用本机C ++而不是Java,但我无法找到一个具体的答案说,C ++的必须使用。我希望尽我所能来避免写另一组插件和插件的处理程序C ++的,但如果它是最有效的/只有这样,才能得到这个工作,我会做到这一点。我不熟悉的OpenGL和C ++

code:

插件方法是从呼吁preRender()附于主摄像头的脚本:

 如果(grabTex){
    INT texPtr = m_VideoTex.GetNativeTextureID();
    的debug.log(texPtr =+ texPtr);
    m_JVInterface.SetTex(texPtr);
}

m_VideoTex 是一个基本的的Texture2D(50,50)设置为白色所有像素,贴在漫着色器在现场四。

Java插件code是如下:

 公共无效SetTexture(上下文续,诠释_texPointer){
    如果(_texPointer!= 0){
        最后BitmapFactory.Options选项=新BitmapFactory.Options();
        options.inScaled = FALSE;
        options.inJustDe codeBounds = FALSE;
        最后的位图位图= BitmapFactory.de codeFILE(/存储/模拟/ 0 /图片/ black.jpg选项);        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,_texPointer);        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,0,位图,0);        Log.i(VideoHandler,收到序号:+ _texPointer);        bitmap.recycle();
    }
}


解决方案

这是最有可能是与OpenGL上下文问题。最简单的方法是发送纹理原始字节到Unity,然后上传AS内部团结的质感。

What i'm trying to do:

  • Pull an image from sd-card on phone using Java Plugin.
  • Unity passes a texture ID to plugin.
  • Plugin uses opengl to assign the image to the texture in Unity through the ID.
  • Will (eventually) be used to play a video clip from the phone in Unity, for now, it's just trying to change a texture outside of unity.

My issue:

When i call the method in the plugin, passing texture.GetNativeTextureID() into it, the texture does not change. I'm currently only using a simple black 50x50 texture for testing, and the original texture is a flat white.

I'm worried that i've missed something significant, as this is my first time working with Gl calls in java. Much of the answers to similar problems involve using native C++ instead of Java, but I can't find a concrete answer saying that C++ must be used. I'd like to do my best to avoid writing another set of plugins and plugin handlers for C++, but if it's the most efficient/only way to get this working, i'll do it as i'm not unfamiliar with OpenGL and C++

Code:

The plugin method is called from OnPreRender() in a script attached to the main camera:

if (grabTex) {
    int texPtr = m_VideoTex.GetNativeTextureID();
    Debug.Log( "texPtr = " + texPtr );
    m_JVInterface.SetTex( texPtr );
}

m_VideoTex is a basic Texture2D( 50, 50 ) with all pixels set to white, attached to the diffuse shader on the quad in the scene.

The Java plugin code is as follows:

public void SetTexture(Context cont, int _texPointer) {
    if (_texPointer != 0) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;
        options.inJustDecodeBounds = false;
        final Bitmap bitmap = BitmapFactory.decodeFile("/storage/emulated/0/Pictures/black.jpg", options);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, _texPointer);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        Log.i("VideoHandler", "Recieved ID: " + _texPointer);

        bitmap.recycle();
    }
}

解决方案

This is most likely a problem with the OpenGL Context. The easiest way would be to send the texture as raw bytes to Unity and then upload as texture inside Unity.

这篇关于试图设置从Java插件纹理在Unity 4.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆