Skip to content

Conversation

@Elideb
Copy link
Contributor

@Elideb Elideb commented Apr 11, 2012

This fixes issue #27.

Testing code for different cases:

using UnityEngine;
using System.Collections;

public class PixelTests : MonoBehaviour
{
    private int frame = 0;
    private Texture2D texture;
    private Color[] pixels;

    void Start()
    {
        texture = (Texture2D)Instantiate(this.renderer.material.mainTexture);
        this.renderer.material.mainTexture = this.texture;

        pixels = texture.GetPixels(0, 0, texture.width, texture.height, 0);

        // Test SetPixel
        ////for (int i = 0; i < texture.width / 2; i++)
        ////{
        ////    for (int j = 0; j < texture.height / 2; j++)
        ////    {
        ////        texture.SetPixel(i + texture.width / 2, j + texture.height / 2, pixels[i + texture.width * j]);
        ////    }
        ////}

        ////texture.Apply(false, false);
    }

    // Update is called once per frame
    void Update ()
    {
        // GetPixel / SetPixel test
        // Shift the lower half of the cube once per frame
        ////for (int i = 0; i < texture.width; i++)
        ////{
        ////    for (int j = 0; j < texture.height / 2; j++)
        ////    {
        ////        texture.SetPixel(i + frame, j, pixels[i + texture.width * j]);
        ////    }
        ////}

        // Test SetPixels
        ////texture.SetPixels(0, texture.height / 2, texture.width, texture.height / 2, pixels);

        // Test SetPixel and GetPixel at runtime
        for (int i = texture.width - 1; i >= 0; i--)
        {
            for (int j = texture.height - 1; j >= 0; j--)
            {
                texture.SetPixel(i + 1, j + 1, texture.GetPixel(i, j));
            }
        }

        frame++;

        texture.Apply(false);
    }
}

Elideb added 6 commits April 4, 2012 18:47
… of Texture.SetPixels and Texture.GetPixels and Texture.Apply(bool).

Added helper methods Texture.GetMipmapSize(miplevel), Texture.GetMipmapWidth(miplevel) and Texture.GetMipmapHeight(miplevel).
… into account to prevent crashing on indexes above or below texture dimensions.
…an index in-texture pixels beyond (0, 0) is using GetData/SetData with Rectangle.
Conflicts:
	Framework/PressPlay.FFWD/Texture.cs
Unstable:
	Framework/PressPlay.FFWD/Texture.cs and Framework/PressPlay.FFWD/Texture2D.cs have duplicated code.
…ble. Also, changed Xna.Framework.Color[] operations to byte[].
@Elideb
Copy link
Contributor Author

Elideb commented Apr 12, 2012

I have synced my fork to the latest version of FFWD and fixed the conflicts in Texture.
Moved all GetPixel/SetPixel operations to Texture2D and switched to the byte[] approach.

One more test to verify things work. To fully check it, set "Generate Mipmaps" to True in the XNA texture's properties.

public void Start()
{
    texture = (Texture2D)Instantiate(this.renderer.material.mainTexture);
    this.renderer.material.mainTexture = this.texture;

    // duplicate the original texture and assign to the material
    // colors used to tint the first 3 mip levels
    var colors = new Color[3];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    var mipCount = Mathf.Min(3, texture.mipmapCount);

    // tint each mip level
    for (var mip = 0; mip < mipCount; ++mip)
    {
        var cols = texture.GetPixels(mip);
        for (var i = 0; i < cols.Length; ++i)
        {
            cols[i] = Color.Lerp(cols[i], colors[mip], 0.33f);
        }
        texture.SetPixels(cols, mip);
    }

    texture.Apply(false, false);
}

@maconbot
Copy link

I am getting a "the 'optional parameter' cannot be used it is not part of the 3.0 c# language specification" error. On Texture2D.cs

Total of 7 places...lines 67, 82, 127, 147, 166, 177 and 188.

Anytime something like:
public void SetPixels(Color[] colors, int miplevel = 0)
...occurs

Apparently xbox and windows phone only use .NET 3.0, I am trying the suggestion linked below...just deleting the "= 0"
http://forums.create.msdn.com/forums/p/89928/556025.aspx

This occurs when debugging the FFWD.Unity.Tests XNA project.

@maconbot
Copy link

i'll add this note to Elideb's fork...not sure if I was testing what you guys wanted tested...however I did notice the "optional parameter" still in the Texture2D.cs so it is worth noting. Just going through and deleting the "=0" made the error go away, not sure if it still functions as desired however. Materials and textures still seem to make it onto their meshes :-)

…th explicit no mipmap methods calling to mipmap capable ones.
@Elideb
Copy link
Contributor Author

Elideb commented Apr 19, 2012

I've learnt the lesson and created WP7 and X360 versions of my test project. I've tested the last commit and it works on WP7.

However, calling GetPixel and SetPixel each frame for each pixel in a 64x64 texture takes 6 seconds per frame in the WP7 emulator. Only calling SetPixels each frame does much better (16 ticks), which is to be expected.

@maconbot
Copy link

Awesome, I will test soon...hopefully whilst working on integrating Terrain, any thoughts here:
maconbot#1

@maconbot
Copy link

After clearing out the UnityTests project and known errors...I compiled your XNA, the errors that were there are gone, now there is a bunch of warnings 14 or so.

And 3 errors:
Error 1 Error loading pipeline assembly "C:\Users\Chad\Desktop\Elideb-FFWD-703b77d\Elideb-FFWD-703b77d\Tests\FFWD.Unity.Tests\FFWD.Unity.Tests.Scripts\bin\x86\Debug\FluentAssertions.dll". FFWD.Unity.Tests.Win
Error 9 Error loading pipeline assembly "C:\Users\Chad\Desktop\Elideb-FFWD-703b77d\Elideb-FFWD-703b77d\Tests\FFWD.Unity.Tests\FFWD.Unity.Tests.Scripts\bin\x86\Debug\FluentAssertions.dll". FFWD.Unity.Tests.WP7
Error 17 Error loading pipeline assembly "C:\Users\Chad\Desktop\Elideb-FFWD-703b77d\Elideb-FFWD-703b77d\Tests\FFWD.Unity.Tests\FFWD.Unity.Tests.Scripts\bin\x86\Debug\FluentAssertions.dll". FFWD.Unity.Tests.X360

Warnings:
Are just related to my machine so ignoring those.

@Elideb
Copy link
Contributor Author

Elideb commented Apr 25, 2012

@maconbot I've integrated Fehaar's latest changes, which fix the compilation and dependencies of the tests.
I've tested them on a fresh copy of my repo and everything seems to be fine. Please, can you check things are OK in your machine too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants