-
-
Notifications
You must be signed in to change notification settings - Fork 957
render: Handle uploading to Bc3RgbaUnorm and Rgba16Float textures #22700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SuchAFuriousDeath
wants to merge
2
commits into
ruffle-rs:master
Choose a base branch
from
SuchAFuriousDeath:texture-upload-compression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
tests/tests/swfs/avm2/stage3d_texture_format_conversion/Test.as
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package { | ||
| import com.adobe.utils.AGALMiniAssembler; | ||
|
|
||
| import flash.display.Stage3D; | ||
| import flash.display3D.Context3D; | ||
| import flash.display3D.Context3DBlendFactor; | ||
| import flash.display3D.Context3DProgramType; | ||
| import flash.display3D.Context3DRenderMode; | ||
| import flash.display3D.Context3DVertexBufferFormat; | ||
| import flash.display3D.IndexBuffer3D; | ||
| import flash.display3D.Program3D; | ||
| import flash.display3D.VertexBuffer3D; | ||
| import flash.events.Event; | ||
| import flash.display.MovieClip; | ||
| import flash.display.BitmapData; | ||
|
|
||
| public class Test extends MovieClip { | ||
| public const viewWidth:Number = 500; | ||
| public const viewHeight:Number = 500; | ||
|
|
||
| private var stage3D:Stage3D; | ||
| private var renderContext:Context3D; | ||
| private var indexList:IndexBuffer3D; | ||
| private var vertexes:VertexBuffer3D; | ||
|
|
||
| private const VERTEX_SHADER:String = | ||
| "add op, va0, vc0 \n" + | ||
| "mov v0, va1"; | ||
|
|
||
| private const FRAGMENT_SHADER_DXT5:String = | ||
| "tex oc, v0, fs0 <2d,clamp,linear,mipnone,dxt5>"; | ||
|
|
||
| private const FRAGMENT_SHADER_FLOAT:String = | ||
| "tex oc, v0, fs0 <2d,clamp,linear,mipnone>"; | ||
|
|
||
| private var vertexAssembly:AGALMiniAssembler = new AGALMiniAssembler(false); | ||
| private var fragmentAssemblyDxt5:AGALMiniAssembler = new AGALMiniAssembler(false); | ||
| private var fragmentAssemblyFloat:AGALMiniAssembler = new AGALMiniAssembler(false); | ||
| private var programDxt5:Program3D; | ||
| private var programFloat:Program3D; | ||
|
|
||
| [Embed(source = "circle.png")] | ||
| public var CIRCLE_PNG: Class; | ||
|
|
||
| public function Test() { | ||
| stage3D = this.stage.stage3Ds[0]; | ||
| stage3D.addEventListener(Event.CONTEXT3D_CREATE, contextCreated); | ||
| // Request "standard" profile which supports compressedAlpha and rgbaHalfFloat | ||
| stage3D.requestContext3D(Context3DRenderMode.AUTO, "standard"); | ||
|
|
||
| vertexAssembly.assemble(Context3DProgramType.VERTEX, VERTEX_SHADER, 2); | ||
| fragmentAssemblyDxt5.assemble(Context3DProgramType.FRAGMENT, FRAGMENT_SHADER_DXT5, 2); | ||
| fragmentAssemblyFloat.assemble(Context3DProgramType.FRAGMENT, FRAGMENT_SHADER_FLOAT, 2); | ||
| } | ||
|
|
||
| private function contextCreated(event:Event):void { | ||
| renderContext = Stage3D(event.target).context3D; | ||
| renderContext.enableErrorChecking = true; | ||
| renderContext.configureBackBuffer(viewWidth, viewHeight, 4, true); | ||
|
|
||
| var triangles:Vector.<uint> = Vector.<uint>([0, 1, 2, 0, 2, 3]); | ||
| indexList = renderContext.createIndexBuffer(triangles.length); | ||
| indexList.uploadFromVector(triangles, 0, triangles.length); | ||
|
|
||
| const dataPerVertex:int = 5; | ||
| var vertexData:Vector.<Number> = Vector.<Number>([ | ||
| -0.4, -0.4, 0, 0, 1, | ||
| 0.4, -0.4, 0, 1, 1, | ||
| 0.4, 0.4, 0, 1, 0, | ||
| -0.4, 0.4, 0, 0, 0 | ||
| ]); | ||
| vertexes = renderContext.createVertexBuffer(vertexData.length / dataPerVertex, dataPerVertex); | ||
| vertexes.uploadFromVector(vertexData, 0, vertexData.length / dataPerVertex); | ||
|
|
||
| renderContext.setVertexBufferAt(0, vertexes, 0, Context3DVertexBufferFormat.FLOAT_3); | ||
| renderContext.setVertexBufferAt(1, vertexes, 3, Context3DVertexBufferFormat.FLOAT_2); | ||
|
|
||
| var circleBitmap:BitmapData = new CIRCLE_PNG().bitmapData; | ||
|
|
||
| var compressedTexture = renderContext.createTexture( | ||
| 512, 512, | ||
| "compressedAlpha", | ||
| false | ||
| ); | ||
| compressedTexture.uploadFromBitmapData(circleBitmap); | ||
|
|
||
| var halfFloatTexture = renderContext.createTexture( | ||
| 512, 512, | ||
| "rgbaHalfFloat", | ||
| false | ||
| ); | ||
| halfFloatTexture.uploadFromBitmapData(circleBitmap); | ||
|
|
||
| programDxt5 = renderContext.createProgram(); | ||
| programDxt5.upload(vertexAssembly.agalcode, fragmentAssemblyDxt5.agalcode); | ||
|
|
||
| programFloat = renderContext.createProgram(); | ||
| programFloat.upload(vertexAssembly.agalcode, fragmentAssemblyFloat.agalcode); | ||
|
|
||
| renderContext.setBlendFactors(Context3DBlendFactor.SOURCE_ALPHA, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA); | ||
|
|
||
| renderContext.clear(.3, .3, .3, 1, 1, 0); | ||
|
|
||
| renderContext.setProgram(programDxt5); | ||
| renderContext.setTextureAt(0, compressedTexture); | ||
| renderContext.setProgramConstantsFromVector("vertex", 0, Vector.<Number>([-0.5, 0.0, 0.0, 0.0])); | ||
| renderContext.drawTriangles(indexList, 0, 2); | ||
|
|
||
| renderContext.setProgram(programFloat); | ||
| renderContext.setTextureAt(0, halfFloatTexture); | ||
| renderContext.setProgramConstantsFromVector("vertex", 0, Vector.<Number>([0.5, 0.0, 0.0, 0.0])); | ||
| renderContext.drawTriangles(indexList, 0, 2); | ||
|
|
||
| renderContext.present(); | ||
| } | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's non-intuitive and closed for extension.
Have you considered using render's
Bitmap<'a>?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't. I'll take a stab at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want me to add more formats to to the BitmapFormat enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if we're using other formats it makes sense to add them there and provide conversions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that confuses me a little bit. Because there are only 2 options here. Either the data is rgba (and needs conversion), or it's already in the dst texture format. So it doesn't really make sense to me to but a Bitmap<'a> here, that just allows for more options that are impossible to happen.