Repitition of texture on pan gesture in Metal Shading Language

若如初见. 提交于 2019-12-13 03:41:31

问题


I am new to metal shading language.So your kind guidance would be so helpful. I just repeated texture using metal as shown on below image (Image sequence). But it seems not smoothy.How can I make it to be appeared as smoothy line as done in following link for metal points.(overlapping Metal Point primitives and blending)

At the moment what I do is allocating memory for vertex buffer (MTLBuffer) at each touch point in my gesture.

code:

func allocateMemoryForVetexBuffer(vertices: Array<Vertex>){
        var vertexData = Array<Float>()
        for vertex in vertices{
            vertexData += vertex.floatBuffer()
        }

        let dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0])
        print("dataSize:\(dataSize)")
        vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: [])

        vertexCount = vertices.count

    }

I am calling this method in my pan gesture recognizer.But it causes to drop FPS.So my problem is without knowing how many textures will add on single pan on metal layer, how may I allocate memory for Frame Buffer.


回答1:


You're unnecessarily using instancing.

Change this:

renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: vertexCount, 
                             instanceCount: vertexCount / 3)

to this:

renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: vertexCount)


来源:https://stackoverflow.com/questions/50622942/repitition-of-texture-on-pan-gesture-in-metal-shading-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!