微信小程序 > 微信公开课 > 微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题
微信小程序,微信公开课,微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题

微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题

2019-03-15 16:54:37

微信公开课小程序热门讨论关于「微信小程序开发请问大佬小游戏webgl渲染中uniform3fv参数的问题」的小程序开发问题
补充:微信请问大佬小游戏webgl渲染中uniform3fv参数的问题,当前Bug的表现(可附上截图)使用webgl渲染时,调用gluniform3fv,gluniform4fv等接口设置shader参数时发现以下问题以gl
展开:问题模块框架类型问题类型操作系统操作系统版本手机型号微信版本客户端小游戏BugAndroid712红米4673当前Bug的表现使用webgl渲染时,调用gluniform3fv,gluniform4fv等接口设置shader参数时发现以下问题:以gluniform3fv(dest,v)为例,如果v=Float32Array([1,2,3])subarray(1,2),即输入的参数是一个byteoffset!=0的TypeArray,那么实际运行时该参数的设置结果是错误的,导致游戏显示出现各种问题预期表现复现路径我们还试过华为,三星的多款Android的手机,均有这个问题提供一个最简复现Demo测试代码:letctx =canvasgetContext(webgl)letHEAP32=newInt32Array(1024*1024*8)letglobal_time=0;varaspectRatio;varvertexArray;varvertexBuffer;varvertexNumComponents;varvertexCount;varuScalingFactor;varuGlobalColor;varuRotationVector;varaVertexPosition;varpreviousTime=00;vardegreesPerSecond=900;varHEAP=newFloat32Array(16);varcurrentRotation=8;varcurrentScale=10;varcurrentAngle=0;varshaderProgram=null;varrotationRate=0;functioncompileShader(code,type){letgl=ctx;varshader=glcreateShader(type);glshaderSource(shader,code);glcompileShader(shader);if(!glgetShaderParameter(shader,glCOMPILE_STATUS)){consolelog(Errorcompiling${type===glVERTEX_SHADER?vertex:fragment}shader:);consolelog(glgetShaderInfoLog(shader));}returnshader;}functionanimateScene(){letgl=ctx;glviewport(0,0,320,528);glclearColor(08,09,10,10);glclear(glCOLOR_BUFFER_BIT);varradians=currentAngle*MathPI1800;HEAP[currentRotation]=Mathsin(radians);HEAP[currentRotation+1]=Mathcos(radians);gluseProgram(shaderProgram);uScalingFactor=glgetUniformLocation(shaderProgram,uScalingFactor);uGlobalColor=glgetUniformLocation(shaderProgram,uGlobalColor);uRotationVector=glgetUniformLocation(shaderProgram,uRotationVector);gluniform2fv(uScalingFactor,HEAPsubarray(currentScale,currentScale+2));gluniform2fv(uRotationVector,HEAPsubarray(currentRotation,currentRotation+2));varrot=glgetUniform(shaderProgram,uRotationVector);if(rot[0]!=HEAP[currentRotation]||rot[1]!=HEAP[currentRotation+1])consolelog(buggy);elseconsolelog(ok);gluniform4fv(uGlobalColor,[01,07,02,10]);glbindBuffer(glARRAY_BUFFER,vertexBuffer);aVertexPosition=glgetAttribLocation(shaderProgram,aVertexPosition);glenableVertexAttribArray(aVertexPosition);glvertexAttribPointer(aVertexPosition,vertexNumComponents,glFLOAT,false,0,0);gldrawArrays(glTRIANGLES,0,vertexCount);windowrequestAnimationFrame(function(currentTime){vardeltaAngle=((currentTimepreviousTime)10000)*degreesPerSecond;currentAngle=(currentAngle+deltaAngle)%360;previousTime=currentTime;animateScene();});}***游戏主函数*exportdefaultclassMain{constructor(){维护当前requestAnimationFrame的idthisaniId =0consolelog(start!!!!!)thisstartup();}startup(){letgl=ctx;varshaderSet=[{type:glVERTEX_SHADER,code:attributevec2aVertexPosition;+uniformvec2uScalingFactor;+uniformvec2uRotationVector;+voidmain(){+vec2rotatedPosition=vec2(aVertexPositionx*uRotationVectory+aVertexPositiony*uRotationVectorx,+aVertexPositiony*uRotationVectoryaVertexPositionx*uRotationVectorx);+gl_Position=vec4(rotatedPosition*uScalingFactor,00,10);+}},{type:glFRAGMENT_SHADER,code:precisionhighpfloat;+uniformvec4uGlobalColor;+voidmain(){gl_FragColor=uGlobalColor;}}];shaderProgram=thisbuildShaderProgram(shaderSet);aspectRatio=320528;HEAP[currentRotation]=0;HEAP[currentRotation+1]=1;HEAP[currentScale]=1;HEAP[currentScale+1]=aspectRatio;vertexArray=newFloat32Array([05,05,05,05,05,05,05,05,05,05,05,05]);vertexBuffer=glcreateBuffer();glbindBuffer(glARRAY_BUFFER,vertexBuffer);glbufferData(glARRAY_BUFFER,vertexArray,glSTATIC_DRAW);vertexNumComponents=2;vertexCount=vertexArraylengthvertexNumComponents;currentAngle=00;rotationRate=6;animateScene();}buildShaderProgram(shaderInfo){letgl=ctx;varprogram=glcreateProgram();shaderInfoforEach(function(desc){varshader=compileShader(desccode,desctype);if(shader)glattachShader(program,shader);});gllinkProgram(program)if(!glgetProgramParameter(program,glLINK_STATUS)){consolelog(Errorlinkingshaderprogram:);consolelog(glgetProgramInfoLog(program));}returnprogram;}实现游戏帧循环}即速小程序:就这个问题,我们研究过了cocos等引擎的处理,它们的做法都是直接new一个新的TypeArray来保证实际传入的TypeArray的byteoffset一定为0即:v=newFloat32Array(newFloat32Array([1,2,3])subarray(1,2))但这样以来其实是会产生一定的garbage的,因此希望知道这个问题的实际机制是什么微信这边是否可以帮忙fix掉
更多有关「微信小程序开发请问大佬小游戏webgl渲染中uniform3fv参数的问题」的讨论可以前往微信公开课小程序参与互动哦!
标签:微信公开课,小程序
微信小程序,微信公开课,微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题

「微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题」热门讨论订阅

方法1:微信扫描微信公开课小程序码即可订阅热门讨论「微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题」

方法2:微信搜索微信公开课小程序名称进入,即可订阅热门讨论「微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题」

方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热门讨论「微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题」

微信公开课小程序热门讨论「微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。

微信公开课热门讨论「微信小程序开发请问大佬关于小游戏webgl渲染中uniform3fv参数的问题」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。