Project

General

Profile

« Previous | Next » 

Revision a5a3b341

Added by Leszek Koltunski 23 days ago

transition of the mesh package.
Compiles, but does not work.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.kt
76 76
            var mainVertHeader = version + ("#define NUM_VERTEX " + (if (numV>0) DistortedLibrary.getMax(EffectType.VERTEX) else 0) + "\n")
77 77
            val mainFragHeader = version + "\n"
78 78

  
79
            mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n"
80
            if (MeshBase.getUseCenters()) mainVertHeader += "#define COMP_CENTERS\n"
79
            mainVertHeader += "#define MAX_COMPON " + MeshBase.maxEffComponents + "\n"
80
            if (MeshBase.useCenters) mainVertHeader += "#define COMP_CENTERS\n"
81 81
            if (DistortedLibrary.isUBOBuggy()) mainVertHeader += "#define BUGGY_UBOS\n"
82 82
            mainVertHeader += "#define POSTPROCESS\n"
83 83

  
......
172 172

  
173 173
        mPreProgram!!.useProgram()
174 174

  
175
        mesh.bindVertexAttribs(mPreProgram)
175
        mesh.bindVertexAttribs(mPreProgram as DistortedProgram)
176 176
        mesh.send(mPreProgramH, 2)
177 177

  
178 178
        val queues = effects.queues
......
188 188
            GLES30.glUniform1i(mPreTextureH, 0)
189 189
        }
190 190

  
191
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.numVertices)
191
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() )
192 192
        mPreProgram!!.stopUsingProgram()
193 193

  
194 194
        InternalRenderState.restoreBlending()
src/main/java/org/distorted/library/main/DistortedLibrary.java
536 536
///////////////////////////////////////////////////////////////////////////////////////////////////
537 537
/**
538 538
 * Execute all VertexEffects and adjust all vertices
539
 *
540
 * @y.exclude
541 539
 */
542 540
  public static void adjustVertices(MeshBase mesh, EffectQueueVertex queue)
543 541
    {
......
980 978
    }
981 979

  
982 980
///////////////////////////////////////////////////////////////////////////////////////////////////
983
/**
984
 * Not an external API
985
 *
986
 * @y.exclude
987
 */
988

  
989 981
  public static void logMessage(String message)
990 982
    {
991 983
    mUser.logMessage(message);
src/main/java/org/distorted/library/mesh/DeferredJobs.kt
153 153
    }
154 154

  
155 155
    ///////////////////////////////////////////////////////////////////////////////////////////////////
156
    fun <T:MeshBase> join(target: T, meshes: Array<T>): JobNode
156
    fun <T:MeshBase> join(target: T, meshes: Array<MeshBase>): JobNode
157 157
    {
158 158
        var jn: JobNode?
159

  
160 159
        val job = Job(JOB_TYPE_JOIN, target, meshes, null, null, null, 0, 0, 0, 0f, 0f, 0f, null)
161 160
        val node = JobNode(job)
162 161

  
......
176 175
    }
177 176

  
178 177
    ///////////////////////////////////////////////////////////////////////////////////////////////////
179
    fun <T:MeshBase> copy(target: T, mesh: T): JobNode
178
    fun <T:MeshBase> copy(target: T, mesh: MeshBase): JobNode
180 179
    {
181 180
        val jn = mesh.mJobNode[0]
182 181
        val meshes = arrayOf(mesh)
src/main/java/org/distorted/library/mesh/MeshBase.kt
61 61

  
62 62
    var mJobNode: Array<DeferredJobs.JobNode?>
63 63

  
64
    companion object
65
    {
66
        private const val ASSOC_UBO_BINDING = 3
67
        private const val CENTER_UBO_BINDING = 4
68

  
69
        // sizes of attributes of an individual vertex.
70
        private const val POS_DATA_SIZE = 3 // vertex coordinates: x,y,z
71
        private const val NOR_DATA_SIZE = 3 // normal vector: x,y,z
72
        private const val TEX_DATA_SIZE = 2 // texture coordinates: s,t
73
        private const val COM_DATA_SIZE = 1 // component number, a single float
74

  
75
        const val POS_ATTRIB: Int = 0
76
        const val NOR_ATTRIB: Int = POS_DATA_SIZE
77
        const val TEX_ATTRIB: Int = 0
78
        const val COM_ATTRIB: Int = TEX_DATA_SIZE
79

  
80
        const val VERT1_ATTRIBS: Int = POS_DATA_SIZE+NOR_DATA_SIZE // number of attributes of a vertex (the part changed by preapply)
81
        const val VERT2_ATTRIBS: Int = TEX_DATA_SIZE+COM_DATA_SIZE // number of attributes of a vertex (the 'preapply invariant' part)
82
        const val TRAN_ATTRIBS: Int = POS_DATA_SIZE+NOR_DATA_SIZE // number of attributes of a transform feedback vertex
83

  
84
        private const val BYTES_PER_FLOAT = 4
85

  
86
        private const val OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT
87
        private const val OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT
88
        private const val OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT
89
        private const val OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT
90

  
91
        private const val TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT
92
        private const val VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT
93
        private const val VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT
94

  
95
        private val mCenterBlockIndex = IntArray(EffectQueue.MAIN_VARIANTS)
96
        private val mAssocBlockIndex = IntArray(EffectQueue.MAIN_VARIANTS)
97

  
98
        private const val TEX_COMP_SIZE = 5 // 5 four-byte entities inside the component
99
        private var mStride = 0
100

  
101
        /**
102
         * How many mesh components are we going to need? Call before compilation of the shaders.
103
         */
104
        @JvmStatic
105
        var maxEffComponents: Int = 100
106

  
107
        ///////////////////////////////////////////////////////////////////////////////////////////////////
108
        /**
109
         * Are we going to need per-component centers (needed for correct postprocessing of concave meshes)
110
         * Switching this on allocates 16*MAX_EFFECT_COMPONENTS bytes for uniforms in the vertex shader.
111
         */
112
        @JvmStatic
113
        var useCenters: Boolean = false
114

  
115
        ///////////////////////////////////////////////////////////////////////////////////////////////////
116
        @JvmStatic
117
        fun getUniforms(programH: Int, variant: Int)
118
        {
119
            mCenterBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentCenter")
120
            mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation")
121

  
122
            if (mStride==0)
123
            {
124
                val uniformNames = arrayOf("vComAssoc")
125
                val indices = IntArray(1)
126
                val params = IntArray(1)
127

  
128
                GLES30.glGetUniformIndices(programH, uniformNames, indices, 0)
129
                GLES30.glGetActiveUniformsiv(programH, 1, indices, 0, GLES30.GL_UNIFORM_ARRAY_STRIDE, params, 0)
130

  
131
                mStride = params[0]/4
132
            }
133
        }
134
    }
135

  
64 136
    private class TexComponent
65 137
    {
66 138
        var mEndIndex: Int
......
322 394
        var mesh: MeshBase
323 395
        var comp: TexComponent
324 396
        val numMeshes = meshes.size
325
        var numVertices: Int
326 397
        var origVertices = this.numVertices
327 398
        val origTexComponents: Int
328 399
        var numTexComponents: Int
......
507 578
        }
508 579

  
509 580
        if (immediateJoin) joinAttribs(meshes)
510
        else mJobNode[0] = DeferredJobs.join(this, meshes)
581
        else mJobNode[0] = DeferredJobs.join(this, meshes as Array<MeshBase>)
511 582
    }
512 583

  
513 584
    ///////////////////////////////////////////////////////////////////////////////////////////////////
......
749 820
    }
750 821

  
751 822
    ///////////////////////////////////////////////////////////////////////////////////////////////////
752
    val tFO: Int
753
        /**
754
         * Not part of public API, do not document (public only because has to be used from the main package)
755
         *
756
         * @y.exclude
757
         */
758
        get()
759
        = mTFO.createImmediatelyFloat(numVertices*TRAN_SIZE, null)
760

  
761
    ///////////////////////////////////////////////////////////////////////////////////////////////////
823
    val tFO: Int get() = mTFO.createImmediatelyFloat(numVertices*TRAN_SIZE, null)
762 824

  
763 825
    ///////////////////////////////////////////////////////////////////////////////////////////////////
764
    /**
765
     * Not part of public API, do not document (public only because has to be used from the main package)
766
     *
767
     * @y.exclude
768
     */
769 826
    fun send(programH: Int, variant: Int)
770 827
    {
771 828
        if (!mStrideCorrected)
......
787 844
    }
788 845

  
789 846
    ///////////////////////////////////////////////////////////////////////////////////////////////////
790
    /**
791
     * Not part of public API, do not document (public only because has to be used from the main package)
792
     *
793
     * @y.exclude
794
     */
795 847
    fun bindVertexAttribs(program: DistortedProgram)
796 848
    {
797 849
        if (mJobNode[0]!=null) mJobNode[0]!!.execute() // this will set itself to null
......
854 906
    }
855 907

  
856 908
    ///////////////////////////////////////////////////////////////////////////////////////////////////
857
    /**
858
     * Not part of public API, do not document (public only because has to be used from the main package)
859
     *
860
     * @y.exclude
861
     */
862 909
    fun bindTransformAttribs(program: DistortedProgram)
863 910
    {
864 911
        val index = mTFO.createImmediatelyFloat(numVertices*TRAN_SIZE, null)
......
868 915
        GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0)
869 916
    }
870 917

  
871
    ///////////////////////////////////////////////////////////////////////////////////////////////////
872

  
873
    ///////////////////////////////////////////////////////////////////////////////////////////////////
874

  
875 918
    ///////////////////////////////////////////////////////////////////////////////////////////////////
876 919
    // Return the number of bytes read.
877 920
    fun read(stream: DataInputStream): Int
......
1027 1070
    }
1028 1071

  
1029 1072
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1030
    /**
1031
     * @y.exclude
1032
     */
1033 1073
    fun getLastVertexEff(effComponent: Int): Int
1034 1074
    {
1035 1075
        if (effComponent>=0&&effComponent<mTexComponent!!.size)
......
1041 1081
    }
1042 1082

  
1043 1083
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1044
    /**
1045
     * @y.exclude
1046
     */
1047 1084
    fun getLastVertexTex(texComponent: Int): Int
1048 1085
    {
1049 1086
        if (texComponent>=0&&texComponent<mTexComponent!!.size)
......
1113 1150
        }
1114 1151
    }
1115 1152

  
1116
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1117

  
1118
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1119

  
1120 1153
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1121 1154
    /**
1122 1155
     * Merge all texture components of this Mesh into a single one.
......
1148 1181
            mJobNode[0] = DeferredJobs.mergeEff(this)
1149 1182
        }
1150 1183
    }
1184
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1185
    /**
1186
     * Return the number of vertices in this Mesh.
1187
     */
1188
    fun getNumVertices() = numVertices
1151 1189

  
1152 1190
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1153 1191
    /**
......
1173 1211
    /**
1174 1212
     * Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
1175 1213
     *
1176
     *
1177 1214
     * This is a static, permanent modification of the vertices contained in this Mesh. If the effect
1178 1215
     * contains any Dynamics, they will be evaluated at 0.
1179 1216
     *
......
1197 1234
    /**
1198 1235
     * Apply a Vertex Effect to the vertex mesh.
1199 1236
     *
1200
     *
1201 1237
     * This is a static, permanent modification of the vertices contained in this Mesh. If the effects
1202 1238
     * contain any Dynamics, the Dynamics will be evaluated at 0.
1203 1239
     * We would call this several times building up a list of Effects to do. This list of effects gets
......
1214 1250
    /**
1215 1251
     * Sets texture maps for (some of) the components of this mesh.
1216 1252
     *
1217
     *
1218 1253
     * Format: ( x of lower-left corner, y of lower-left corner, width, height ).
1219 1254
     * For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
1220 1255
     * upper-left quadrant of the texture.
1221 1256
     *
1222
     *
1223 1257
     * Probably the most common user case would be sending as many maps as there are components in this
1224 1258
     * Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
1225 1259
     * to null (those will be ignored as well). So if there are 5 components, and we want to set the map
......
1268 1302
     * The point: this way we can configure the system so that each Vertex Effect acts only on a certain
1269 1303
     * subset of a Mesh, thus potentially significantly reducing the number of render calls.
1270 1304
     *
1271
     *
1272 1305
     * Only the bottom 31 bits of the 'andAssociation' are possible, the top one is taken by Postprocessing
1273 1306
     * Association [i.e. marking which components are disabled when we postprocess]
1274 1307
     */
1275 1308
    fun setEffectAssociation(component: Int, andAssociation: Int, equAssociation: Int)
1276 1309
    {
1277
        if (component>=0&&component<maxEffComponents)
1310
        if( component in 0..<maxEffComponents )
1278 1311
        {
1279 1312
            if (mJobNode[0]==null)
1280 1313
            {
......
1320 1353
     */
1321 1354
    fun setComponentCenter(component: Int, centerX: Float, centerY: Float, centerZ: Float)
1322 1355
    {
1323
        if (component>=0&&component<maxEffComponents)
1356
        if( component in 0..<maxEffComponents )
1324 1357
        {
1325 1358
            if (mJobNode[0]==null)
1326 1359
            {
......
1367 1400
    }
1368 1401

  
1369 1402
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1370
    val numTexComponents: Int
1371
        /**
1372
         * Return the number of texture components, i.e. individual subsets of the whole set of vertices
1373
         * which can be independently textured.
1374
         *
1375
         * @return The number of Texture Components of this Mesh.
1376
         */
1377
        get()
1378
        = mTexComponent!!.size
1403
    /**
1404
     * Return the number of texture components, i.e. individual subsets of the whole set of vertices
1405
     * which can be independently textured.
1406
     *
1407
     * @return The number of Texture Components of this Mesh.
1408
     */
1409
    val numTexComponents: Int get() = mTexComponent!!.size
1379 1410

  
1380 1411
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1381
    val numEffComponents: Int
1382
        /**
1383
         * Return the number of 'effect' components, i.e. individual subsets of the whole set of vertices
1384
         * to which a VertexEffect can be addressed, independently of other vertices.
1385
         *
1386
         * @return The number of Effect Components of this Mesh.
1387
         */
1388
        get()
1389
        = mEffComponent!!.size
1412
    /**
1413
     * Return the number of 'effect' components, i.e. individual subsets of the whole set of vertices
1414
     * to which a VertexEffect can be addressed, independently of other vertices.
1415
     *
1416
     * @return The number of Effect Components of this Mesh.
1417
     */
1418
    val numEffComponents: Int get() = mEffComponent!!.size
1390 1419

  
1391 1420
    ///////////////////////////////////////////////////////////////////////////////////////////////////
1392 1421
    /**
......
1397 1426
     * coordinates and effect associations, is always deep copied)
1398 1427
     */
1399 1428
    abstract fun copy(deep: Boolean): MeshBase
1400

  
1401
    companion object
1402
    {
1403
        private const val ASSOC_UBO_BINDING = 3
1404
        private const val CENTER_UBO_BINDING = 4
1405

  
1406
        // sizes of attributes of an individual vertex.
1407
        private const val POS_DATA_SIZE = 3 // vertex coordinates: x,y,z
1408
        private const val NOR_DATA_SIZE = 3 // normal vector: x,y,z
1409
        private const val TEX_DATA_SIZE = 2 // texture coordinates: s,t
1410
        private const val COM_DATA_SIZE = 1 // component number, a single float
1411

  
1412
        const val POS_ATTRIB: Int = 0
1413
        const val NOR_ATTRIB: Int = POS_DATA_SIZE
1414
        const val TEX_ATTRIB: Int = 0
1415
        const val COM_ATTRIB: Int = TEX_DATA_SIZE
1416

  
1417
        const val VERT1_ATTRIBS: Int = POS_DATA_SIZE+NOR_DATA_SIZE // number of attributes of a vertex (the part changed by preapply)
1418
        const val VERT2_ATTRIBS: Int = TEX_DATA_SIZE+COM_DATA_SIZE // number of attributes of a vertex (the 'preapply invariant' part)
1419
        const val TRAN_ATTRIBS: Int = POS_DATA_SIZE+NOR_DATA_SIZE // number of attributes of a transform feedback vertex
1420

  
1421
        private const val BYTES_PER_FLOAT = 4
1422

  
1423
        private const val OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT
1424
        private const val OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT
1425
        private const val OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT
1426
        private const val OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT
1427

  
1428
        private const val TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT
1429
        private const val VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT
1430
        private const val VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT
1431

  
1432
        private val mCenterBlockIndex = IntArray(EffectQueue.MAIN_VARIANTS)
1433
        private val mAssocBlockIndex = IntArray(EffectQueue.MAIN_VARIANTS)
1434

  
1435
        private const val TEX_COMP_SIZE = 5 // 5 four-byte entities inside the component
1436

  
1437
        /**
1438
         * Are we using per-component centers?
1439
         */
1440
        var useCenters: Boolean = false
1441
            private set
1442
        private var mStride = 0
1443

  
1444
        /**
1445
         * How many mesh components are we going to need? Call before compilation of the shaders.
1446
         */
1447
        ///////////////////////////////////////////////////////////////////////////////////////////////////
1448
        var maxEffComponents: Int = 100
1449

  
1450
        ///////////////////////////////////////////////////////////////////////////////////////////////////
1451
        /**
1452
         * Are we going to need per-component centers (needed for correct postprocessing of concave meshes)
1453
         * Switching this on allocates 16*MAX_EFFECT_COMPONENTS bytes for uniforms in the vertex shader.
1454
         */
1455
        fun setUseCenters()
1456
        {
1457
            useCenters = true
1458
        }
1459

  
1460
        ///////////////////////////////////////////////////////////////////////////////////////////////////
1461

  
1462
        ///////////////////////////////////////////////////////////////////////////////////////////////////
1463

  
1464
        ///////////////////////////////////////////////////////////////////////////////////////////////////
1465
        @JvmStatic
1466
        fun getUniforms(programH: Int, variant: Int)
1467
        {
1468
            mCenterBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentCenter")
1469
            mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation")
1470

  
1471
            if (mStride==0)
1472
            {
1473
                val uniformNames = arrayOf("vComAssoc")
1474
                val indices = IntArray(1)
1475
                val params = IntArray(1)
1476

  
1477
                GLES30.glGetUniformIndices(programH, uniformNames, indices, 0)
1478
                GLES30.glGetActiveUniformsiv(programH, 1, indices, 0, GLES30.GL_UNIFORM_ARRAY_STRIDE, params, 0)
1479

  
1480
                mStride = params[0]/4
1481
            }
1482
        }
1483
    }
1484 1429
}
src/main/java/org/distorted/library/mesh/MeshMultigon.kt
692 692
        ///////////////////////////////////////////////////////////////////////////////////////////////////
693 693
        // PUBLIC API
694 694
        ///////////////////////////////////////////////////////////////////////////////////////////////////
695
        @JvmStatic
695 696
        fun computeEdgesUp(vertices: Array<Array<FloatArray>>): Array<IntArray>
696 697
        {
697 698
            val numPoly = vertices.size
......
708 709
        }
709 710

  
710 711
        ///////////////////////////////////////////////////////////////////////////////////////////////////
712
        @JvmStatic
711 713
        fun computeOuterAndHoleVertices(vertices: Array<Array<FloatArray>>, edgesUp: Array<IntArray>): Array<Array<FloatArray>>
712 714
        {
713 715
            val tmp = ArrayList<FloatArray>()
src/main/java/org/distorted/library/mesh/MeshPolygon.kt
286 286
     * all bands go to.
287 287
     * @param centerY    Y coordinate of the center.
288 288
     */
289
    @JvmOverloads
290
    constructor(verticesXY: Array<FloatArray>, bands: FloatArray, exBand: Int = 0, exVertices: Int = 0, centerX: Float = 0.0f, centerY: Float = 0.0f) : super()
289
    constructor(verticesXY: Array<FloatArray>, bands: FloatArray, exBand: Int, exVertices: Int, centerX: Float, centerY: Float) : super()
291 290
    {
292 291
        mPolygonVertices = verticesXY
293 292
        mPolygonBands = bands
......
330 329
    }
331 330

  
332 331
    ///////////////////////////////////////////////////////////////////////////////////////////////////
333
    constructor(verticesXY: Array<FloatArray>, bands: FloatArray, exIndex: Int, exVertices: Int) : this(verticesXY, bands, exIndex, exVertices, 0.0f, 0.0f)
332
    constructor(verticesXY: Array<FloatArray>, bands: FloatArray, exIndex: Int, exVertices: Int)
333
               : this(verticesXY, bands, exIndex, exVertices, 0.0f, 0.0f)
334

  
335
    ///////////////////////////////////////////////////////////////////////////////////////////////////
336
    constructor(verticesXY: Array<FloatArray>, bands: FloatArray)
337
               : this(verticesXY, bands, 0, 0, 0.0f, 0.0f)
334 338

  
335 339
    ///////////////////////////////////////////////////////////////////////////////////////////////////
336 340
    /**
src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.kt
48 48
    ///////////////////////////////////////////////////////////////////////////////////////////////
49 49
    constructor()
50 50
    {
51
        mMax = MeshBase.getMaxEffComponents()
51
        mMax = MeshBase.maxEffComponents
52 52
        mStride = DEFAULT_STRIDE
53 53
        mAssociations = IntArray(mStride*mMax)
54 54

  
src/main/java/org/distorted/library/uniformblock/UniformBlockCenter.kt
38 38
    ///////////////////////////////////////////////////////////////////////////////////////////////
39 39
    constructor()
40 40
    {
41
        mMax = MeshBase.getMaxEffComponents()
41
        mMax = MeshBase.maxEffComponents
42 42
        backingArray = FloatArray(4*mMax)
43 43
        mUBO = InternalBuffer()
44 44
    }

Also available in: Unified diff