Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
99d2b1d4
Commit
99d2b1d4
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
moved vertexArray code to own file
parent
2766f3cc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-gl/webgl/render-item.ts
+38
-64
38 additions, 64 deletions
src/mol-gl/webgl/render-item.ts
src/mol-gl/webgl/vertex-array.ts
+31
-0
31 additions, 0 deletions
src/mol-gl/webgl/vertex-array.ts
with
69 additions
and
64 deletions
src/mol-gl/webgl/render-item.ts
+
38
−
64
View file @
99d2b1d4
...
@@ -5,13 +5,14 @@
...
@@ -5,13 +5,14 @@
*/
*/
import
{
UniformValues
}
from
'
./uniform
'
;
import
{
UniformValues
}
from
'
./uniform
'
;
import
{
AttributeValues
,
createAttributeBuffers
,
createElementsBuffer
,
ElementsBuffer
,
createAttributeBuffer
,
ArrayKind
,
AttributeBuffers
}
from
'
./buffer
'
;
import
{
AttributeValues
,
createAttributeBuffers
,
createElementsBuffer
,
ElementsBuffer
,
createAttributeBuffer
,
ArrayKind
}
from
'
./buffer
'
;
import
{
TextureValues
,
createTextures
}
from
'
./texture
'
;
import
{
TextureValues
,
createTextures
}
from
'
./texture
'
;
import
{
Context
}
from
'
./context
'
;
import
{
Context
}
from
'
./context
'
;
import
{
ShaderCode
,
addShaderDefines
,
DefineValues
}
from
'
../shader-code
'
;
import
{
ShaderCode
,
addShaderDefines
,
DefineValues
}
from
'
../shader-code
'
;
import
{
Program
}
from
'
./program
'
;
import
{
Program
}
from
'
./program
'
;
import
{
RenderableSchema
,
RenderableValues
,
AttributeSpec
}
from
'
../renderable/schema
'
;
import
{
RenderableSchema
,
RenderableValues
,
AttributeSpec
}
from
'
../renderable/schema
'
;
import
{
idFactory
}
from
'
mol-util/id-factory
'
;
import
{
idFactory
}
from
'
mol-util/id-factory
'
;
import
{
deleteVertexArray
,
createVertexArray
}
from
'
./vertex-array
'
;
const
getNextRenderItemId
=
idFactory
()
const
getNextRenderItemId
=
idFactory
()
...
@@ -53,28 +54,6 @@ function getValueVersions<T extends RenderableValues>(values: T) {
...
@@ -53,28 +54,6 @@ function getValueVersions<T extends RenderableValues>(values: T) {
return
versions
as
Versions
<
T
>
return
versions
as
Versions
<
T
>
}
}
function
createVertexArray
(
ctx
:
Context
,
program
:
Program
,
attributeBuffers
:
AttributeBuffers
,
elementsBuffer
?:
ElementsBuffer
)
{
const
{
oesVertexArrayObject
}
=
ctx
.
extensions
let
vertexArray
:
WebGLVertexArrayObjectOES
|
undefined
=
undefined
if
(
oesVertexArrayObject
)
{
vertexArray
=
oesVertexArrayObject
.
createVertexArrayOES
()
oesVertexArrayObject
.
bindVertexArrayOES
(
vertexArray
)
program
.
bindAttributes
(
attributeBuffers
)
if
(
elementsBuffer
)
elementsBuffer
.
bind
()
ctx
.
vaoCount
+=
1
oesVertexArrayObject
.
bindVertexArrayOES
(
null
!
)
}
return
vertexArray
}
function
deleteVertexArray
(
ctx
:
Context
,
vertexArray
?:
WebGLVertexArrayObjectOES
)
{
const
{
oesVertexArrayObject
}
=
ctx
.
extensions
if
(
oesVertexArrayObject
&&
vertexArray
)
{
oesVertexArrayObject
.
deleteVertexArrayOES
(
vertexArray
)
ctx
.
vaoCount
-=
1
}
}
export
interface
RenderItem
{
export
interface
RenderItem
{
readonly
id
:
number
readonly
id
:
number
readonly
programId
:
number
readonly
programId
:
number
...
@@ -111,8 +90,8 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
...
@@ -111,8 +90,8 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
let
vertexArray
:
WebGLVertexArrayObjectOES
|
undefined
=
createVertexArray
(
ctx
,
program
,
attributeBuffers
,
elementsBuffer
)
let
vertexArray
:
WebGLVertexArrayObjectOES
|
undefined
=
createVertexArray
(
ctx
,
program
,
attributeBuffers
,
elementsBuffer
)
let
drawCount
=
values
.
drawCount
.
ref
let
drawCount
=
values
.
drawCount
.
ref
.
value
let
instanceCount
=
values
.
instanceCount
.
ref
let
instanceCount
=
values
.
instanceCount
.
ref
.
value
let
destroyed
=
false
let
destroyed
=
false
...
@@ -131,18 +110,16 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
...
@@ -131,18 +110,16 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
}
}
program
.
bindTextures
(
textures
)
program
.
bindTextures
(
textures
)
if
(
elementsBuffer
)
{
if
(
elementsBuffer
)
{
angleInstancedArrays
.
drawElementsInstancedANGLE
(
glDrawMode
,
drawCount
.
value
,
elementsBuffer
.
_dataType
,
0
,
instanceCount
.
value
);
angleInstancedArrays
.
drawElementsInstancedANGLE
(
glDrawMode
,
drawCount
,
elementsBuffer
.
_dataType
,
0
,
instanceCount
);
}
else
{
}
else
{
angleInstancedArrays
.
drawArraysInstancedANGLE
(
glDrawMode
,
0
,
drawCount
.
value
,
instanceCount
.
value
)
angleInstancedArrays
.
drawArraysInstancedANGLE
(
glDrawMode
,
0
,
drawCount
,
instanceCount
)
}
}
},
},
update
:
()
=>
{
update
:
()
=>
{
let
defineChange
=
false
let
defineChange
=
false
Object
.
keys
(
defineValues
).
forEach
(
k
=>
{
Object
.
keys
(
defineValues
).
forEach
(
k
=>
{
const
value
=
defineValues
[
k
]
const
value
=
defineValues
[
k
]
if
(
value
.
ref
.
version
===
versions
[
k
])
{
if
(
value
.
ref
.
version
!==
versions
[
k
])
{
// console.log('define version unchanged', k)
}
else
{
console
.
log
(
'
define version changed
'
,
k
)
console
.
log
(
'
define version changed
'
,
k
)
defineChange
=
true
defineChange
=
true
versions
[
k
]
=
value
.
ref
.
version
versions
[
k
]
=
value
.
ref
.
version
...
@@ -152,8 +129,6 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
...
@@ -152,8 +129,6 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
if
(
defineChange
)
{
if
(
defineChange
)
{
console
.
log
(
'
some defines changed, need to rebuild program
'
)
console
.
log
(
'
some defines changed, need to rebuild program
'
)
programRef
.
free
()
programRef
.
free
()
// programCache.clear()
// console.log('programCache.count', programCache.count)
programRef
=
programCache
.
get
(
ctx
,
{
programRef
=
programCache
.
get
(
ctx
,
{
shaderCode
:
addShaderDefines
(
defineValues
,
shaderCode
),
shaderCode
:
addShaderDefines
(
defineValues
,
shaderCode
),
schema
schema
...
@@ -161,36 +136,35 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
...
@@ -161,36 +136,35 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
program
=
programRef
.
value
program
=
programRef
.
value
}
}
console
.
log
(
'
RenderItem.update
'
,
id
,
values
)
if
(
values
.
drawCount
.
ref
.
version
!==
versions
.
drawCount
)
{
if
(
values
.
drawCount
.
ref
.
version
!==
drawCount
.
version
)
{
console
.
log
(
'
drawCount version changed
'
)
console
.
log
(
'
drawCount version changed
'
)
drawCount
=
values
.
drawCount
.
ref
drawCount
=
values
.
drawCount
.
ref
.
value
versions
.
drawCount
=
values
.
drawCount
.
ref
.
version
}
}
if
(
values
.
instanceCount
.
ref
.
version
!==
instanceCount
.
version
)
{
if
(
values
.
instanceCount
.
ref
.
version
!==
versions
.
instanceCount
)
{
console
.
log
(
'
instanceCount version changed
'
)
console
.
log
(
'
instanceCount version changed
'
)
instanceCount
=
values
.
instanceCount
.
ref
instanceCount
=
values
.
instanceCount
.
ref
.
value
versions
.
instanceCount
=
values
.
instanceCount
.
ref
.
version
}
}
let
bufferChange
=
false
let
bufferChange
=
false
Object
.
keys
(
attributeValues
).
forEach
(
k
=>
{
Object
.
keys
(
attributeValues
).
forEach
(
k
=>
{
const
value
=
attributeValues
[
k
]
const
value
=
attributeValues
[
k
]
if
(
value
.
ref
.
version
===
versions
[
k
])
{
if
(
value
.
ref
.
version
!==
versions
[
k
])
{
// console.log('attribute version unchanged', k)
const
buffer
=
attributeBuffers
[
k
]
return
if
(
buffer
.
length
>=
value
.
ref
.
value
.
length
)
{
}
console
.
log
(
'
attribute array large enough to update
'
,
k
)
const
buffer
=
attributeBuffers
[
k
]
attributeBuffers
[
k
].
updateData
(
value
.
ref
.
value
)
if
(
buffer
.
length
>=
value
.
ref
.
value
.
length
)
{
}
else
{
console
.
log
(
'
attribute array large enough to update
'
,
k
)
console
.
log
(
'
attribute array to small, need to create new attribute
'
,
k
)
attributeBuffers
[
k
].
updateData
(
value
.
ref
.
value
)
attributeBuffers
[
k
].
destroy
()
}
else
{
const
spec
=
schema
[
k
]
as
AttributeSpec
<
ArrayKind
>
console
.
log
(
'
attribute array to small, need to create new attribute
'
,
k
)
attributeBuffers
[
k
]
=
createAttributeBuffer
(
ctx
,
value
.
ref
.
value
,
spec
.
itemSize
,
spec
.
divisor
)
attributeBuffers
[
k
].
destroy
()
bufferChange
=
true
const
spec
=
schema
[
k
]
as
AttributeSpec
<
ArrayKind
>
}
attributeBuffers
[
k
]
=
createAttributeBuffer
(
ctx
,
value
.
ref
.
value
,
spec
.
itemSize
,
spec
.
divisor
)
versions
[
k
]
=
value
.
ref
.
version
bufferChange
=
true
}
}
versions
[
k
]
=
value
.
ref
.
version
})
})
if
(
elementsBuffer
&&
values
.
elements
.
ref
.
version
!==
versions
.
elements
)
{
if
(
elementsBuffer
&&
values
.
elements
.
ref
.
version
!==
versions
.
elements
)
{
...
@@ -214,22 +188,22 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
...
@@ -214,22 +188,22 @@ export function createRenderItem(ctx: Context, drawMode: DrawMode, shaderCode: S
Object
.
keys
(
textureValues
).
forEach
(
k
=>
{
Object
.
keys
(
textureValues
).
forEach
(
k
=>
{
const
value
=
textureValues
[
k
]
const
value
=
textureValues
[
k
]
if
(
value
.
ref
.
version
===
versions
[
k
])
{
if
(
value
.
ref
.
version
!==
versions
[
k
])
{
// console.log('texture version unchanged', k)
console
.
log
(
'
texture version changed, uploading image
'
,
k
)
return
textures
[
k
].
load
(
value
.
ref
.
value
)
versions
[
k
]
=
value
.
ref
.
version
}
}
console
.
log
(
'
texture version changed, uploading image
'
,
k
)
textures
[
k
].
load
(
value
.
ref
.
value
)
})
})
},
},
destroy
:
()
=>
{
destroy
:
()
=>
{
if
(
destroyed
)
return
if
(
!
destroyed
)
{
programRef
.
free
()
programRef
.
free
()
Object
.
keys
(
textures
).
forEach
(
k
=>
textures
[
k
].
destroy
())
Object
.
keys
(
textures
).
forEach
(
k
=>
textures
[
k
].
destroy
())
Object
.
keys
(
attributeBuffers
).
forEach
(
k
=>
attributeBuffers
[
k
].
destroy
())
Object
.
keys
(
attributeBuffers
).
forEach
(
k
=>
attributeBuffers
[
k
].
destroy
())
if
(
elementsBuffer
)
elementsBuffer
.
destroy
()
if
(
elementsBuffer
)
elementsBuffer
.
destroy
()
deleteVertexArray
(
ctx
,
vertexArray
)
deleteVertexArray
(
ctx
,
vertexArray
)
destroyed
=
true
destroyed
=
true
}
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-gl/webgl/vertex-array.ts
0 → 100644
+
31
−
0
View file @
99d2b1d4
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import
{
Context
}
from
'
./context
'
;
import
{
Program
}
from
'
./program
'
;
import
{
AttributeBuffers
,
ElementsBuffer
}
from
'
./buffer
'
;
export
function
createVertexArray
(
ctx
:
Context
,
program
:
Program
,
attributeBuffers
:
AttributeBuffers
,
elementsBuffer
?:
ElementsBuffer
)
{
const
{
oesVertexArrayObject
}
=
ctx
.
extensions
let
vertexArray
:
WebGLVertexArrayObjectOES
|
undefined
=
undefined
if
(
oesVertexArrayObject
)
{
vertexArray
=
oesVertexArrayObject
.
createVertexArrayOES
()
oesVertexArrayObject
.
bindVertexArrayOES
(
vertexArray
)
program
.
bindAttributes
(
attributeBuffers
)
if
(
elementsBuffer
)
elementsBuffer
.
bind
()
ctx
.
vaoCount
+=
1
oesVertexArrayObject
.
bindVertexArrayOES
(
null
!
)
}
return
vertexArray
}
export
function
deleteVertexArray
(
ctx
:
Context
,
vertexArray
?:
WebGLVertexArrayObjectOES
)
{
const
{
oesVertexArrayObject
}
=
ctx
.
extensions
if
(
oesVertexArrayObject
&&
vertexArray
)
{
oesVertexArrayObject
.
deleteVertexArrayOES
(
vertexArray
)
ctx
.
vaoCount
-=
1
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment