Skip to content

Commit

Permalink
Make Reprocessing work with the latest bs-platform (#140)
Browse files Browse the repository at this point in the history
* Make small changes to work with reasongl-web and bucklescript proper

* Update package.json to pin reasongl-web version

* Bump version of reasongl-web

* Update reasongl-web version

* Maybe bs-platform has a fix for a bug...

* Bump reasongl version and make fixes for it

* cleanup package.json
  • Loading branch information
bsansouci authored Nov 19, 2020
1 parent bcf8344 commit 341ad22
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"dir": "examples",
"type": "dev"
}],
"bs-dependencies": ["@bsansouci/reasongl", "dynlink"],
"entries": [{
"backend": "bytecode",
"main-module": "IndexHot"
Expand Down Expand Up @@ -47,5 +46,6 @@
"backend": "js",
"main-module": "Redsquare"
}],
"bs-dependencies": ["@bsansouci/reasongl-web"],
"refmt": 3
}
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
"version": "1.0.0",
"description": "Processing library for Reason",
"scripts": {
"build": "bsb -make-world -backend js",
"build:bytecode": "bsb -make-world -backend bytecode",
"build:native": "bsb -make-world -backend native",
"build": "bsb -make-world",
"clean": "bsb -clean-world"
},
"dependencies": {
"@bsansouci/reasongl": "^1.0.0",
"@bsansouci/tsdl": "^1.0.1",
"dynlink": "bsansouci/otherlibs"
"@bsansouci/reasongl-web": "^1.0.1"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +25,6 @@
"license": "MIT",
"author": "bsansouci & schmavery",
"devDependencies": {
"bsb-native": "^5.0.0"
"bs-platform": "^8.3.3"
}
}
1 change: 1 addition & 0 deletions src/Reprocessing.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module RGLConstants = Reasongl.Constants
open Reasongl;

open Reprocessing_Internal;
Expand Down
2 changes: 0 additions & 2 deletions src/Reprocessing_Common.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
open Reasongl;

module Constants = RGLConstants;

type strokeCapT =
| Round
| Square
Expand Down
2 changes: 1 addition & 1 deletion src/Reprocessing_Draw.re
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ let textWidth = (~font=?, ~body, env) =>
let clear = env =>
Reasongl.Gl.clear(
~context=env.gl,
~mask=Constants.color_buffer_bit lor Constants.depth_buffer_bit
~mask=Reasongl.Constants.color_buffer_bit lor Reasongl.Constants.depth_buffer_bit
);

let background = (color, env: glEnv) => {
Expand Down
8 changes: 5 additions & 3 deletions src/Reprocessing_Events.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
type buttonStateT = Reasongl.Gl.Events.buttonStateT = | LeftButton | MiddleButton | RightButton;
open Reasongl

type stateT = Reasongl.Gl.Events.stateT = | MouseDown | MouseUp;
type buttonStateT = Gl.Events.buttonStateT = | LeftButton | MiddleButton | RightButton;

type stateT = Gl.Events.stateT = | MouseDown | MouseUp;

type keycodeT =
Reasongl.Gl.Events.keycodeT =
Gl.Events.keycodeT =
| Backspace
| Delete
| Tab
Expand Down
58 changes: 29 additions & 29 deletions src/Reprocessing_Internal.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let getProgram =
~fragmentShader as fragmentShaderSource: string
)
: option(Gl.programT) => {
let vertexShader = Gl.createShader(~context, RGLConstants.vertex_shader);
let vertexShader = Gl.createShader(~context, Constants.vertex_shader);
Gl.shaderSource(~context, ~shader=vertexShader, ~source=vertexShaderSource);
Gl.compileShader(~context, vertexShader);
let compiledCorrectly =
Expand All @@ -23,7 +23,7 @@ let getProgram =
== 1;
if (compiledCorrectly) {
let fragmentShader =
Gl.createShader(~context, RGLConstants.fragment_shader);
Gl.createShader(~context, Constants.fragment_shader);
Gl.shaderSource(
~context,
~shader=fragmentShader,
Expand Down Expand Up @@ -76,7 +76,7 @@ let createCanvas = (window, height: int, width: int) : glEnv => {
Gl.clearColor(~context, ~r=0., ~g=0., ~b=0., ~a=1.);
Gl.clear(
~context,
~mask=RGLConstants.color_buffer_bit lor RGLConstants.depth_buffer_bit
~mask=Constants.color_buffer_bit lor Constants.depth_buffer_bit
);

/*** Camera is a simple record containing one matrix used to project a point in 3D onto the screen. **/
Expand Down Expand Up @@ -123,16 +123,16 @@ let createCanvas = (window, height: int, width: int) : glEnv => {
/*** This tells OpenGL that we're going to be using texture0. OpenGL imposes a limit on the number of
texture we can manipulate at the same time. That limit depends on the device. We don't care as we'll just
always use texture0. **/
Gl.activeTexture(~context, RGLConstants.texture0);
Gl.activeTexture(~context, Constants.texture0);

/*** Bind `texture` to `texture_2d` to modify it's magnification and minification params. **/
Gl.bindTexture(~context, ~target=RGLConstants.texture_2d, ~texture);
Gl.bindTexture(~context, ~target=Constants.texture_2d, ~texture);
let uSampler = Gl.getUniformLocation(~context, ~program, ~name="uSampler");

/*** Load a dummy texture. This is because we're using the same shader for things with and without a texture */
Gl.texImage2D_RGBA(
~context,
~target=RGLConstants.texture_2d,
~target=Constants.texture_2d,
~level=0,
~width=1,
~height=1,
Expand All @@ -141,23 +141,23 @@ let createCanvas = (window, height: int, width: int) : glEnv => {
);
Gl.texParameteri(
~context,
~target=RGLConstants.texture_2d,
~pname=RGLConstants.texture_mag_filter,
~param=RGLConstants.linear
~target=Constants.texture_2d,
~pname=Constants.texture_mag_filter,
~param=Constants.linear
);
Gl.texParameteri(
~context,
~target=RGLConstants.texture_2d,
~pname=RGLConstants.texture_min_filter,
~param=RGLConstants.linear_mipmap_nearest
~target=Constants.texture_2d,
~pname=Constants.texture_min_filter,
~param=Constants.linear_mipmap_nearest
);

/*** Enable blend and tell OpenGL how to blend. */
Gl.enable(~context, RGLConstants.blend);
Gl.enable(~context, Constants.blend);
Gl.blendFunc(
~context,
RGLConstants.src_alpha,
RGLConstants.one_minus_src_alpha
Constants.src_alpha,
Constants.one_minus_src_alpha
);

/***
Expand Down Expand Up @@ -255,24 +255,24 @@ let drawGeometry =
`array_buffer` */
Gl.bindBuffer(
~context=env.gl,
~target=RGLConstants.array_buffer,
~target=Constants.array_buffer,
~buffer=env.vertexBuffer
);

/*** Copy all of the data over into whatever's in `array_buffer` (so here it's `vertexBuffer`) **/
Gl.bufferData(
~context=env.gl,
~target=RGLConstants.array_buffer,
~target=Constants.array_buffer,
~data=vertexArray,
~usage=RGLConstants.stream_draw
~usage=Constants.stream_draw
);

/*** Tell the GPU about the shader attribute called `aVertexPosition` so it can access the data per vertex */
Gl.vertexAttribPointer(
~context=env.gl,
~attribute=env.aVertexPosition,
~size=2,
~type_=RGLConstants.float_,
~type_=Constants.float_,
~normalize=false,
~stride=vertexSize * 4,
~offset=0
Expand All @@ -283,7 +283,7 @@ let drawGeometry =
~context=env.gl,
~attribute=env.aVertexColor,
~size=4,
~type_=RGLConstants.float_,
~type_=Constants.float_,
~normalize=false,
~stride=vertexSize * 4,
~offset=2 * 4
Expand All @@ -294,7 +294,7 @@ let drawGeometry =
~context=env.gl,
~attribute=env.aTextureCoord,
~size=2,
~type_=RGLConstants.float_,
~type_=Constants.float_,
~normalize=false,
~stride=vertexSize * 4,
~offset=6 * 4
Expand All @@ -308,22 +308,22 @@ let drawGeometry =
the data representing the indices of the vertex. **/
Gl.bindBuffer(
~context=env.gl,
~target=RGLConstants.element_array_buffer,
~target=Constants.element_array_buffer,
~buffer=env.elementBuffer
);

/*** Copy the `elementArray` into whatever buffer is in `element_array_buffer` **/
Gl.bufferData(
~context=env.gl,
~target=RGLConstants.element_array_buffer,
~target=Constants.element_array_buffer,
~data=elementArray,
~usage=RGLConstants.stream_draw
~usage=Constants.stream_draw
);

/*** We bind `texture` to texture_2d, like we did for the vertex buffers in some ways (I think?) **/
Gl.bindTexture(
~context=env.gl,
~target=RGLConstants.texture_2d,
~target=Constants.texture_2d,
~texture=textureBuffer
);

Expand All @@ -332,7 +332,7 @@ let drawGeometry =
~context=env.gl,
~mode,
~count,
~type_=RGLConstants.unsigned_short,
~type_=Constants.unsigned_short,
~offset=0
);
};
Expand Down Expand Up @@ -364,7 +364,7 @@ let flushGlobalBatch = env =>
~offset=0,
~len=env.batch.elementPtr
),
~mode=RGLConstants.triangles,
~mode=Constants.triangles,
~count=env.batch.elementPtr,
~textureBuffer,
env
Expand Down Expand Up @@ -796,7 +796,7 @@ let loadImage = (env: glEnv, filename, isPixel) : imageT => {
let imageRef = {glData: None, drawnTo: false};
Gl.loadImage(
~filename,
~loadOption=LoadRGBA,
~loadOption=Gl.LoadRGBA,
~callback=
imageData =>
switch imageData {
Expand Down Expand Up @@ -849,7 +849,7 @@ let loadImageFromMemory = (env: glEnv, data, isPixel) : imageT => {
let imageRef = {glData: None, drawnTo: false};
Gl.loadImageFromMemory(
~data,
~loadOption=LoadRGBA,
~loadOption=Gl.LoadRGBA,
~callback=
imageData =>
switch imageData {
Expand Down

0 comments on commit 341ad22

Please sign in to comment.