mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
GL: Fix fallback when glDrawRangeElementsBaseVertex is absent
This commit is contained in:
parent
7b1afc849e
commit
66940cab38
3 changed files with 8 additions and 10 deletions
|
@ -255,18 +255,18 @@ namespace PICA::IndexBuffer {
|
||||||
// So we need to subtract the base vertex index from every index in the index buffer ourselves
|
// So we need to subtract the base vertex index from every index in the index buffer ourselves
|
||||||
// This is not really common, so we do it without SIMD for the moment, just to be able to run on Android Studio
|
// This is not really common, so we do it without SIMD for the moment, just to be able to run on Android Studio
|
||||||
template <bool useShortIndices>
|
template <bool useShortIndices>
|
||||||
void subtractBaseIndex(u8* indexBuffer, u32 vertexCount, u16 baseIndex) {
|
void subtractBaseIndex(u8* indexBuffer, u32 indexCount, u16 baseIndex) {
|
||||||
// Calculate the minimum and maximum indices used in the index buffer, so we'll only upload them
|
// Calculate the minimum and maximum indices used in the index buffer, so we'll only upload them
|
||||||
if constexpr (useShortIndices) {
|
if constexpr (useShortIndices) {
|
||||||
u16* indexBuffer16 = reinterpret_cast<u16*>(indexBuffer);
|
u16* indexBuffer16 = reinterpret_cast<u16*>(indexBuffer);
|
||||||
|
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < indexCount; i++) {
|
||||||
indexBuffer16[i] -= baseIndex;
|
indexBuffer16[i] -= baseIndex;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
u8 baseIndex8 = u8(baseIndex);
|
u8 baseIndex8 = u8(baseIndex);
|
||||||
|
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < indexCount; i++) {
|
||||||
indexBuffer[i] -= baseIndex8;
|
indexBuffer[i] -= baseIndex8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ namespace OpenGL {
|
||||||
struct Driver {
|
struct Driver {
|
||||||
bool supportsExtFbFetch = false;
|
bool supportsExtFbFetch = false;
|
||||||
bool supportsArmFbFetch = false;
|
bool supportsArmFbFetch = false;
|
||||||
// Does this driver support glDraw(Range)ElementsBaseVertex?
|
|
||||||
bool supportsDrawElementsBaseVertex = false;
|
|
||||||
|
|
||||||
bool supportFbFetch() const { return supportsExtFbFetch || supportsArmFbFetch; }
|
bool supportFbFetch() const { return supportsExtFbFetch || supportsArmFbFetch; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -195,7 +195,6 @@ void RendererGL::initGraphicsContextInternal() {
|
||||||
// Populate our driver info structure
|
// Populate our driver info structure
|
||||||
driverInfo.supportsExtFbFetch = (GLAD_GL_EXT_shader_framebuffer_fetch != 0);
|
driverInfo.supportsExtFbFetch = (GLAD_GL_EXT_shader_framebuffer_fetch != 0);
|
||||||
driverInfo.supportsArmFbFetch = (GLAD_GL_ARM_shader_framebuffer_fetch != 0);
|
driverInfo.supportsArmFbFetch = (GLAD_GL_ARM_shader_framebuffer_fetch != 0);
|
||||||
driverInfo.supportsDrawElementsBaseVertex = (glDrawRangeElementsBaseVertex != nullptr);
|
|
||||||
|
|
||||||
// Initialize the default vertex shader used with shadergen
|
// Initialize the default vertex shader used with shadergen
|
||||||
std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader();
|
std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader();
|
||||||
|
@ -531,7 +530,7 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> v
|
||||||
// If glDrawRangeElementsBaseVertex is not available then prepareForDraw will have subtracted the base vertex from the index buffer
|
// If glDrawRangeElementsBaseVertex is not available then prepareForDraw will have subtracted the base vertex from the index buffer
|
||||||
// for us, so just use glDrawRangeElements
|
// for us, so just use glDrawRangeElements
|
||||||
glDrawRangeElements(
|
glDrawRangeElements(
|
||||||
primitiveTopology, 0, maximumIndex - minimumIndex, GLsizei(vertices.size()),
|
primitiveTopology, 0, GLint(maximumIndex - minimumIndex), GLsizei(vertices.size()),
|
||||||
usingShortIndices ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, hwIndexBufferOffset
|
usingShortIndices ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, hwIndexBufferOffset
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1183,9 +1182,10 @@ void RendererGL::accelerateVertexUpload(ShaderUnit& shaderUnit, PICA::DrawAccele
|
||||||
|
|
||||||
std::memcpy(indexBufferRes.pointer, accel->indexBuffer, indexBufferSize);
|
std::memcpy(indexBufferRes.pointer, accel->indexBuffer, indexBufferSize);
|
||||||
// If we don't have glDrawRangeElementsBaseVertex, we must subtract the base index value from our index buffer manually
|
// If we don't have glDrawRangeElementsBaseVertex, we must subtract the base index value from our index buffer manually
|
||||||
if (!driverInfo.supportsDrawElementsBaseVertex) [[unlikely]] {
|
if (glDrawRangeElementsBaseVertex == nullptr) [[unlikely]] {
|
||||||
usingShortIndices ? PICA::IndexBuffer::subtractBaseIndex<true>((u8*)indexBufferRes.pointer, vertexCount, accel->minimumIndex)
|
const u32 indexCount = regs[PICA::InternalRegs::VertexCountReg];
|
||||||
: PICA::IndexBuffer::subtractBaseIndex<false>((u8*)indexBufferRes.pointer, vertexCount, accel->minimumIndex);
|
usingShortIndices ? PICA::IndexBuffer::subtractBaseIndex<true>((u8*)indexBufferRes.pointer, indexCount, accel->minimumIndex)
|
||||||
|
: PICA::IndexBuffer::subtractBaseIndex<false>((u8*)indexBufferRes.pointer, indexCount, accel->minimumIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
hwIndexBuffer->Unmap(indexBufferSize);
|
hwIndexBuffer->Unmap(indexBufferSize);
|
||||||
|
|
Loading…
Add table
Reference in a new issue