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
126ef26a
Commit
126ef26a
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
fragDepth ext support, better ext availablitity handling
parent
54f9cd2a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-gl/shader-code.ts
+41
-14
41 additions, 14 deletions
src/mol-gl/shader-code.ts
src/mol-gl/webgl/compat.ts
+7
-0
7 additions, 0 deletions
src/mol-gl/webgl/compat.ts
src/mol-gl/webgl/context.ts
+13
-2
13 additions, 2 deletions
src/mol-gl/webgl/context.ts
with
61 additions
and
16 deletions
src/mol-gl/shader-code.ts
+
41
−
14
View file @
126ef26a
...
@@ -14,39 +14,50 @@ export type DefineValues = { [k: string]: ValueCell<DefineType> }
...
@@ -14,39 +14,50 @@ export type DefineValues = { [k: string]: ValueCell<DefineType> }
const
shaderCodeId
=
idFactory
()
const
shaderCodeId
=
idFactory
()
export
interface
ShaderExtensions
{
readonly
standardDerivatives
:
boolean
readonly
fragDepth
:
boolean
}
export
interface
ShaderCode
{
export
interface
ShaderCode
{
id
:
number
readonly
id
:
number
vert
:
string
readonly
vert
:
string
frag
:
string
readonly
frag
:
string
readonly
extensions
:
ShaderExtensions
}
}
export
function
ShaderCode
(
vert
:
string
,
frag
:
string
):
ShaderCode
{
export
function
ShaderCode
(
vert
:
string
,
frag
:
string
,
extensions
:
ShaderExtensions
):
ShaderCode
{
return
{
id
:
shaderCodeId
(),
vert
,
frag
}
return
{
id
:
shaderCodeId
(),
vert
,
frag
,
extensions
}
}
}
export
const
PointsShaderCode
=
ShaderCode
(
export
const
PointsShaderCode
=
ShaderCode
(
require
(
'
mol-gl/shader/points.vert
'
),
require
(
'
mol-gl/shader/points.vert
'
),
require
(
'
mol-gl/shader/points.frag
'
)
require
(
'
mol-gl/shader/points.frag
'
),
{
standardDerivatives
:
false
,
fragDepth
:
false
}
)
)
export
const
LinesShaderCode
=
ShaderCode
(
export
const
LinesShaderCode
=
ShaderCode
(
require
(
'
mol-gl/shader/lines.vert
'
),
require
(
'
mol-gl/shader/lines.vert
'
),
require
(
'
mol-gl/shader/lines.frag
'
)
require
(
'
mol-gl/shader/lines.frag
'
),
{
standardDerivatives
:
false
,
fragDepth
:
false
}
)
)
export
const
MeshShaderCode
=
ShaderCode
(
export
const
MeshShaderCode
=
ShaderCode
(
require
(
'
mol-gl/shader/mesh.vert
'
),
require
(
'
mol-gl/shader/mesh.vert
'
),
require
(
'
mol-gl/shader/mesh.frag
'
)
require
(
'
mol-gl/shader/mesh.frag
'
),
{
standardDerivatives
:
true
,
fragDepth
:
false
}
)
)
export
const
GaussianDensityShaderCode
=
ShaderCode
(
export
const
GaussianDensityShaderCode
=
ShaderCode
(
require
(
'
mol-gl/shader/gaussian-density.vert
'
),
require
(
'
mol-gl/shader/gaussian-density.vert
'
),
require
(
'
mol-gl/shader/gaussian-density.frag
'
)
require
(
'
mol-gl/shader/gaussian-density.frag
'
),
{
standardDerivatives
:
false
,
fragDepth
:
false
}
)
)
export
const
DirectVolumeShaderCode
=
ShaderCode
(
export
const
DirectVolumeShaderCode
=
ShaderCode
(
require
(
'
mol-gl/shader/direct-volume.vert
'
),
require
(
'
mol-gl/shader/direct-volume.vert
'
),
require
(
'
mol-gl/shader/direct-volume.frag
'
)
require
(
'
mol-gl/shader/direct-volume.frag
'
),
{
standardDerivatives
:
false
,
fragDepth
:
true
}
)
)
export
type
ShaderDefines
=
{
export
type
ShaderDefines
=
{
...
@@ -74,8 +85,20 @@ function getDefinesCode (defines: ShaderDefines) {
...
@@ -74,8 +85,20 @@ function getDefinesCode (defines: ShaderDefines) {
return
lines
.
join
(
'
\n
'
)
+
'
\n
'
return
lines
.
join
(
'
\n
'
)
+
'
\n
'
}
}
const
glsl100FragPrefix
=
`#extension GL_OES_standard_derivatives : enable
function
getGlsl100FragPrefix
(
ctx
:
Context
,
extensions
:
ShaderExtensions
)
{
`
const
prefix
:
string
[]
=
[]
if
(
extensions
.
standardDerivatives
)
{
prefix
.
push
(
'
#extension GL_OES_standard_derivatives : enable
'
)
prefix
.
push
(
'
#define enabledStandardDerivatives
'
)
}
if
(
extensions
.
fragDepth
)
{
if
(
ctx
.
extensions
.
fragDepth
)
{
prefix
.
push
(
'
#extension GL_EXT_frag_depth : enable
'
)
prefix
.
push
(
'
#define enabledFragDepth
'
)
}
}
return
prefix
.
join
(
'
\n
'
)
+
'
\n
'
}
const
glsl300VertPrefix
=
`#version 300 es
const
glsl300VertPrefix
=
`#version 300 es
#define attribute in
#define attribute in
...
@@ -89,16 +112,20 @@ layout(location = 0) out highp vec4 out_FragColor;
...
@@ -89,16 +112,20 @@ layout(location = 0) out highp vec4 out_FragColor;
#define gl_FragColor out_FragColor
#define gl_FragColor out_FragColor
#define gl_FragDepthEXT gl_FragDepth
#define gl_FragDepthEXT gl_FragDepth
#define texture2D texture
#define texture2D texture
#define enabledStandardDerivatives
#define enabledFragDepth
`
`
export
function
addShaderDefines
(
ctx
:
Context
,
defines
:
ShaderDefines
,
shaders
:
ShaderCode
):
ShaderCode
{
export
function
addShaderDefines
(
ctx
:
Context
,
defines
:
ShaderDefines
,
shaders
:
ShaderCode
):
ShaderCode
{
const
{
isWebGL2
}
=
ctx
const
{
isWebGL2
}
=
ctx
const
header
=
getDefinesCode
(
defines
)
const
header
=
getDefinesCode
(
defines
)
const
vertPrefix
=
isWebGL2
?
glsl300VertPrefix
:
''
const
vertPrefix
=
isWebGL2
?
glsl300VertPrefix
:
''
const
fragPrefix
=
isWebGL2
?
glsl300FragPrefix
:
glsl100FragPrefix
const
fragPrefix
=
isWebGL2
?
glsl300FragPrefix
:
g
etG
lsl100FragPrefix
(
ctx
,
shaders
.
extensions
)
return
{
return
{
id
:
shaderCodeId
(),
id
:
shaderCodeId
(),
vert
:
`
${
vertPrefix
}${
header
}${
shaders
.
vert
}
`
,
vert
:
`
${
vertPrefix
}${
header
}${
shaders
.
vert
}
`
,
frag
:
`
${
fragPrefix
}${
header
}${
shaders
.
frag
}
`
frag
:
`
${
fragPrefix
}${
header
}${
shaders
.
frag
}
`
,
extensions
:
shaders
.
extensions
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-gl/webgl/compat.ts
+
7
−
0
View file @
126ef26a
...
@@ -121,4 +121,11 @@ export function getBlendMinMax(gl: GLRenderingContext): COMPAT_blend_minmax | nu
...
@@ -121,4 +121,11 @@ export function getBlendMinMax(gl: GLRenderingContext): COMPAT_blend_minmax | nu
if
(
ext
===
null
)
return
null
if
(
ext
===
null
)
return
null
return
{
MIN
:
ext
.
MIN_EXT
,
MAX
:
ext
.
MAX_EXT
}
return
{
MIN
:
ext
.
MIN_EXT
,
MAX
:
ext
.
MAX_EXT
}
}
}
}
export
interface
COMPAT_frag_depth
{
}
export
function
getFragDepth
(
gl
:
GLRenderingContext
):
COMPAT_frag_depth
|
null
{
return
isWebGL2
(
gl
)
?
{}
:
gl
.
getExtension
(
'
EXT_frag_depth
'
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-gl/webgl/context.ts
+
13
−
2
View file @
126ef26a
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import
{
createProgramCache
,
ProgramCache
}
from
'
./program
'
import
{
createProgramCache
,
ProgramCache
}
from
'
./program
'
import
{
createShaderCache
,
ShaderCache
}
from
'
./shader
'
import
{
createShaderCache
,
ShaderCache
}
from
'
./shader
'
import
{
GLRenderingContext
,
COMPAT_instanced_arrays
,
COMPAT_standard_derivatives
,
COMPAT_vertex_array_object
,
getInstancedArrays
,
getStandardDerivatives
,
getVertexArrayObject
,
isWebGL2
,
COMPAT_element_index_uint
,
getElementIndexUint
,
COMPAT_texture_float
,
getTextureFloat
,
COMPAT_texture_float_linear
,
getTextureFloatLinear
,
COMPAT_blend_minmax
,
getBlendMinMax
}
from
'
./compat
'
;
import
{
GLRenderingContext
,
COMPAT_instanced_arrays
,
COMPAT_standard_derivatives
,
COMPAT_vertex_array_object
,
getInstancedArrays
,
getStandardDerivatives
,
getVertexArrayObject
,
isWebGL2
,
COMPAT_element_index_uint
,
getElementIndexUint
,
COMPAT_texture_float
,
getTextureFloat
,
COMPAT_texture_float_linear
,
getTextureFloatLinear
,
COMPAT_blend_minmax
,
getBlendMinMax
,
getFragDepth
,
COMPAT_frag_depth
}
from
'
./compat
'
;
export
function
getGLContext
(
canvas
:
HTMLCanvasElement
,
contextAttributes
?:
WebGLContextAttributes
):
GLRenderingContext
|
null
{
export
function
getGLContext
(
canvas
:
HTMLCanvasElement
,
contextAttributes
?:
WebGLContextAttributes
):
GLRenderingContext
|
null
{
function
getContext
(
contextId
:
'
webgl
'
|
'
experimental-webgl
'
|
'
webgl2
'
)
{
function
getContext
(
contextId
:
'
webgl
'
|
'
experimental-webgl
'
|
'
webgl2
'
)
{
...
@@ -105,6 +105,7 @@ type Extensions = {
...
@@ -105,6 +105,7 @@ type Extensions = {
textureFloatLinear
:
COMPAT_texture_float_linear
textureFloatLinear
:
COMPAT_texture_float_linear
elementIndexUint
:
COMPAT_element_index_uint
|
null
elementIndexUint
:
COMPAT_element_index_uint
|
null
vertexArrayObject
:
COMPAT_vertex_array_object
|
null
vertexArrayObject
:
COMPAT_vertex_array_object
|
null
fragDepth
:
COMPAT_frag_depth
|
null
}
}
/** A WebGL context object, including the rendering context, resource caches and counts */
/** A WebGL context object, including the rendering context, resource caches and counts */
...
@@ -165,6 +166,10 @@ export function createContext(gl: GLRenderingContext): Context {
...
@@ -165,6 +166,10 @@ export function createContext(gl: GLRenderingContext): Context {
if
(
vertexArrayObject
===
null
)
{
if
(
vertexArrayObject
===
null
)
{
console
.
log
(
'
Could not find support for "vertex_array_object"
'
)
console
.
log
(
'
Could not find support for "vertex_array_object"
'
)
}
}
const
fragDepth
=
getFragDepth
(
gl
)
if
(
fragDepth
===
null
)
{
console
.
log
(
'
Could not find support for "frag_depth"
'
)
}
const
shaderCache
=
createShaderCache
()
const
shaderCache
=
createShaderCache
()
const
programCache
=
createProgramCache
()
const
programCache
=
createProgramCache
()
...
@@ -172,6 +177,11 @@ export function createContext(gl: GLRenderingContext): Context {
...
@@ -172,6 +177,11 @@ export function createContext(gl: GLRenderingContext): Context {
const
parameters
=
{
const
parameters
=
{
maxTextureSize
:
gl
.
getParameter
(
gl
.
MAX_TEXTURE_SIZE
),
maxTextureSize
:
gl
.
getParameter
(
gl
.
MAX_TEXTURE_SIZE
),
maxDrawBuffers
:
isWebGL2
(
gl
)
?
gl
.
getParameter
(
gl
.
MAX_DRAW_BUFFERS
)
:
0
,
maxDrawBuffers
:
isWebGL2
(
gl
)
?
gl
.
getParameter
(
gl
.
MAX_DRAW_BUFFERS
)
:
0
,
maxVertexTextureImageUnits
:
gl
.
getParameter
(
gl
.
MAX_VERTEX_TEXTURE_IMAGE_UNITS
),
}
if
(
parameters
.
maxVertexTextureImageUnits
<
4
)
{
throw
new
Error
(
'
Need "MAX_VERTEX_TEXTURE_IMAGE_UNITS" >= 4
'
)
}
}
return
{
return
{
...
@@ -184,7 +194,8 @@ export function createContext(gl: GLRenderingContext): Context {
...
@@ -184,7 +194,8 @@ export function createContext(gl: GLRenderingContext): Context {
textureFloat
,
textureFloat
,
textureFloatLinear
,
textureFloatLinear
,
elementIndexUint
,
elementIndexUint
,
vertexArrayObject
vertexArrayObject
,
fragDepth
},
},
pixelRatio
:
getPixelRatio
(),
pixelRatio
:
getPixelRatio
(),
...
...
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