Smaller render than usual when using Context3DGraphics

Hi,
I’m trying to retrieve the output of a render of the class Graphics.hx onto a bitmap using Context3DGraphics, and while it displays fine on the bitmap, I’ve noticed that it is smaller than the original for some reason, is there a reason why and how to fix it?

Here’s the code:

var cacheRTT = renderer.__context3D.__state.renderToTexture;
var cacheRTTDepthStencil = renderer.__context3D.__state.renderToTextureDepthStencil;
var cacheRTTAntiAlias = renderer.__context3D.__state.renderToTextureAntiAlias;
var cacheRTTSurfaceSelector = renderer.__context3D.__state.renderToTextureSurfaceSelector;
		
var bmp = new BitmapData(Math.ceil(gfx.__bounds.width), Math.ceil(gfx.__bounds.height), 0);
renderer.__context3D.setRenderToTexture(bmp.getTexture(renderer.__context3D));
var bounds = gfx.__owner.getBounds(null);

trace(bounds);
trace(gfx.__owner.__renderTransform);
renderer.__worldTransform.identity();
renderer.__worldTransform.translate(-bounds.x, -bounds.y);
Context3DGraphics.render(gfx, renderer);
// GfxRenderer.render(gfx, cast renderer.__softwareRenderer);
// var bmp = gfx.__bitmap;

// gfx.__bitmap = null;

if (cacheRTT != null)
{
	renderer.__context3D.setRenderToTexture(cacheRTT, cacheRTTDepthStencil, cacheRTTAntiAlias, cacheRTTSurfaceSelector);
}
else
{
	renderer.__context3D.setRenderToBackBuffer();
}

(this comes from a function, but it’s easy to implement by just doing var gfx = displayObject.graphics)

I’m not sure why you are accessing OpenFL’s private internals like that. It’s better to use the public API instead. If you want to draw any display object to BitmapData, you can pass it to the draw() method of a BitmapData object. You can pass the Sprite or Shape that owns the Graphics object to BitmapData.draw().

As for the scaling, you probably need to account for the value of stage.contentsScaleFactor in some way. I don’t recall the exact details, but I believe that this value is also required in some way when using BitmapData.draw().

I’m not sure why you are accessing OpenFL’s private internals like that. It’s better to use the public API instead.

I understand this but, the way I need to be drawn is very nitpicky, something that does the job that could be called a fairly big amount of times while keeping a decent FPS. The method I’m using as of now accomplishes this, with the issue of going with private internals, but going with draw() makes even two calls in a row go to 20 max, which is not very ideal.

you probably need to account for the value of stage.contentsScaleFactor in some way.

I’m not sure this could do, since from what I can remember looking into the source, it’s only used by Stage itself and doesnt seem to go beyond that class besides documentation mentioning it.

The value of stage.contentsScaleFactor affects all display object rendering. Traditionally, OpenFL used stage.window.scale (which you’ll see used more often internally), but Flash added stage.contentsScaleFactor, so OpenFL needed to add it too. Both will return the same value.