Skip to content
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

upgrade three for better error printing in julia #3290

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions WGLMakie/src/Camera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as THREE from "https://cdn.esm.sh/v66/three@0.136/es2021/three.js";
import * as THREE from "https://cdn.esm.sh/v66/three@0.157/es2021/three.js";

const pixelRatio = window.devicePixelRatio || 1.0;

Expand Down Expand Up @@ -260,8 +260,7 @@ export class MakieCamera {
// update all existing preprojection matrices
Object.keys(this.preprojections).forEach((key) => {
const [space, markerspace] = key.split(","); // jeez js, really just converting array keys to "elem,elem"?
this.preprojections[key].value =
this.calculate_preprojection_matrix(space, markerspace);
this.preprojections[key].value = this.calculate_preprojection_matrix(space, markerspace);
});
}

Expand Down
37 changes: 31 additions & 6 deletions WGLMakie/src/Serialization.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Camera from "./Camera.js";
import * as THREE from "https://cdn.esm.sh/v66/three@0.136/es2021/three.js";
import * as THREE from "https://cdn.esm.sh/v66/three@0.157/es2021/three.js";

// global scene cache to look them up for dynamic operations in Makie
// e.g. insert!(scene, plot) / delete!(scene, plot)
Expand Down Expand Up @@ -239,10 +239,25 @@ function connect_uniforms(mesh, updater) {
});
}

function convert_RGB_to_RGBA(rgbArray) {
const length = rgbArray.length;
const rgbaArray = new Float32Array((length / 3) * 4);

for (let i = 0, j = 0; i < length; i += 3, j += 4) {
rgbaArray[j] = rgbArray[i]; // R
rgbaArray[j + 1] = rgbArray[i + 1]; // G
rgbaArray[j + 2] = rgbArray[i + 2]; // B
rgbaArray[j + 3] = 1.0; // A
}

return rgbaArray;
}


function create_texture(data) {
const buffer = data.data;
if (data.size.length == 3) {
const tex = new THREE.DataTexture3D(
const tex = new THREE.Data3DTexture(
buffer,
data.size[0],
data.size[1],
Expand All @@ -253,13 +268,22 @@ function create_texture(data) {
return tex;
} else {
// a little optimization to not send the texture atlas over & over again
const tex_data =
buffer == "texture_atlas" ? TEXTURE_ATLAS[0].value : buffer;
let tex_data;
if (buffer == "texture_atlas") {
tex_data = TEXTURE_ATLAS[0].value;
} else {
tex_data = buffer;
}
let format = THREE[data.three_format];
if (data.three_format == "RGBFormat") {
tex_data = convert_RGB_to_RGBA(tex_data);
format = THREE.RGBAFormat;
}
return new THREE.DataTexture(
tex_data,
data.size[0],
data.size[1],
THREE[data.three_format],
format,
THREE[data.three_type]
);
}
Expand All @@ -268,7 +292,7 @@ function create_texture(data) {
function re_create_texture(old_texture, buffer, size) {
let tex;
if (size.length == 3) {
tex = new THREE.DataTexture3D(buffer, size[0], size[1], size[2]);
tex = new THREE.Data3DTexture(buffer, size[0], size[1], size[2]);
tex.format = old_texture.format;
tex.type = old_texture.type;
} else {
Expand Down Expand Up @@ -379,6 +403,7 @@ function create_material(program) {
fragmentShader: program.fragment_source,
side: is_volume ? THREE.BackSide : THREE.DoubleSide,
transparent: true,
glslVersion: THREE.GLSL3,
depthTest: !program.overdraw.value,
depthWrite: !program.transparency.value,
});
Expand Down
6 changes: 4 additions & 2 deletions WGLMakie/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,12 @@ function serialize_three(program::Program)
uniforms = serialize_uniforms(program.uniforms)
attribute_updater = Observable(["", [], 0])
register_geometry_updates(attribute_updater, program)
# TODO, make this configurable in ShaderAbstractions
update_shader(x) = replace(x, "#version 300 es" => "")
return Dict(:vertexarrays => serialize_named_buffer(program.vertexarray),
:faces => indices, :uniforms => uniforms,
:vertex_source => program.vertex_source,
:fragment_source => program.fragment_source,
:vertex_source => update_shader(program.vertex_source),
:fragment_source => update_shader(program.fragment_source),
:uniform_updater => uniform_updater(program.uniforms),
:attribute_updater => attribute_updater)
end
Expand Down
9 changes: 8 additions & 1 deletion WGLMakie/src/three_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ function three_display(session::Session, scene::Scene; screen_config...)
evaljs(session, js"""
$(WGL).then(WGL => {
try {
WGL.create_scene($wrapper, $canvas, $canvas_width, $scene_serialized, $comm, $width, $height, $(ta), $(config.framerate), $(config.resize_to_body))
const renderer = WGL.create_scene(
$wrapper, $canvas, $canvas_width, $scene_serialized, $comm, $width, $height,
$(ta), $(config.framerate), $(config.resize_to_body))
const gl = renderer.getContext()
const err = gl.getError()
if (err != gl.NO_ERROR) {
throw new Error("WebGL error: " + WGL.wglerror(gl, err))
}
$(done_init).notify(true)
} catch (e) {
JSServe.Connection.send_error("error initializing scene", e)
Expand Down
Loading
Loading