@@ -6,6 +6,7 @@ import { EventHandler } from '../core/event-handler.js';
6
6
import { math } from '../math/math.js' ;
7
7
import { Color } from '../math/color.js' ;
8
8
import { Vec3 } from '../math/vec3.js' ;
9
+ import { Mat4 } from '../math/mat4.js' ;
9
10
10
11
import { http } from '../net/http.js' ;
11
12
@@ -14,17 +15,12 @@ import {
14
15
CLEARFLAG_COLOR , CLEARFLAG_DEPTH ,
15
16
FILTER_NEAREST ,
16
17
PIXELFORMAT_DEPTHSTENCIL , PIXELFORMAT_R8_G8_B8_A8 ,
17
- PRIMITIVE_TRIANGLES , PRIMITIVE_TRIFAN , PRIMITIVE_TRISTRIP ,
18
- SEMANTIC_POSITION ,
19
- TYPE_FLOAT32
18
+ PRIMITIVE_TRIANGLES , PRIMITIVE_TRIFAN , PRIMITIVE_TRISTRIP
20
19
} from '../graphics/constants.js' ;
21
20
import { destroyPostEffectQuad } from '../graphics/simple-post-effect.js' ;
22
21
import { GraphicsDevice } from '../graphics/graphics-device.js' ;
23
22
import { RenderTarget } from '../graphics/render-target.js' ;
24
23
import { Texture } from '../graphics/texture.js' ;
25
- import { VertexBuffer } from '../graphics/vertex-buffer.js' ;
26
- import { VertexFormat } from '../graphics/vertex-format.js' ;
27
- import { VertexIterator } from '../graphics/vertex-iterator.js' ;
28
24
29
25
import {
30
26
LAYERID_DEPTH , LAYERID_IMMEDIATE , LAYERID_SKYBOX , LAYERID_UI , LAYERID_WORLD ,
@@ -34,13 +30,10 @@ import {
34
30
} from '../scene/constants.js' ;
35
31
import { BatchManager } from '../scene/batching/batch-manager.js' ;
36
32
import { ForwardRenderer } from '../scene/forward-renderer.js' ;
37
- import { GraphNode } from '../scene/graph-node.js' ;
38
- import { ImmediateData , LineBatch } from '../scene/immediate.js' ;
33
+ import { ImmediateData } from '../scene/immediate.js' ;
39
34
import { Layer } from '../scene/layer.js' ;
40
35
import { LayerComposition } from '../scene/layer-composition.js' ;
41
36
import { Lightmapper } from '../scene/lightmapper.js' ;
42
- import { Mesh } from '../scene/mesh.js' ;
43
- import { MeshInstance } from '../scene/mesh-instance.js' ;
44
37
import { ParticleEmitter } from '../scene/particle-system/particle-emitter.js' ;
45
38
import { Scene } from '../scene/scene.js' ;
46
39
@@ -143,7 +136,6 @@ class Progress {
143
136
}
144
137
145
138
var _deprecationWarning = false ;
146
- var tempGraphNode = new GraphNode ( ) ;
147
139
148
140
/**
149
141
* @class
@@ -809,8 +801,6 @@ class Application extends EventHandler {
809
801
}
810
802
}
811
803
812
- this . meshInstanceArray = [ ] ;
813
-
814
804
// bind tick function to current scope
815
805
816
806
/* eslint-disable-next-line no-use-before-define */
@@ -1813,19 +1803,11 @@ class Application extends EventHandler {
1813
1803
1814
1804
// IMMEDIATE MODE API
1815
1805
_preRenderImmediate ( ) {
1816
- for ( var i = 0 ; i < this . _immediateData . lineBatches . length ; i ++ ) {
1817
- if ( this . _immediateData . lineBatches [ i ] ) {
1818
- this . _immediateData . lineBatches [ i ] . finalize ( this . meshInstanceArray ) ;
1819
- }
1820
- }
1806
+ this . _immediateData . finalize ( ) ;
1821
1807
}
1822
1808
1823
1809
_postRenderImmediate ( ) {
1824
- for ( var i = 0 ; i < this . _immediateData . layers . length ; i ++ ) {
1825
- this . _immediateData . layers [ i ] . clearMeshInstances ( true ) ;
1826
- }
1827
-
1828
- this . _immediateData . layers . length = 0 ;
1810
+ this . _immediateData . clear ( ) ;
1829
1811
}
1830
1812
1831
1813
_initImmediate ( ) {
@@ -1844,27 +1826,10 @@ class Application extends EventHandler {
1844
1826
var mask = ( options && options . mask ) ? options . mask : undefined ;
1845
1827
1846
1828
this . _initImmediate ( ) ;
1829
+ let lineBatch = this . _immediateData . prepareLineBatch ( layer , depthTest , mask , position . length / 2 ) ;
1847
1830
1848
- this . _immediateData . addLayer ( layer ) ;
1849
-
1850
- var idx = this . _immediateData . getLayerIdx ( layer ) ;
1851
- if ( idx === undefined ) {
1852
- // Init used batch once
1853
- var batch = new LineBatch ( ) ;
1854
- batch . init ( this . graphicsDevice , this . _immediateData . lineVertexFormat , layer , position . length / 2 ) ;
1855
- batch . material . depthTest = depthTest ;
1856
- if ( mask ) batch . meshInstance . mask = mask ;
1857
-
1858
- idx = this . _immediateData . lineBatches . push ( batch ) - 1 ; // push into list and get index
1859
- this . _immediateData . addLayerIdx ( idx , layer ) ;
1860
- } else {
1861
- // Possibly reallocate buffer if it's small
1862
- this . _immediateData . lineBatches [ idx ] . init ( this . graphicsDevice , this . _immediateData . lineVertexFormat , layer , position . length / 2 ) ;
1863
- this . _immediateData . lineBatches [ idx ] . material . depthTest = depthTest ;
1864
- if ( mask ) this . _immediateData . lineBatches [ idx ] . meshInstance . mask = mask ;
1865
- }
1866
1831
// Append
1867
- this . _immediateData . lineBatches [ idx ] . addLines ( position , color ) ;
1832
+ lineBatch . addLines ( position , color ) ;
1868
1833
}
1869
1834
1870
1835
/**
@@ -2094,88 +2059,45 @@ class Application extends EventHandler {
2094
2059
] , color , options ) ;
2095
2060
}
2096
2061
2097
- // Draw meshInstance at this frame
2098
- renderMeshInstance ( meshInstance , options ) {
2099
- if ( ! options ) {
2100
- options = {
2101
- layer : this . scene . layers . getLayerById ( LAYERID_IMMEDIATE )
2102
- } ;
2103
- }
2062
+ _getDefaultImmediateOptions ( ) {
2063
+ return {
2064
+ layer : this . scene . layers . getLayerById ( LAYERID_IMMEDIATE )
2065
+ } ;
2066
+ }
2104
2067
2068
+ // Draw meshInstance at this frame
2069
+ renderMeshInstance ( meshInstance , options = this . _getDefaultImmediateOptions ( ) ) {
2105
2070
this . _initImmediate ( ) ;
2106
-
2107
- this . _immediateData . addLayer ( options . layer ) ;
2108
-
2109
- this . meshInstanceArray [ 0 ] = meshInstance ;
2110
- options . layer . addMeshInstances ( this . meshInstanceArray , true ) ;
2071
+ this . _immediateData . renderMesh ( null , null , null , meshInstance , options ) ;
2111
2072
}
2112
2073
2113
2074
// Draw mesh at this frame
2114
- renderMesh ( mesh , material , matrix , options ) {
2115
- if ( ! options ) {
2116
- options = {
2117
- layer : this . scene . layers . getLayerById ( LAYERID_IMMEDIATE )
2118
- } ;
2119
- }
2120
-
2075
+ renderMesh ( mesh , material , matrix , options = this . _getDefaultImmediateOptions ( ) ) {
2121
2076
this . _initImmediate ( ) ;
2122
- tempGraphNode . worldTransform = matrix ;
2123
- tempGraphNode . _dirtyWorld = tempGraphNode . _dirtyNormal = false ;
2124
-
2125
- var instance = new MeshInstance ( mesh , material , tempGraphNode ) ;
2126
- instance . cull = false ;
2127
-
2128
- if ( options . mask ) instance . mask = options . mask ;
2129
- this . _immediateData . addLayer ( options . layer ) ;
2130
-
2131
- this . meshInstanceArray [ 0 ] = instance ;
2132
- options . layer . addMeshInstances ( this . meshInstanceArray , true ) ;
2077
+ this . _immediateData . renderMesh ( material , matrix , mesh , null , options ) ;
2133
2078
}
2134
2079
2135
2080
// Draw quad of size [-0.5, 0.5] at this frame
2136
- renderQuad ( matrix , material , options ) {
2137
- if ( ! options ) {
2138
- options = {
2139
- layer : this . scene . layers . getLayerById ( LAYERID_IMMEDIATE )
2140
- } ;
2141
- }
2142
-
2081
+ renderQuad ( matrix , material , options = this . _getDefaultImmediateOptions ( ) ) {
2143
2082
this . _initImmediate ( ) ;
2083
+ this . _immediateData . renderMesh ( material , matrix , this . _immediateData . getQuadMesh ( ) , null , options ) ;
2084
+ }
2144
2085
2145
- // Init quad data once
2146
- if ( ! this . _immediateData . quadMesh ) {
2147
- var format = new VertexFormat ( this . graphicsDevice , [
2148
- { semantic : SEMANTIC_POSITION , components : 3 , type : TYPE_FLOAT32 }
2149
- ] ) ;
2150
- var quadVb = new VertexBuffer ( this . graphicsDevice , format , 4 ) ;
2151
- var iterator = new VertexIterator ( quadVb ) ;
2152
- iterator . element [ SEMANTIC_POSITION ] . set ( - 0.5 , - 0.5 , 0 ) ;
2153
- iterator . next ( ) ;
2154
- iterator . element [ SEMANTIC_POSITION ] . set ( 0.5 , - 0.5 , 0 ) ;
2155
- iterator . next ( ) ;
2156
- iterator . element [ SEMANTIC_POSITION ] . set ( - 0.5 , 0.5 , 0 ) ;
2157
- iterator . next ( ) ;
2158
- iterator . element [ SEMANTIC_POSITION ] . set ( 0.5 , 0.5 , 0 ) ;
2159
- iterator . end ( ) ;
2160
- this . _immediateData . quadMesh = new Mesh ( this . graphicsDevice ) ;
2161
- this . _immediateData . quadMesh . vertexBuffer = quadVb ;
2162
- this . _immediateData . quadMesh . primitive [ 0 ] . type = PRIMITIVE_TRISTRIP ;
2163
- this . _immediateData . quadMesh . primitive [ 0 ] . base = 0 ;
2164
- this . _immediateData . quadMesh . primitive [ 0 ] . count = 4 ;
2165
- this . _immediateData . quadMesh . primitive [ 0 ] . indexed = false ;
2166
- }
2167
-
2168
- // Issue quad drawcall
2169
- tempGraphNode . worldTransform = matrix ;
2170
- tempGraphNode . _dirtyWorld = tempGraphNode . _dirtyNormal = false ;
2086
+ // draws a texture on [x,y] position on screen, with size [width, height].
2087
+ // Coordinates / sizes are in projected space (-1 .. 1)
2088
+ renderTexture ( x , y , width , height , texture , options ) {
2089
+ this . _initImmediate ( ) ;
2171
2090
2172
- var quad = new MeshInstance ( this . _immediateData . quadMesh , material , tempGraphNode ) ;
2173
- quad . cull = false ;
2174
- this . meshInstanceArray [ 0 ] = quad ;
2091
+ // TODO: if this is used for anything other than debug texture display, we should optimize this to avoid allocations
2092
+ let matrix = new Mat4 ( ) ;
2093
+ matrix . setTRS ( new Vec3 ( x , y , 0.0 ) , pc . Quat . IDENTITY , new Vec3 ( width , height , 0.0 ) ) ;
2175
2094
2176
- this . _immediateData . addLayer ( options . layer ) ;
2095
+ let material = new pc . Material ( ) ;
2096
+ material . setParameter ( "colorMap" , texture ) ;
2097
+ material . shader = this . _immediateData . getTextureShader ( ) ;
2098
+ material . update ( ) ;
2177
2099
2178
- options . layer . addMeshInstances ( this . meshInstanceArray , true ) ;
2100
+ this . renderQuad ( matrix , material , options ) ;
2179
2101
}
2180
2102
2181
2103
/**
0 commit comments