Beispiel #1
0
    bool SetupOutputTextures()
    {
        int   texWidth      = 1920; // HD=1920, SD=720
        int   texHeight     = 1080; // HD=1080, SD=486
        float lAspect       = 0;
        bool  lIsInterlaced = false;

        UtyGLNvSdi.GetSizeFromVideoFormat(options.videoFormat, ref texWidth, ref texHeight, ref lAspect, ref lIsInterlaced);

        // Check the count of cameras. The plugin support until two cameras
        if (outputTexture.Length > 4)
        {
            UnityEngine.Debug.LogWarning("GLNvSdi plugin does not support more than four cameras.");
        }

        // Verify the amount of render textures needed
        int lTexCount = 0;

        if (options.outputDual)
        {
            lTexCount = 2;
        }
        else
        {
            lTexCount = 1;
        }

        if (lIsInterlaced)
        {
            lTexCount *= 2;
        }


        // If dual progressive output, change the order of cameras. So, the first two are active
        if (options.outputDual && !lIsInterlaced)     // dual output progressive
        {
            RenderTexture tmp = outputTexture[1];
            outputTexture[1] = outputTexture[2];
            outputTexture[2] = tmp;
        }


        // Setting the cameras and directing the render to texture
        for (int i = 0; i < lTexCount; ++i)
        {
            if (outputTexture[i] != null)
            {
                //
                // Checking texture sizes
                //
                if (texWidth != outputTexture[i].width || texHeight != outputTexture[i].height)
                {
                    UnityEngine.Debug.LogError("The size of RenderTexture does not match with sdi video options");
                    return(false);
                }

                //
                // Check if the texture has been created
                //
                if (!outputTexture[i].IsCreated())
                {
                    if (!outputTexture[i].Create())
                    {
                        UnityEngine.Debug.LogError("Could not create Output Sdi RenderTexture");
                    }
                }

                //
                // Sending texture id to plugin
                //
                UtyGLNvSdi.SdiOutputSetTexturePtr(i, outputTexture[i].GetNativeTexturePtr(), outputTexture[i].width, outputTexture[i].height);
            }
            else
            {
                UnityEngine.Debug.LogError("Sdi Output RenderTexture is null");
                return(false);
            }
        }

        // If the options to invert fields is marked, we have to invert
        // the textures id already sent to plugin
        if (options.outputInvertFields)
        {
            UtyGLNvSdi.SdiOutputInvertFields(options.outputInvertFields);
        }

        return(true);
    }
Beispiel #2
0
    bool SetupOutputTextures()
    {
        float lAspect       = 0;
        bool  lIsInterlaced = false;

        UtyGLNvSdi.GetSizeFromVideoFormat(options.videoFormat, ref m_TexWidth, ref m_TexHeight, ref lAspect, ref lIsInterlaced);

        // Check the count of cameras. The plugin support until two cameras
        if (m_Camera.Length > 4)
        {
            UnityEngine.Debug.LogWarning("GLNvSdi plugin does not support more than four cameras.");
        }

        // Disable all cameras
        for (int i = 0; i < m_Camera.Length; ++i)
        {
            m_Camera[i].enabled = false;
        }

        // Verify the amount of render textures needed
        int lTexCount = 0;

        if (options.outputDual)
        {
            lTexCount = 2;
        }
        else
        {
            lTexCount = 1;
        }

        if (lIsInterlaced)
        {
            lTexCount *= 2;
        }

        // If dual progressive output, change the order of cameras. So, the first two are active
        if (options.outputDual && !lIsInterlaced)     // dual output progressive
        {
            Camera tmp = m_Camera[1];
            m_Camera[1] = m_Camera[2];
            m_Camera[2] = tmp;

            GLNvSdiRenderTexture rt1 = m_Camera[1].GetComponent <GLNvSdiRenderTexture>();
            GLNvSdiRenderTexture rt2 = m_Camera[2].GetComponent <GLNvSdiRenderTexture>();

            if (rt1 != null && rt2 != null)
            {
                int tmp_index = rt1.sdiTextureIndex;
                rt1.sdiTextureIndex = rt2.sdiTextureIndex;
                rt2.sdiTextureIndex = tmp_index;
            }
            else
            {
                UnityEngine.Debug.LogError("Error: Could not find GLNvSdiRenderTexture when switching camera parameters");
                return(false);
            }
        }


        // Setting the cameras and directing the render to texture
        for (int i = 0; i < lTexCount; ++i)
        {
            if (m_Camera[i] != null)
            {
                m_Camera[i].aspect  = lAspect;
                m_Camera[i].enabled = true;


                GLNvSdiRenderTexture sdiTex = m_Camera[i].GetComponent <GLNvSdiRenderTexture>();
                if (sdiTex != null)
                {
                    sdiTex.CreateSdiTexture(m_TexWidth, m_TexHeight, 32, false, "RenderTex_" + m_Camera[i].name);

                    if (sdiTex.sdiRenderTarget == null)
                    {
                        UnityEngine.Debug.LogError("Could not create SdiRenderTarget for GLNvSdiRenderTexture in " + m_Camera[i].name);
                        return(false);
                    }

                    UtyGLNvSdi.SdiOutputSetTexturePtr(i, sdiTex.sdiRenderTarget.GetNativeTexturePtr(), sdiTex.sdiRenderTarget.width, sdiTex.sdiRenderTarget.height);
                    //UtyGLNvSdi.SdiOutputSetTexturePtr(i, outputTexture[i].GetNativeTexturePtr(), outputTexture[i].width, outputTexture[i].height);
                }
                else
                {
                    UnityEngine.Debug.LogError("Could not find GLNvSdiRenderTexture in " + m_Camera[i].name);
                    return(false);
                }
            }
            else
            {
                UnityEngine.Debug.LogError(m_Camera[i].name + " is null");
                return(false);
            }
        }

        // If the options to invert fields is marked, we have to invert
        // the textures id already sent to plugin
        if (options.outputInvertFields)
        {
            UtyGLNvSdi.SdiOutputInvertFields(options.outputInvertFields);
        }

        return(true);
    }