-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
69 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# 0.92.13 - Aug 7, 2021 | ||
|
||
Added: | ||
|
||
- RuntimeEffect #120 #124 thx @Vechro | ||
|
||
# 0.92.11 - July 27, 2021 | ||
|
||
Added: | ||
|
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 |
---|---|---|
@@ -1,20 +1,48 @@ | ||
package org.jetbrains.skija.examples.scenes; | ||
|
||
import java.nio.*; | ||
import java.nio.file.*; | ||
import java.nio.file.Path; | ||
import java.io.*; | ||
import org.jetbrains.skija.*; | ||
|
||
public class RuntimeEffectScene extends Scene { | ||
@Override | ||
public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) { | ||
var sksl = "const half3 iColor = half3(0, 0.5, 0.75);\n" | ||
+ "half4 main(float2 coord) {\n" | ||
+ " return iColor.rgb1;\n" | ||
+ "}"; | ||
public final Shader _texture; | ||
public final RuntimeEffect _effect; | ||
|
||
public RuntimeEffectScene() { | ||
try { | ||
_texture = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/triangle.png")))).makeShader(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
var effect = RuntimeEffect.makeForShader(sksl); | ||
var myShader = effect.makeShader(null, null, null, false); | ||
_effect = RuntimeEffect.makeForShader( | ||
"uniform float xScale;\n" + | ||
"uniform float xBias;\n" + | ||
"uniform float yScale;\n" + | ||
"uniform float yBias;\n" + | ||
"uniform shader input;\n" + | ||
"half4 main(float2 xy) {\n" + | ||
" half4 tex = sample(input, mod(xy, 100));\n" + | ||
" return half4((xy.x - xBias) / xScale / 2 + 0.5, (xy.y - yBias) / yScale / 2 + 0.5, tex.b, 1);\n" + | ||
"}" | ||
); | ||
} | ||
|
||
var p = new Paint(); | ||
p.setShader(myShader); | ||
canvas.drawPaint(p); | ||
@Override | ||
public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) { | ||
var bb = ByteBuffer.allocate(4 * 4).order(ByteOrder.nativeOrder()); | ||
bb.putFloat((float) width); | ||
bb.putFloat((float) xpos); | ||
bb.putFloat((float) height); | ||
bb.putFloat((float) ypos); | ||
try (var data = Data.makeFromBytes(bb.array()); | ||
var paint = new Paint(); | ||
var shader = _effect.makeShader(data, new Shader[] { _texture }, null, true);) | ||
{ | ||
paint.setShader(shader); | ||
canvas.drawPaint(paint); | ||
} | ||
} | ||
} |
This file contains 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 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 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