Skip to content

Commit

Permalink
chore: tell dont ask fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Jan 22, 2024
1 parent f196a38 commit 6426856
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion playground/src/pages/rendering-modes/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ setTimeout(() => {
<template>
<TresCanvas
:clear-color="clearColor"
render-mode="manual"
render-mode="on-demand"
@render="() => console.log('onRender')"
>
<Scene />
Expand Down
2 changes: 1 addition & 1 deletion playground/src/pages/rendering-modes/scene.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OrbitControls } from '@tresjs/cientos'
const { invalidate, advance } = useTres()
function onControlChange() {
advance()
invalidate()
}
const positionX = ref(0)
Expand Down
6 changes: 5 additions & 1 deletion src/composables/useTresContextProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface TresContext {
* If set to 'always', the scene will be rendered every frame
*/
renderMode: Ref<'always' | 'on-demand' | 'manual'>
canBeInvalidated: ComputedRef<boolean>
internal: InternalState
/**
* Invalidates the current frame when renderMode === 'on-demand'
Expand Down Expand Up @@ -147,6 +148,8 @@ export function useTresContextProvider({
disableRender,
})

const renderMode = ref<'always' | 'on-demand' | 'manual'>(rendererOptions.renderMode || 'always')

const toProvide: TresContext = {
sizes,
scene: localScene,
Expand All @@ -167,7 +170,8 @@ export function useTresContextProvider({
accumulator: [],
},
},
renderMode: ref(rendererOptions.renderMode || 'always'),
renderMode,
canBeInvalidated: computed(() => renderMode.value === 'on-demand' && internal.frames.value === 0),
internal,
advance,
extend,
Expand Down
2 changes: 1 addition & 1 deletion src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function invalidateInstance(instance: TresObject) {

if (!ctx) return

if (ctx.renderMode.value === 'on-demand' && ctx.internal.frames.value === 0) {
if (ctx.canBeInvalidated.value) {
ctx.invalidate()
}

Expand Down

0 comments on commit 6426856

Please sign in to comment.