Border.hx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package h3d.pass;
  2. private class BorderShader extends h3d.shader.ScreenShader {
  3. static var SRC = {
  4. @param var color : Vec4;
  5. function fragment() {
  6. pixelColor = color;
  7. }
  8. }
  9. }
  10. class Border extends ScreenFx<BorderShader> {
  11. var width(default, null) : Int;
  12. var height(default, null) : Int;
  13. var size(default, null) : Int;
  14. public function new( width : Int, height : Int, size : Int = 1 ) {
  15. super(new BorderShader());
  16. this.width = width;
  17. this.height = height;
  18. this.size = size;
  19. shader.color.set(1,1,1,1);
  20. }
  21. function createPrimitive() {
  22. var bbuf = new hxd.FloatBuffer();
  23. inline function add(x, y) {
  24. bbuf.push((x / width) * 2 - 1);
  25. bbuf.push(1 - (y / height) * 2);
  26. }
  27. add(0, 0);
  28. add(width, 0);
  29. add(0, size);
  30. add(width, size);
  31. add(0, 0);
  32. add(size, 0);
  33. add(0, height);
  34. add(size, height);
  35. add(0, height-size);
  36. add(width, height-size);
  37. add(0, height);
  38. add(width, height);
  39. add(width-size, 0);
  40. add(width, 0);
  41. add(width-size, height);
  42. add(width, height);
  43. this.primitive = new h3d.prim.RawPrimitive({ vbuf : bbuf, format : hxd.BufferFormat.make([{ name : "position", type : DVec2 }]) }, true);
  44. }
  45. override function render() {
  46. if (primitive == null)
  47. createPrimitive();
  48. super.render();
  49. }
  50. override function dispose() {
  51. if (primitive != null)
  52. this.primitive.dispose();
  53. super.dispose();
  54. }
  55. }