Comments (4)
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.
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.
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.
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)
- Sounds over a certain length do not play properly. HOT 3
- Text Field fails to render certain Unicode characters HOT 6
- [html5] FileReferenceList doesn't dispatch Event.CANCEL HOT 1
- DropShadowFilter renders incorrectly when applied onto a TextField HOT 1
- OpenFL is compatible with old devices on WeChat IOS, which can cause`__scissorRectangle` An error occurred during off screen rendering;
- FlashPlayer does not change its size HOT 4
- [HTML5] Display looks bad when it is not a scale HOT 1
- Custom fonts don't support bold or italic variants on Windows HOT 3
- Uncaught TypeError: Cannot read properties of null (reading 'duration') - Sound.hx:761
- TextField does not handle <img> on platforms other than Flash HOT 3
- The Hashlink profiler does not work with OpenFL HOT 5
- Linking to `utest` or `munit` breaks HTML5 target HOT 1
- how do i use the core opengl core profile on macOS haxe? HOT 5
- Support for uniform structures in GLSL
- WebSocket APIs
- preserveDrawingBuffer attribute support.
- iOS Runpath issue
- Holding down keyboard keys on MacOS brings up special character menu HOT 5
- Threading with bitmap datas converted to textures silent crashes the game HOT 2
- Setting bitmap smoothing to false still results in smoothed bitmaps
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openfl.