2016-09-24 03:28:58 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLVertexAttribData.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
2016-12-29 11:08:39 +03:00
|
|
|
#include "WebGLBuffer.h"
|
2016-09-24 03:28:58 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
CalcBytesPerVertex(GLenum type, uint8_t size)
|
|
|
|
{
|
|
|
|
uint8_t bytesPerType;
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_INT_2_10_10_10_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
bytesPerType = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_HALF_FLOAT:
|
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
bytesPerType = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FIXED: // GLES 3.0.4 p9: 32-bit signed, with 16 fractional bits.
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
case LOCAL_GL_INT:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
bytesPerType = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad `type`.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytesPerType * size;
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
static webgl::AttribBaseType
|
2016-12-22 06:42:07 +03:00
|
|
|
AttribPointerBaseType(bool integerFunc, GLenum type)
|
|
|
|
{
|
|
|
|
if (!integerFunc)
|
2018-10-17 07:18:15 +03:00
|
|
|
return webgl::AttribBaseType::Float;
|
2016-12-22 06:42:07 +03:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
case LOCAL_GL_INT:
|
2018-10-17 07:18:15 +03:00
|
|
|
return webgl::AttribBaseType::Int;
|
2016-12-22 06:42:07 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
2018-10-17 07:18:15 +03:00
|
|
|
return webgl::AttribBaseType::UInt;
|
2016-12-22 06:42:07 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-24 03:28:58 +03:00
|
|
|
void
|
|
|
|
WebGLVertexAttribData::VertexAttribPointer(bool integerFunc, WebGLBuffer* buf,
|
|
|
|
uint8_t size, GLenum type, bool normalized,
|
|
|
|
uint32_t stride, uint64_t byteOffset)
|
|
|
|
{
|
|
|
|
mIntegerFunc = integerFunc;
|
2016-12-29 11:08:39 +03:00
|
|
|
WebGLBuffer::SetSlot(0, buf, &mBuf);
|
2016-09-24 03:28:58 +03:00
|
|
|
mType = type;
|
2016-12-22 06:42:07 +03:00
|
|
|
mBaseType = AttribPointerBaseType(integerFunc, type);
|
2016-09-24 03:28:58 +03:00
|
|
|
mSize = size;
|
|
|
|
mBytesPerVertex = CalcBytesPerVertex(mType, mSize);
|
|
|
|
mNormalized = normalized;
|
|
|
|
mStride = stride;
|
|
|
|
mExplicitStride = (mStride ? mStride : mBytesPerVertex);
|
|
|
|
mByteOffset = byteOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLVertexAttribData::DoVertexAttribPointer(gl::GLContext* gl, GLuint index) const
|
|
|
|
{
|
|
|
|
if (mIntegerFunc) {
|
|
|
|
gl->fVertexAttribIPointer(index, mSize, mType, mStride,
|
|
|
|
(const void*)mByteOffset);
|
|
|
|
} else {
|
|
|
|
gl->fVertexAttribPointer(index, mSize, mType, mNormalized, mStride,
|
|
|
|
(const void*)mByteOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|