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

Add "view as standalone webpage" link; improvements for external samples #473

Merged
merged 1 commit into from
Nov 14, 2024
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
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ <h1>
<div id="sample" style="display: none;">
<div class="sampleInfo">
<h1 id="title"></h1>
<a id="src" target="_blank" rel="noreferrer" href="">See it on Github!</a>
<a id="src" target="_blank" rel="noreferrer" href="">View source!</a>
&mdash; <a id="standalone" target="_blank" rel="noreferrer" href="">View as standalone webpage</a>
<p id="description"></p>
</div>
<div class="sampleContainer"></div>
Expand Down
10 changes: 7 additions & 3 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ body {

a {
text-decoration: none;
color: var(--link)
color: var(--link);
}
a:not([href]), a[href=""] {
/* link is missing href */
text-decoration: wavy underline;
color: #f00;
}

a:hover {
text-decoration: underline;
}
Expand All @@ -49,4 +53,4 @@ main {

.cm-editor {
max-height: 100vh;
}
}
10 changes: 5 additions & 5 deletions sample/bundleCulling/meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
name: 'Bundle Culling',
description: `A demonstration of using frustum culling with render bundles through indirect instanced draw calls.

Source at <https://github.com/toji/webgpu-bundle-culling/>
`,
description: `A demonstration of using frustum culling with render bundles through indirect instanced draw calls.`,
filename: __DIRNAME__,
url: 'https://toji.github.io/webgpu-bundle-culling/',
external: {
url: 'https://toji.github.io/webgpu-bundle-culling/',
sourceURL: 'https://github.com/toji/webgpu-bundle-culling',
},
sources: [],
};
10 changes: 5 additions & 5 deletions sample/clusteredShading/meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
name: 'Clustered Shading',
description: `Shows a simple clustered forward shading renderer.

Source at <https://github.com/toji/webgpu-clustered-shading/>
`,
description: `Shows a simple clustered forward shading renderer.`,
filename: __DIRNAME__,
url: 'https://toji.github.io/webgpu-clustered-shading/',
external: {
url: 'https://toji.github.io/webgpu-clustered-shading/',
sourceURL: 'https://github.com/toji/webgpu-clustered-shading',
},
sources: [],
};
10 changes: 5 additions & 5 deletions sample/marchingCubes/meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
name: 'Marching Cubes',
description: `This example demonstrates how to dynamically generate procedural meshes using a signed distance field and a multi-pass marching cubes algorithm on the GPU.

Source at <https://github.com/tcoppex/webgpu-marchingcubes>
`,
description: `This example demonstrates how to dynamically generate procedural meshes using a signed distance field and a multi-pass marching cubes algorithm on the GPU.`,
filename: __DIRNAME__,
url: 'https://tcoppex.github.io/webgpu-marchingcubes/',
external: {
url: 'https://tcoppex.github.io/webgpu-marchingcubes/',
sourceURL: 'https://github.com/tcoppex/webgpu-marchingcubes',
},
sources: [],
};
10 changes: 5 additions & 5 deletions sample/metaballs/meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
name: 'Metaballs',
description: `This example shows an implementation of metaballs with WebGPU.

Source at https://github.com/toji/webgpu-metaballs/
`,
description: `This example shows an implementation of metaballs with WebGPU.`,
filename: __DIRNAME__,
url: 'https://toji.github.io/webgpu-metaballs/',
external: {
url: 'https://toji.github.io/webgpu-metaballs/',
sourceURL: 'https://github.com/toji/webgpu-metaballs',
},
sources: [],
};
10 changes: 5 additions & 5 deletions sample/pristineGrid/meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
name: 'Pristine Grid',
description: `A simple WebGPU implementation of the "Pristine Grid" technique described in this wonderful little blog post: <https://bgolus.medium.com/the-best-darn-grid-shader-yet-727f9278b9d8>

Source at <https://github.com/toji/pristine-grid-webgpu/>
`,
description: `A simple WebGPU implementation of the "Pristine Grid" technique described in this wonderful little blog post: <https://bgolus.medium.com/the-best-darn-grid-shader-yet-727f9278b9d8>`,
filename: __DIRNAME__,
url: 'https://toji.github.io/pristine-grid-webgpu/',
external: {
url: 'https://toji.github.io/pristine-grid-webgpu/',
sourceURL: 'https://github.com/toji/pristine-grid-webgpu',
},
sources: [],
};
10 changes: 5 additions & 5 deletions sample/spookyball/meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
name: 'Spookyball',
description: `This example shows a simple game made with WebGPU.

Source at <https://github.com/toji/spookyball>
`,
description: `This example shows a simple game made with WebGPU.`,
filename: __DIRNAME__,
url: 'https://spookyball.com',
external: {
url: 'https://spookyball.com',
sourceURL: 'https://github.com/toji/spookyball',
},
sources: [],
};
20 changes: 12 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function getElem(
const sampleListElem = getElem('#samplelist');
const sampleElem = getElem('#sample');
const githubElem = getElem('#src') as HTMLAnchorElement;
const standaloneElem = getElem('#standalone') as HTMLAnchorElement;
const introElem = getElem('#intro');
const codeTabsElem = getElem('#codeTabs');
const sourcesElem = getElem('#sources');
Expand Down Expand Up @@ -183,7 +184,7 @@ function setSampleIFrame(
descriptionElem.innerHTML = '';

currentSampleInfo = sampleInfo;
const { name, description, filename, url, sources } = sampleInfo || {
const { name, description, filename, external, sources } = sampleInfo || {
name: '',
description: '',
filename: '',
Expand All @@ -197,17 +198,18 @@ function setSampleIFrame(
// Replace the iframe because changing src adds to the user's history.
sampleContainerElem.innerHTML = '';
if (filename) {
const src = url || `${filename}${search}`;
const src = external ? external.url : `${filename}${search}`;
sampleContainerElem.appendChild(el('iframe', { src }));
sampleContainerElem.style.height = sources.length > 0 ? '600px' : '100%';

if (url) {
// If it's remote example, hide the github link and assume it's in the description.
githubElem.style.display = 'none';
if (external) {
// For remote samples, get the source URL from the metadata.
githubElem.href = external.sourceURL;
standaloneElem.href = external.url;
} else {
// It's a local sample so show the github link.
githubElem.style.display = '';
// For local samples, generate a link to the source in this repo.
githubElem.href = `https://github.com/webgpu/webgpu-samples/tree/main/${filename}`;
standaloneElem.href = filename;
}

// hide intro and show sample
Expand Down Expand Up @@ -294,7 +296,9 @@ for (const { title, description, samples } of pageCategories) {
...Object.entries(samples).map(([key, sampleInfo]) =>
el('li', {}, [
el('a', {
href: sampleInfo.filename,
href: sampleInfo.external
? sampleInfo.external.url
: sampleInfo.filename,
...(!sampleInfo.openInNewTab && {
onClick: (e: PointerEvent) => {
setSampleIFrameURL(e, sampleInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type SampleInfo = {
description: string;
openInNewTab?: boolean;
filename: string; // used if sample is local
url?: string; // used if sample is remote
external?: { url: string; sourceURL: string }; // used if sample is remote
sources: SourceInfo[];
};

Expand Down