«попытка доступа к вершинам вне диапазона» только на мобильном устройстве (android)Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 «попытка доступа к вершинам вне диапазона» только на мобильном устройстве (android)

Сообщение Anonymous »

На настольном компьютере работает нормально, но на мобильном устройстве Android13 не работает.

Ящик:

Код: Выделить всё

App.operation.draws.drawObj = function(object, ray) {
var lighting = 1;
var localLooper = 0;
lighting = true;

mat4.identity(object.mvMatrix);
world.mvPushMatrix(object.mvMatrix, this.mvMatrixStack);

if(App.camera.FirstPersonController == true) {
camera.setCamera(object);
} else if(App.camera.SceneController == true) {
camera.setSceneCamera(object);
}

mat4.translate(object.mvMatrix, object.mvMatrix, object.position.worldLocation);
if(raycaster.checkingProcedureCalc && typeof ray === 'undefined') raycaster.checkingProcedureCalcObj(object);
mat4.rotate(object.mvMatrix, object.mvMatrix, degToRad(object.rotation.rx), object.rotation.getRotDirX());
mat4.rotate(object.mvMatrix, object.mvMatrix, degToRad(object.rotation.ry), object.rotation.getRotDirY());
mat4.rotate(object.mvMatrix, object.mvMatrix, degToRad(object.rotation.rz), object.rotation.getRotDirZ());

if(typeof object.mesh.vertexBuffer != 'undefined') {
if(object.animation != null) {
object.animation.currentDraws++;
if(typeof object.animation.anims === 'undefined' && object.animation.currentDraws > object.animation.speed) {
object.animation.currentAni++;
object.animation.currentDraws = 0;
if(object.animation.currentAni > object.animation.sumOfAniFrames) {
object.animation.currentAni = 0;
}
}

// Make animation sequences -> sub animation
if(typeof object.animation.anims !== 'undefined') {
if(object.animation.currentDraws > object.animation.anims[object.animation.anims.active].speed) {
object.animation.currentAni++;
object.animation.currentDraws = 0;
if(object.animation.currentAni > object.animation.anims[object.animation.anims.active].to - 1) {
object.animation.currentAni = object.animation.anims[object.animation.anims.active].from;
}
}
}

if(object.animation.currentAni == 0) {
world.GL.gl.bindBuffer(world.GL.gl.ARRAY_BUFFER, object.meshList[object.animation.id].vertexBuffer);
world.GL.gl.enableVertexAttribArray(object.shaderProgram.vertexPositionAttribute);
world.GL.gl.vertexAttribPointer(object.shaderProgram.vertexPositionAttribute, object.meshList[object.animation.id].vertexBuffer.itemSize, world.GL.gl.FLOAT, false, 0, 0);
} else {
world.GL.gl.bindBuffer(world.GL.gl.ARRAY_BUFFER, object.meshList[object.animation.id + object.animation.currentAni].vertexBuffer);
world.GL.gl.enableVertexAttribArray(object.shaderProgram.vertexPositionAttribute);
world.GL.gl.vertexAttribPointer(
object.shaderProgram.vertexPositionAttribute,
object.meshList[object.animation.id + object.animation.currentAni].vertexBuffer.itemSize,
world.GL.gl.FLOAT,
false,
0,
0
);
}

} else {
// now to render the mesh test
world.GL.gl.bindBuffer(world.GL.gl.ARRAY_BUFFER, object.mesh.vertexBuffer);
world.GL.gl.bufferData(world.GL.gl.ARRAY_BUFFER, object.mesh.vertices, world.GL.gl.STATIC_DRAW);
world.GL.gl.enableVertexAttribArray(object.shaderProgram.vertexPositionAttribute);
world.GL.gl.vertexAttribPointer(object.shaderProgram.vertexPositionAttribute, object.mesh.vertexBuffer.itemSize, world.GL.gl.FLOAT, false, 0, 0);
}
}

// COLOR BUFFER
if(object.vertexColorBuffer) {
world.GL.gl.bindBuffer(world.GL.gl.ARRAY_BUFFER, object.vertexColorBuffer);
world.GL.gl.enableVertexAttribArray(object.shaderProgram.vertexColorAttribute);
world.GL.gl.vertexAttribPointer(object.shaderProgram.vertexColorAttribute, object.vertexColorBuffer.itemSize, world.GL.gl.FLOAT, false, 0, 0);
localLooper = localLooper + 1;
}

//LIGHT STAFF
if(lighting &&  object.shaderProgram.useLightingUniform) {
world.GL.gl.uniform1i(object.shaderProgram.useLightingUniform, lighting);
/* Set the normals */
if(object.mesh.normalBuffer) {
world.GL.gl.bindBuffer(world.GL.gl.ARRAY_BUFFER, object.mesh.normalBuffer);
world.GL.gl.enableVertexAttribArray(object.shaderProgram.vertexNormalAttribute);
world.GL.gl.vertexAttribPointer(object.shaderProgram.vertexNormalAttribute, object.mesh.normalBuffer.itemSize, world.GL.gl.FLOAT, false, 0, 0);
localLooper = localLooper + 1;
}
/* Set the ambient light                 */
if(object.shaderProgram.ambientColorUniform) {
if(E('ambLight') && E('ambLight').color) {
world.GL.gl.uniform3f(object.shaderProgram.ambientColorUniform, parseFloat(E('ambLight').color.rgb[0]), parseFloat(E('ambLight').color.rgb[1]), parseFloat(E('ambLight').color.rgb[2]));
} else {
world.GL.gl.uniform3f(object.shaderProgram.ambientColorUniform, object.LightsData.ambientLight.R(), object.LightsData.ambientLight.G(), object.LightsData.ambientLight.B());
}
}
/* Directional light */
if(object.shaderProgram.directionalColorUniform) {
if(E('dirLight') && E('dirLight').color) {
world.GL.gl.uniform3f(object.shaderProgram.directionalColorUniform, parseFloat(E('dirLight').color.rgb[0]), parseFloat(E('dirLight').color.rgb[1]), parseFloat(E('dirLight').color.rgb[2]));
} else {
world.GL.gl.uniform3f(object.shaderProgram.directionalColorUniform, object.LightsData.directionLight.R(), object.LightsData.directionLight.G(), object.LightsData.directionLight.B());
}
}

/* Normalize the direction */
var lightingDirection = null;
if(object.shaderProgram.lightingDirectionUniform) {
if(E('dirX') && E('dirY') && E('dirZ')) {
lightingDirection = [parseFloat(E('dirX').value), parseFloat(E('dirY').value), parseFloat(E('dirZ').value)];
} else {
lightingDirection = [object.LightsData.lightingDirection.r, object.LightsData.lightingDirection.g, object.LightsData.lightingDirection.b];
}

var adjustedLD = vec3.create();
vec3.normalize(adjustedLD, lightingDirection);
vec3.scale(adjustedLD, adjustedLD, -1);
world.GL.gl.uniform3fv(object.shaderProgram.lightingDirectionUniform, adjustedLD);
}
} else {
if(object.shaderProgram.useLightingUniform) {
if(object.shaderProgram.ambientColorUniform) {
world.GL.gl.uniform3f(object.shaderProgram.ambientColorUniform, parseFloat(1), parseFloat(2), parseFloat(0));
}
if(object.shaderProgram.directionalColorUniform) {
world.GL.gl.uniform3f(object.shaderProgram.directionalColorUniform, parseFloat(1), parseFloat(1), parseFloat(0));
}
}
}

// it's possible that the mesh doesn't contain any texture coordinates
// in this case, the texture vertexAttribArray will need to be disabled
// before the call to drawElements
if(!object.mesh.textures.length && !object.texture) {
world.GL.gl.disableVertexAttribArray(object.shaderProgram.textureCoordAttribute);
} else {
// if the texture vertexAttribArray has been previously
// disabled, then it needs to be re-enabled
if(object.texture) {
world.GL.gl.bindBuffer(world.GL.gl.ARRAY_BUFFER, object.mesh.textureBuffer);
world.GL.gl.enableVertexAttribArray(object.shaderProgram.textureCoordAttribute);
world.GL.gl.vertexAttribPointer(object.shaderProgram.textureCoordAttribute, object.mesh.textureBuffer.itemSize, world.GL.gl.FLOAT, false, 0, 0);

if(object.streamTextures != null) {
// video/webcam tex
if(object.streamTextures.video) {
// App.tools.loadVideoTexture('glVideoTexture', object.streamTextures.videoImage);
App.tools.loadVideoTexture('glVideoTexture', object.streamTextures.video);
} else {
App.tools.loadVideoTexture('glVideoTexture', object.streamTextures.videoImage);
}
world.GL.gl.uniform1i(object.shaderProgram.samplerUniform, 0);
}  else {
//------------
if(object.shadows &&  object.shadows.type == "spot-shadow") {
// --------------------------------------------------------------------
let textureMatrix = m4.identity();
textureMatrix = m4.translate(textureMatrix, 0.5, 0.5, 0.5);
textureMatrix = m4.scale(textureMatrix, 0.5, 0.5, 0.5);
textureMatrix = m4.multiply(textureMatrix, object.shadows.lightProjectionMatrix);
const lightWorldMatrix = m4.lookAt(
[object.shadows.lightPosition[0], object.shadows.lightPosition[1], object.shadows.lightPosition[2]],
[object.shadows.lightTarget[0], object.shadows.lightTarget[1], object.shadows.lightTarget[2]], // target
[object.shadows.orientation[0], object.shadows.orientation[1], object.shadows.orientation[2]], // up
);
textureMatrix = m4.multiply(textureMatrix, m4.inverse(lightWorldMatrix));
const mat = m4.multiply(lightWorldMatrix, m4.inverse(object.shadows.lightProjectionMatrix));
world.GL.gl.uniformMatrix4fv(object.shaderProgram.u_textureMatrix, false, textureMatrix);
world.GL.gl.uniform3fv(object.shaderProgram.lightWorldPositionLocation, object.shadows.lightPosition);
world.GL.gl.uniformMatrix4fv(object.shaderProgram.u_world, false,
m4.translate(object.position.worldLocation[0],
object.position.worldLocation[1],
object.position.worldLocation[2])
);
// world.GL.gl.uniformMatrix4fv(object.shaderProgram.u_world, false, mat);
world.GL.gl.uniform3fv(object.shaderProgram.u_reverseLightDirection, lightWorldMatrix.slice(8, 11));
world.GL.gl.uniform1f(object.shaderProgram.u_bias, object.shadows.bias);

}
//------------ FROM CUBE
for(var t = 0;t < object.textures.length;t++) {
if(object.custom.gl_texture == null) {
world.GL.gl.activeTexture(world.GL.gl['TEXTURE' + t]);
world.GL.gl.bindTexture(world.GL.gl.TEXTURE_2D, object.textures[t]);
if(world.GL.extTFAnisotropic) {
world.GL.gl.texParameterf(world.GL.gl.TEXTURE_2D,
world.GL.extTFAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,
world.GL.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
}
if(object.texParams.MIPMAP == false) {
// world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_S, world.GL.gl.REPEAT);
// world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_T, world.GL.gl.REPEAT);

world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_S, world.GL.gl.CLAMP_TO_EDGE);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_WRAP_T, world.GL.gl.CLAMP_TO_EDGE);
}
else {
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MAG_FILTER, object.texParams.TEXTURE_MAG_FILTER | world.GL.gl.LINEAR);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MIN_FILTER, object.texParams.TEXTURE_MIN_FILTER | world.GL.gl.LINEAR);
}

if(typeof object.texParams.spriteAnimation != 'undefined' && object.texParams.spriteAnimation != false && object.textures[t].image.width != 0) {
//char * data; // data of 8-bit per sample RGBA image
// int w, h; // size of the image
// int sx, sy, sw, sh;  // position and size of area you want to crop.
//glTexImage2D does support regions - of - interest.You do it as follows:
world.GL.gl.pixelStorei(world.GL.gl.UNPACK_FLIP_Y_WEBGL, false);
var [XX, YY] = object.texParams.spriteAnimation.getOffsetXY();
world.GL.gl.pixelStorei(world.GL.gl.UNPACK_ROW_LENGTH, object.textures[t].image.height);
world.GL.gl.pixelStorei(world.GL.gl.UNPACK_SKIP_PIXELS,
XX * (object.textures[t].image.width / object.texParams.spriteAnimation.shema[0]));
world.GL.gl.pixelStorei(world.GL.gl.UNPACK_SKIP_ROWS,
YY * (object.textures[t].image.height / object.texParams.spriteAnimation.shema[1]));
world.GL.gl.pixelStorei(world.GL.gl.UNPACK_ALIGNMENT, 1);
// LodePNG tightly packs everything
// glTexImage2D(GL_TEXTURE_2D, level, internalFormat,
// sw, sh, border, format, type, data);
world.GL.gl.texImage2D(world.GL.gl.TEXTURE_2D,
0, world.GL.gl.RGBA,
object.textures[t].image.width / object.texParams.spriteAnimation.shema[0],
object.textures[t].image.height / object.texParams.spriteAnimation.shema[1],
0,
world.GL.gl.RGBA,
world.GL.gl.UNSIGNED_BYTE,
object.textures[t].image);
}

if(object.texParams.MIPMAP == true) {
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MAG_FILTER, world.GL.gl.NEAREST);
world.GL.gl.texParameteri(world.GL.gl.TEXTURE_2D, world.GL.gl.TEXTURE_MIN_FILTER, world.GL.gl.LINEAR_MIPMAP_NEAREST);
world.GL.gl.generateMipmap(world.GL.gl.TEXTURE_2D);
}

world.GL.gl.uniform1i(object.shaderProgram.samplerUniform, t);
} else {
object.custom.gl_texture(object, t);
}
}
}

localLooper = localLooper + 1;
} else {
world.GL.gl.disableVertexAttribArray(object.shaderProgram.textureCoordAttribute);
}
}

world.GL.gl.bindBuffer(world.GL.gl.ELEMENT_ARRAY_BUFFER, object.mesh.indexBuffer);
this.setMatrixUniforms(object, this.pMatrix, object.mvMatrix);

if(object.mesh.normalBuffer &&  object.shaderProgram.nMatrixUniform) {
var normalMatrix = mat3.create();
mat3.normalFromMat4(normalMatrix, object.mvMatrix);
mat3.transpose(normalMatrix, normalMatrix);
world.GL.gl.uniformMatrix3fv(object.shaderProgram.nMatrixUniform, false, normalMatrix);
}

if(object.glBlend.blendEnabled == true) {
if(!world.GL.gl.isEnabled(world.GL.gl.BLEND)) {
// world.GL.gl.disable(world.GL.gl.DEPTH_TEST);
world.GL.gl.enable(world.GL.gl.BLEND);
}
world.GL.gl.blendFunc(world.GL.gl[object.glBlend.blendParamSrc], world.GL.gl[object.glBlend.blendParamDest]);
} else {
world.GL.gl.disable(world.GL.gl.BLEND);
world.GL.gl.enable(world.GL.gl.DEPTH_TEST);
}

if(object.TEST) world.disableUnusedAttr(world.GL.gl, object.TEST);
world.GL.gl.drawElements(world.GL.gl[object.glDrawElements.mode], object.glDrawElements.numberOfIndicesRender, world.GL.gl.UNSIGNED_SHORT, 0);
// world.GL.gl.drawArrays(world.GL.gl[object.glDrawElements.mode], object.glDrawElements.numberOfIndicesRender, world.GL.gl.UNSIGNED_INT, 0);

object.instancedDraws.overrideDrawArraysInstance(object);

this.mvPopMatrix(object.mvMatrix, this.mvMatrixStack);
};
Я обнаружил эту ошибку с помощью удаленного отладчика Chrome...
Журнал ошибок:

Код: Выделить всё

GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0
Изображение

демо
Обновление:
Интересный факт: я использую отладчик построчно, потому что в журнале предупреждений не указывается номер строки разрыва.
Я замечаю строка:

Код: Выделить всё

    if (object.mesh.normalBuffer) {
_matrixWorld.world.GL.gl.bindBuffer(_matrixWorld.world.GL.gl.ARRAY_BUFFER, object.mesh.normalBuffer);
предупреждение желтого цвета с тем же журналом предупреждений.
[img]https://i.sstatic .net/GZlzcxQE.png[/img]


Подробнее здесь: https://stackoverflow.com/questions/793 ... ce-android
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»