Giter Site home page Giter Site logo

Comments (4)

joshtynjala avatar joshtynjala commented on May 26, 2024

Based on the current implementation, this appears to be the expected behavior.

As far as I can tell, BitmapData.fromTexture() is intended to be a way to make it possible to render the texture in an openfl.display.Bitmap only (and only when rendering OpenFL on the GPU). I would expect that calling most of the common methods on the BitmapData class will probably fail with a similar exception because the texture is never converted from a hardware format to a software format. (It's worth mentioning that BitmapData.fromTexture() does not exist in Flash, and that's probably for good reason because converting hardware textures to software bitmaps is very expensive, performance-wise).

BitmapData.fromTexture() has the following code:

var bitmapData = new BitmapData(texture.__width, texture.__height, true, 0);
bitmapData.readable = false;
bitmapData.__texture = texture;
bitmapData.__textureContext = texture.__textureContext;
bitmapData.image = null;

Notice, in particular, that the image private variable is set to null. That's where the raw software-renderable pixel data is supposed to be stored normally. Only the hardware texture is saved, and it isn't converted for software. However, a number of important operations happen in software. For instance, when you use beginBitmapFill(), it ends up calling ImageCanvasUtil.convertToCanvas(bitmap.image);. But image is null. With normal BitmapData it wouldn't be null.

Basically, in Flash, ATF textures weren't intended for use on the classic display list. They were meant for Stage 3D. OpenFL happens to render the classic display list using Stage 3D by default, which is pretty clever, but OpenFL has not provided a way to make ATF textures work on the classic display list as completely as PNG/JPG/etc. image formats can be.

from openfl.

joshtynjala avatar joshtynjala commented on May 26, 2024

I added some details to the documentation for BitmapData.fromTexture() (including specifying that Graphics.beginBitmapFill() is one of the operations that does not work).

I also stopped the exception from being thrown when calling Graphics.beginBitmapFill() and bitmapData.readable == false. Instead, a hardware-only texture will render as plain black when passed to Graphics.beginBitmapFill(). So it won't render the texture, for the reasons specified, but it will prevent the app from crashing.

It also makes native targets more consistent with html5 because those previously failed silently without rendering anything.

from openfl.

loudoweb avatar loudoweb commented on May 26, 2024

Thanks for your answer.

It also makes native targets more consistent with html5 because those previously failed silently without rendering anything.

No. It renders actually. But crashes on mouse over. I don't know what the convertToCanvas is doing. But in case it's for delimit the bounds of the sprite, we could get/build that information when calling drawRect or drawTriangles. I don't get why it calls that from a hitTest... At least, it would be preferable to stop the exception from being thrown from there (in convertToCanvas instead of displaying a full back sprite. In that case, as an user, I could use the differ library to mimic hitTest.

As far as I can tell, BitmapData.fromTexture() is intended to be a way to make it possible to render the texture in an openfl.display.Bitmap only

No we can use it in Tilemap actually.

I came across this bug during some tests I made. Drawing 464 sprites with Tilemap on html5 takes 275ms. With my polygon library that uses drawTriangles, it takes 178ms and with ATF it takes 45ms. So I'm afraid to lose something, especially because Stage3D looks less convienent and uses Agal instead of GLSL if I'm correct. For the record, with that, I'm also beating Unity3D rendering on native.

from openfl.

joshtynjala avatar joshtynjala commented on May 26, 2024

It also makes native targets more consistent

No. It renders actually.

I didn't see anything rendering on C++/Neko/HashLink when I tested the same beginBitmapFill() code there.

No we can use it in Tilemap actually.

Fair enough. I often forget about the existence of Tilemap, since it wasn't a Flash API. Regardless, that's a similar use-case to Bitmap in terms of rendering a hardware texture with no access to software pixel data.

from openfl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.