Skip to content

Commit

Permalink
Move some module aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
wlitwin committed Aug 28, 2021
1 parent 049ff87 commit 37fccde
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
17 changes: 8 additions & 9 deletions renderers/gles2/core/graphv_gles2.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
open Graphv_core_lib

module Make(Gl : Ogl_intf.S) : Impl.S
with type Buffer.UByte.t = Gl.Buffer.UByte.t
and type Buffer.Float.t = Gl.Buffer.Float.t
and type gl = Gl.t
with type gl = Gl.t
and module Buffer = Gl.Buffer
and module Dyn = Gl.Dyn
and module VertexBuffer = Gl.VertexBuffer
and module Path = Gl.Path
= struct

module Buffer = Gl.Buffer
module Dyn = Gl.Dyn
module Path = Gl.Path
module VertexBuffer = Gl.VertexBuffer

type gl = Gl.t

Expand Down Expand Up @@ -106,10 +111,6 @@ module ShaderType = struct
let img = 3.
end

module VertexBuffer = Gl.VertexBuffer

module Path = Gl.Path

module IPath = struct
type t = {
fill_offset : int;
Expand Down Expand Up @@ -177,8 +178,6 @@ module Call = struct
;;
end

module Buffer = Gl.Buffer

let check_error _ = ()
(*Gl.check_error*)

Expand Down
4 changes: 2 additions & 2 deletions renderers/gles2/web/graphv_webgl_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Buffer = struct

let set = Typed_array.set
let get = Typed_array.unsafe_get
let [@inline always] length (t : t) : int = (*t##.length*) Js.Unsafe.get t "length"
let [@inline always] length (t : t) : int = t##.length
let [@inline always] sub (t : t) (start : int) (len : int) : t =
t##subarray start len

Expand All @@ -26,7 +26,7 @@ module Buffer = struct

let set : t -> int -> float -> unit = Typed_array.set
let get : t -> int -> float = Typed_array.unsafe_get
let [@inline always] length (t : t) : int = Js.Unsafe.get t "length"
let [@inline always] length (t : t) : int = t##.length

let fill (t : t) (value : float) =
let len : int = Js.Unsafe.get t "length" - 1 in
Expand Down
11 changes: 11 additions & 0 deletions test/gles2/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(executable
(name graphv_gles2_tests)
(libraries
graphv_gles2_native
glfw-ocaml
tgls.tgles2
)
(preprocess (pps ppx_expect))
(enabled_if (= %{profile} dev))
)

60 changes: 60 additions & 0 deletions test/gles2/graphv_gles2_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
open Tgles2

module Gv = Graphv_gles2_native

let _ =
GLFW.init();
at_exit GLFW.terminate;
GLFW.windowHint ~hint:GLFW.ClientApi ~value:GLFW.OpenGLESApi;
GLFW.windowHint ~hint:GLFW.ContextVersionMajor ~value:2;
GLFW.windowHint ~hint:GLFW.ContextVersionMinor ~value:0;

let window =
GLFW.createWindow ~width:400 ~height:400 ~title:"window" ()
in

GLFW.makeContextCurrent ~window:(Some window);
GLFW.swapInterval ~interval:1;

Gl.clear_color 0.3 0.3 0.32 1.;

let vg = Gv.create
~flags:Gv.CreateFlags.(antialias lor stencil_strokes)
()
in

while not GLFW.(windowShouldClose ~window) do
let win_w, win_h = GLFW.getWindowSize ~window in
Gl.viewport 0 0 win_w win_h;
Gl.clear (
Gl.color_buffer_bit
lor Gl.depth_buffer_bit
lor Gl.stencil_buffer_bit
);

Gv.begin_frame vg
~width:(float win_w)
~height:(float win_h)
~device_ratio:1.
;
Gv.Transform.scale vg ~x:2. ~y:2.;

Gv.Path.begin_ vg;
Gv.Path.arc vg ~cx:200. ~cy:200. ~a0:0. ~a1:(Float.pi*.0.5) ~r:100. ~dir:Gv.Winding.CW;
Gv.set_stroke_color vg
~color:Gv.Color.(rgba ~r:255 ~g:203 ~b:255 ~a:255);
Gv.set_stroke_width vg ~width:50.;
Gv.stroke vg;

Gv.Path.begin_ vg;
Gv.Path.circle vg ~cx:300. ~cy:200. ~r:30.;
Gv.set_fill_color vg
~color:Gv.Color.(rgba ~r:154 ~g:203 ~b:255 ~a:255);
Gv.fill vg;

Gv.end_frame vg;

GLFW.swapBuffers ~window;
GLFW.pollEvents();
done;
;;

0 comments on commit 37fccde

Please sign in to comment.