Пример #1
0
    private IEnumerator LoadImageFromURLIntoImageSphereInternal(ImageSphereController imageSphereController, int sphereIndex, int postImageIndex, string url, string imageIdentifier, bool showLoading)
    {
        if (postImageIndex != Helper.kIgnoreImageIndex && !m_posts.IsValidRequest(postImageIndex))
        {
            yield break;
        }

        yield return(m_appDirector.VerifyInternetConnection());

        m_isLoading = true;
        if (showLoading)
        {
            m_loadingIcon.Display();
        }

        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL: Downloading image and getting stream through GetImageStreamFromURL() with url: " + url);
        }
        yield return(m_threadJob.WaitFor());

        bool   debugOn       = Debug.isDebugBuild;
        Stream imageStream   = null;
        int    contentLength = 0;

        m_threadJob.Start(() =>
                          contentLength = GetImageStreamFromURL(url, ref imageStream, debugOn)
                          );
        yield return(m_threadJob.WaitFor());

        if (contentLength > 0)
        {
            int textureIndex = GetAvailableTextureIndex();
            yield return(m_cppPlugin.LoadImageFromStreamIntoImageSphere(imageSphereController, sphereIndex, imageStream, imageIdentifier, textureIndex, contentLength));

            imageStream.Close();
        }
        else
        {
            imageSphereController.SetImageAtIndexToLoading(sphereIndex, true);
        }

        m_isLoading = false;
        if (showLoading)
        {
            m_loadingIcon.Hide();
        }
    }
Пример #2
0
    // **************************
    // Private/Helper functions
    // **************************

    private IEnumerator LoadImageFromPathIntoImageSphereInternal(ImageSphereController imageSphereController, int sphereIndex, int galleryImageIndex, string filePathAndIdentifier, bool showLoading, int maxImageWidth)
    {
        if (galleryImageIndex != Helper.kIgnoreImageIndex && !m_gallery.IsValidRequest(galleryImageIndex))
        {
            yield break;
        }

        m_isLoading = true;
        if (showLoading)
        {
            m_loadingIcon.Display();
        }

        int textureIndex = GetAvailableTextureIndex();

        yield return(m_cppPlugin.LoadImageFromPathIntoImageSphere(imageSphereController, sphereIndex, filePathAndIdentifier, textureIndex, maxImageWidth));

        m_isLoading = false;
        if (showLoading)
        {
            m_loadingIcon.Hide();
        }
    }
Пример #3
0
    //WIP
    public IEnumerator TestLoad(ImageSphereController imageSphereController, int sphereIndex, string url, string imageIdentifier, int textureIndex)
    {
        var startTime = DateTime.UtcNow;

        WWW www = new WWW(url);

        yield return(www);


        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL-TEST: TestLoad() 1 " + (DateTime.UtcNow - startTime));
        }
        yield return(new WaitForSeconds(2));

        startTime = DateTime.UtcNow;


        byte[] newBytes = new byte[4096 * 2048 * 3];

        for (int i = 0; i < (4096 * 2048); i++)
        {
            newBytes[i * 3 + 0] = 0;
            newBytes[i * 3 + 1] = 255;
            newBytes[i * 3 + 2] = 0;
        }

        //DO STUFF

        /*
         * GCHandle rawDataHandle = GCHandle.Alloc(myBinary, GCHandleType.Pinned);
         * IntPtr rawDataPtr = rawDataHandle.AddrOfPinnedObject();
         * yield return m_threadJob.WaitFor();
         * ranJobSuccessfully = false;
         * m_threadJob.Start( () =>
         *  ranJobSuccessfully = LoadIntoWorkingMemoryFromImageData(rawDataPtr, myBinary.Length)
         * );
         * yield return m_threadJob.WaitFor();
         * rawDataHandle.Free();
         */


        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL-TEST: TestLoad() 2 " + (DateTime.UtcNow - startTime));
        }
        yield return(new WaitForSeconds(2));

        startTime = DateTime.UtcNow;


        m_lastTextureOperatedOn = new Texture2D(4096, 2048, TextureFormat.RGB24, false);
        m_lastTextureOperatedOn.LoadRawTextureData(newBytes);


        //www.LoadImageIntoTexture(m_lastTextureOperatedOn);


        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL-TEST: TestLoad() 3 " + (DateTime.UtcNow - startTime));
        }
        yield return(new WaitForSeconds(2));

        startTime = DateTime.UtcNow;


        m_lastTextureOperatedOn.Apply();



        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL-TEST: TestLoad() 4 " + (DateTime.UtcNow - startTime));
        }
        yield return(new WaitForSeconds(2));

        startTime = DateTime.UtcNow;


        imageSphereController.SetImageAtIndex(sphereIndex, m_lastTextureOperatedOn, imageIdentifier, textureIndex, true);



        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL-TEST: TestLoad() 5 " + (DateTime.UtcNow - startTime));
        }
    }
Пример #4
0
    public IEnumerator LoadImageFromStreamIntoImageSphere(ImageSphereController imageSphereController, int sphereIndex, Stream imageStream, string imageIdentifier, int textureIndex, int contentLength)
    {
        yield return(null);

        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL: Calling LoadImageFromStreamIntoImageSphere() with sphereIndex: " + sphereIndex + ", imageIdentifier: " + imageIdentifier + ", with TextureIndex: " + textureIndex);
        }

        SetRGB565On(Helper.kRGB565On);
        SetMaxImageWidth(Helper.kMaxImageWidth);


        var startTime = DateTime.UtcNow;


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling ToByteArray(), on background thread!");
        yield return(m_threadJob.WaitFor());

        bool ranJobSuccessfully = false;

        byte[] myBinary = null;
        m_threadJob.Start(() =>
                          ranJobSuccessfully = ToByteArray(imageStream, contentLength, ref myBinary)
                          );
        yield return(m_threadJob.WaitFor());

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished ToByteArray(), ran Job Successully = " + ranJobSuccessfully);


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL-TEST: 1 " + (DateTime.UtcNow-startTime));
        startTime = DateTime.UtcNow;

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling LoadIntoWorkingMemoryFromImagePath(), on background thread!");
        GCHandle rawDataHandle = GCHandle.Alloc(myBinary, GCHandleType.Pinned);
        IntPtr   rawDataPtr    = rawDataHandle.AddrOfPinnedObject();

        yield return(m_threadJob.WaitFor());

        ranJobSuccessfully = false;
        m_threadJob.Start(() =>
                          ranJobSuccessfully = LoadIntoWorkingMemoryFromImageData(rawDataPtr, myBinary.Length)
                          );
        yield return(m_threadJob.WaitFor());

        rawDataHandle.Free();
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished LoadIntoWorkingMemoryFromImagePath(), ran Job Successully = " + ranJobSuccessfully);


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL-TEST: 2 " + (DateTime.UtcNow-startTime));
        startTime = DateTime.UtcNow;


        //TODO: Make CreateEmptyTexture() more efficient - the problem is simply that a glTexImage2D() call is slow with large textures!
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling CreateEmptyTexture()");
        yield return(m_waitForEndOfFrame);

        SetCurrTextureIndex(textureIndex);
        GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderFunctions.kRenewTextureHandle);
        yield return(m_waitForSeconds); // These waits need to be longer to ensure that GL.IssuePluginEvent() has gone through!

        yield return(null);

        GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderFunctions.kCreateEmptyTexture);
        yield return(m_waitForSeconds); // These waits need to be longer to ensure that GL.IssuePluginEvent() has gone through!

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished CreateEmptyTexture(), Texture Handle = " + GetCurrStoredTexturePtr() );


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL-TEST: 3 " + (DateTime.UtcNow-startTime));
        startTime = DateTime.UtcNow;

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling LoadScanlinesIntoTextureFromWorkingMemory()");
        while (IsLoadingIntoTexture())
        {
            yield return(m_waitForEndOfFrame);

            GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderFunctions.kLoadScanlinesIntoTextureFromWorkingMemory);
            yield return(m_waitForSeconds); // These waits need to be longer to ensure that GL.IssuePluginEvent() has gone through!
        }
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished LoadScanlinesIntoTextureFromWorkingMemory()");


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL-TEST: 4 " + (DateTime.UtcNow-startTime));
        startTime = DateTime.UtcNow;

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling CreateExternalTexture(), size of Texture is Width x Height = " + GetCurrStoredImageWidth() + " x " + GetCurrStoredImageHeight());
        yield return(m_waitForEndOfFrame);

        m_lastTextureOperatedOn =
            Texture2D.CreateExternalTexture(
                GetCurrStoredImageWidth(),
                GetCurrStoredImageHeight(),
                Helper.kRGB565On ? TextureFormat.RGB565 : TextureFormat.RGB24, // Default textures have a format of ARGB32
                true,
                true,
                GetCurrStoredTexturePtr()
                );
        yield return(null);

        m_lastTextureOperatedOn.filterMode = FilterMode.Trilinear;
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished CreateExternalTexture()!");

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL-TEST: 5 " + (DateTime.UtcNow-startTime));
        startTime = DateTime.UtcNow;

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling SetImageAtIndex()");
        imageSphereController.SetImageAtIndex(sphereIndex, m_lastTextureOperatedOn, imageIdentifier, textureIndex, true);
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished SetImageAtIndex()");

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL-TEST: 6 " + (DateTime.UtcNow-startTime));
        startTime = DateTime.UtcNow;

        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL: Completed LoadImageFromStreamIntoImageSphere() with sphereIndex: " + sphereIndex + ", imageIdentifier: " + imageIdentifier + ", with TextureIndex: " + textureIndex);
        }
    }
Пример #5
0
    public IEnumerator LoadImageFromPathIntoImageSphere(ImageSphereController imageSphereController, int sphereIndex, string filePathAndIdentifier, int textureIndex, int maxImageWidth)
    {
        StringBuilder filePathForCpp = new StringBuilder(filePathAndIdentifier);

        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL: Calling LoadImageFromPathIntoImageSphere() with sphereIndex : " + sphereIndex + ", from filePath: " + filePathAndIdentifier + ", with TextureIndex: " + textureIndex + ", with MaxImageWidth: " + maxImageWidth);
        }
        yield return(null);

        SetRGB565On(Helper.kRGB565On);
        SetMaxImageWidth(maxImageWidth);
        SetUseExif(false); //SetUseExif(maxImageWidth == Helper.kThumbnailWidth);

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling LoadIntoWorkingMemoryFromImagePath(), on background thread!");
        yield return(m_threadJob.WaitFor());

        bool ranJobSuccessfully = false;

        m_threadJob.Start(() =>
                          ranJobSuccessfully = LoadIntoWorkingMemoryFromImagePath(filePathForCpp)
                          );
        yield return(m_threadJob.WaitFor());

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished LoadIntoWorkingMemoryFromImagePath(), ran Job Successully = " + ranJobSuccessfully);


        //TODO: Make CreateEmptyTexture() more efficient - the problem is simply that a glTexImage2D() call is slow with large textures!
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling CreateEmptyTexture() over textureIndex = " + textureIndex);
        yield return(m_waitForEndOfFrame);

        SetCurrTextureIndex(textureIndex);
        GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderFunctions.kRenewTextureHandle);
        yield return(m_waitForSeconds); // These waits need to be longer to ensure that GL.IssuePluginEvent() has gone through!

        yield return(null);

        GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderFunctions.kCreateEmptyTexture);
        yield return(m_waitForSeconds); // These waits need to be longer to ensure that GL.IssuePluginEvent() has gone through!

        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished CreateEmptyTexture(), Texture Handle = " + GetCurrStoredTexturePtr() );


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling LoadScanlinesIntoTextureFromWorkingMemory()");
        while (IsLoadingIntoTexture())
        {
            yield return(m_waitForEndOfFrame);

            GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderFunctions.kLoadScanlinesIntoTextureFromWorkingMemory);
            yield return(m_waitForSeconds);
        }
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished LoadScanlinesIntoTextureFromWorkingMemory()");


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling CreateExternalTexture(), size of Texture is Width x Height = " + GetCurrStoredImageWidth() + " x " + GetCurrStoredImageHeight());
        yield return(m_waitForEndOfFrame);

        m_lastTextureOperatedOn =
            Texture2D.CreateExternalTexture(
                GetCurrStoredImageWidth(),
                GetCurrStoredImageHeight(),
                Helper.kRGB565On ? TextureFormat.RGB565 : TextureFormat.RGB24, // Default textures have a format of ARGB32
                true,
                true,
                GetCurrStoredTexturePtr()
                );
        yield return(null);

        m_lastTextureOperatedOn.filterMode = FilterMode.Trilinear;
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished CreateExternalTexture()!");


        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Calling SetImageAtIndex()");
        imageSphereController.SetImageAtIndex(sphereIndex, m_lastTextureOperatedOn, filePathAndIdentifier, textureIndex, true);
        //if (Debug.isDebugBuild) Debug.Log("------- VREEL: Finished SetImageAtIndex()");

        if (Debug.isDebugBuild)
        {
            Debug.Log("------- VREEL: Completed LoadImageFromPathIntoImageSphere() with sphereIndex : " + sphereIndex + ", from filePath: " + filePathAndIdentifier + ", with TextureIndex: " + textureIndex);
        }
    }
Пример #6
0
 public void LoadImageFromURLIntoImageSphere(ImageSphereController imageSphereController, int sphereIndex, int postImageIndex, string url, string filePathAndIdentifier, bool showLoading)
 {
     m_coroutineQueue.EnqueueAction(LoadImageFromURLIntoImageSphereInternal(imageSphereController, sphereIndex, postImageIndex, url, filePathAndIdentifier, showLoading));
 }
Пример #7
0
 public void LoadImageFromPathIntoImageSphere(ImageSphereController imageSphereController, int sphereIndex, int galleryImageIndex, string filePathAndIdentifier, bool showLoading, int maxImageWidth)
 {
     m_coroutineQueue.EnqueueAction(LoadImageFromPathIntoImageSphereInternal(imageSphereController, sphereIndex, galleryImageIndex, filePathAndIdentifier, showLoading, maxImageWidth));
 }