javascript - Optimisation help: useProgram called every frame and low FPS -


I am experimenting with a component-based game engine inspired by the unit structure, and works correctly in me, But my frame rate is extremely low.

My setup includes an Mesh Renderer object with its own init () and draw () methods. initMesh () function:

     function initMesh (Aries) {if (! Mesh.vertices) { Mesh.vertices = new Float32Array ([0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1]); } If (! Mesh.uvs) {mesh.uvs = new float 32 array ([0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1]); } Mesh.itemSize = 2; Mesh.numItems = mesh.vertices.length/mesh.itemSize; Mesh.vertexBuffer = gl.createBuffer (); Mesh.uvBuffer = gl.createBuffer (); }  

and initMaterial () function:

  function initMaterial (material, FS, vs.) {content.program = InitShaders (FS, VS); If (material.image) {material.texture = gl.createTtexture ();  

Draw

During the method method I call setMeshBuffer () function

  Function set meshbuffer (trap, content) {// Vertex buffer globbler (gl.ARRAY_BUFFER, mesh.vettesbuffer); Gl.bufferData (gl.ARRAY_BUFFER, Mesh. Description, GL. STATIC_DRAW); Gl.vertexAttribPointer (content.program.aVertexPosition, mesh.itemSize, gl.FLOAT, incorrect, 0, 0); If (physical.text) {// UV buffer globbuffer (gl.ARRAY_BUFFER, Aries.Uubber); Gl.bufferData (gl.ARRAY_BUFFER, mesh.uvs, gl.STATIC_DRAW); Gl.enableVertexAttribArray (material.program.aTexCoord); Gl.vertexAttribPointer (content.program.aTexCoord, mesh.itemSize, gl.FLOAT, incorrect, 0, 0); }}  

and setMaterialBuffer () function:

  function Setmatribrifr (content) {gl.useProgram (material.program) ); Gl.uniform4fv (content.program.uColor, [content.color.r, material.color.g, material.color.b, material.color.a]); If (physical. Motor) (gl.BindTexture (gl.TEXTURE_2D, material.texture); Gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); Gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl Kklanp_to_aj); Glkteksprmeteri (Glktekscr_2D, Glktekscr_mn_failtr, Glknearest); Glkteksprmeteri (Glktekscr_2D, Glktekscr_mag_failtr, Glknearest); Glkteksimage2D (Glktekscr_2D, 0, Gal. RGBA, gl.RGBA, gl.UNSIGNED_BYTE, material.image);}}  

And finally, I drawBuffers () function

  function drawBuffers (numItems) I am calling {gl.drawArrays (Gl. Triyongl, 0, and so on);}  

question

so, Can I do anything to customize this flow? So far, I am unable to find a detailed guideline for a modular structure like this.

My project is, if you try to exclude it, then it is test.html File

My comment in the extended reply form, as requested:

You are uploading new frames and texture data in every frame, every time you render, then make it again. Instead, upload data during initial time. You can complete this by moving your buffer data call to your initMesh () method, and texImage2D call for initMaterial method (you must bind the previously created objects). After leaving the draw, you will see a great performance.

Regarding your comment about changing UV coordination, in every frame you have a few options, which should perform better than you do.

The first option is to update the data on the CPU (as you are currently doing). It's good that the UV data in a buffer - the beginning of data in faster CPU updates and makes it more cache coherent call my Init materials such as I have suggested, but change using GL_DYNAMIC_DRAW instead GL_STATIC_DRAW parameters. This is a sign for the driver that you often plan to change the data. After that, set MathBuffer, use gl.bufferSubData instead of gl.bufferData. This allows you to update only a portion of the data, but it is normally faster at uploading new data.

The second option - which I like - to keep the UV stable, instead of modifying them on the CPU, modify them in a top program.

Hope it helps, and good luck!

Depending on the UV you are changing,

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -