1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-07 03:13:49 +00:00

Do not fail if indices of barycoords attributes are greater or equal to max vertex attributes.

This commit is contained in:
Sergey Lipskiy 2020-12-26 21:50:47 +07:00
parent 2f8372c113
commit ca68dc3675
9 changed files with 45 additions and 20 deletions

View File

@ -3019,13 +3019,13 @@ CombinerProgramBuilder::CombinerProgramBuilder(const opengl::GLInfo & _glinfo, o
, m_shaderCoverage(new ShaderCoverage()) , m_shaderCoverage(new ShaderCoverage())
, m_useProgram(_useProgram) , m_useProgram(_useProgram)
, m_combinerOptionsBits(graphics::CombinerProgram::getShaderCombinerOptionsBits()) , m_combinerOptionsBits(graphics::CombinerProgram::getShaderCombinerOptionsBits())
, m_useCoverage(_glinfo.coverage && config.generalEmulation.enableCoverage != 0)
{ {
m_vertexShaderRect = _createVertexShader(m_vertexHeader.get(), m_vertexRect.get(), m_vertexEnd.get()); m_vertexShaderRect = _createVertexShader(m_vertexHeader.get(), m_vertexRect.get(), m_vertexEnd.get());
m_vertexShaderTriangle = _createVertexShader(m_vertexHeader.get(), m_vertexTriangle.get(), m_vertexEnd.get()); m_vertexShaderTriangle = _createVertexShader(m_vertexHeader.get(), m_vertexTriangle.get(), m_vertexEnd.get());
m_vertexShaderTexturedRect = _createVertexShader(m_vertexHeader.get(), m_vertexTexturedRect.get(), m_vertexEnd.get()); m_vertexShaderTexturedRect = _createVertexShader(m_vertexHeader.get(), m_vertexTexturedRect.get(), m_vertexEnd.get());
m_vertexShaderTexturedTriangle = _createVertexShader(m_vertexHeader.get(), m_vertexTexturedTriangle.get(), m_vertexEnd.get()); m_vertexShaderTexturedTriangle = _createVertexShader(m_vertexHeader.get(), m_vertexTexturedTriangle.get(), m_vertexEnd.get());
m_uniformFactory.reset(new CombinerProgramUniformFactory(_glinfo)); m_uniformFactory.reset(new CombinerProgramUniformFactory(_glinfo));
m_useCoverage = (config.generalEmulation.enableCoverage != 0) && (_glinfo.dual_source_blending || _glinfo.ext_fetch || _glinfo.ext_fetch_arm);
} }
CombinerProgramBuilder::~CombinerProgramBuilder() CombinerProgramBuilder::~CombinerProgramBuilder()

View File

@ -7,8 +7,13 @@ using namespace glsl;
void Utils::locateAttributes(GLuint _program, bool _rect, bool _textures) void Utils::locateAttributes(GLuint _program, bool _rect, bool _textures)
{ {
static GLint maxVertexAttribs = 0;
if (maxVertexAttribs == 0)
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
if (_rect) { if (_rect) {
glBindAttribLocation(_program, opengl::rectAttrib::position, "aRectPosition"); glBindAttribLocation(_program, opengl::rectAttrib::position, "aRectPosition");
if (opengl::rectAttrib::barycoords < static_cast<u32>(maxVertexAttribs))
glBindAttribLocation(_program, opengl::rectAttrib::barycoords, "aBaryCoords"); glBindAttribLocation(_program, opengl::rectAttrib::barycoords, "aBaryCoords");
if (_textures) { if (_textures) {
glBindAttribLocation(_program, opengl::rectAttrib::texcoord0, "aTexCoord0"); glBindAttribLocation(_program, opengl::rectAttrib::texcoord0, "aTexCoord0");
@ -21,6 +26,7 @@ void Utils::locateAttributes(GLuint _program, bool _rect, bool _textures)
glBindAttribLocation(_program, opengl::triangleAttrib::color, "aColor"); glBindAttribLocation(_program, opengl::triangleAttrib::color, "aColor");
glBindAttribLocation(_program, opengl::triangleAttrib::numlights, "aNumLights"); glBindAttribLocation(_program, opengl::triangleAttrib::numlights, "aNumLights");
glBindAttribLocation(_program, opengl::triangleAttrib::modify, "aModify"); glBindAttribLocation(_program, opengl::triangleAttrib::modify, "aModify");
if (opengl::triangleAttrib::barycoords < static_cast<u32>(maxVertexAttribs))
glBindAttribLocation(_program, opengl::triangleAttrib::barycoords, "aBaryCoords"); glBindAttribLocation(_program, opengl::triangleAttrib::barycoords, "aBaryCoords");
if (_textures) if (_textures)
glBindAttribLocation(_program, opengl::triangleAttrib::texcoord, "aTexCoord"); glBindAttribLocation(_program, opengl::triangleAttrib::texcoord, "aTexCoord");

View File

@ -8,14 +8,14 @@ namespace opengl {
const GLuint texcoord = 2U; const GLuint texcoord = 2U;
const GLuint numlights = 3U; const GLuint numlights = 3U;
const GLuint modify = 4U; const GLuint modify = 4U;
const GLuint barycoords = 5U; const GLuint barycoords = 8U;
} }
// Rect attributes // Rect attributes
namespace rectAttrib { namespace rectAttrib {
const GLuint position = 6U; const GLuint position = 5U;
const GLuint texcoord0 = 7U; const GLuint texcoord0 = 6U;
const GLuint texcoord1 = 8U; const GLuint texcoord1 = 7U;
const GLuint barycoords = 9U; const GLuint barycoords = 9U;
} }
} }

View File

@ -33,6 +33,7 @@ BufferedDrawer::BufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray *
glVertexAttribPointer(rectAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, x))); glVertexAttribPointer(rectAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, x)));
glVertexAttribPointer(rectAttrib::texcoord0, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s0))); glVertexAttribPointer(rectAttrib::texcoord0, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s0)));
glVertexAttribPointer(rectAttrib::texcoord1, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s1))); glVertexAttribPointer(rectAttrib::texcoord1, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s1)));
if (_glinfo.coverage)
glVertexAttribPointer(rectAttrib::barycoords, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, bc0))); glVertexAttribPointer(rectAttrib::barycoords, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, bc0)));
/* Init buffers for triangles */ /* Init buffers for triangles */
@ -45,13 +46,15 @@ BufferedDrawer::BufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray *
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, true); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, true);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, true); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, true);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::numlights, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::numlights, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, true);
glVertexAttribPointer(triangleAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, x))); glVertexAttribPointer(triangleAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, x)));
glVertexAttribPointer(triangleAttrib::color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, r))); glVertexAttribPointer(triangleAttrib::color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, r)));
glVertexAttribPointer(triangleAttrib::texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, s))); glVertexAttribPointer(triangleAttrib::texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, s)));
glVertexAttribPointer(triangleAttrib::modify, 4, GL_BYTE, GL_TRUE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, modify))); glVertexAttribPointer(triangleAttrib::modify, 4, GL_BYTE, GL_TRUE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, modify)));
if (_glinfo.coverage) {
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, true);
glVertexAttribPointer(triangleAttrib::barycoords, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, bc0))); glVertexAttribPointer(triangleAttrib::barycoords, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, bc0)));
} }
}
void BufferedDrawer::_initBuffer(Buffer & _buffer, GLuint _bufSize) void BufferedDrawer::_initBuffer(Buffer & _buffer, GLuint _bufSize)
{ {

View File

@ -57,8 +57,8 @@ namespace opengl {
f32 x, y, z, w; f32 x, y, z, w;
f32 r, g, b, a; f32 r, g, b, a;
f32 s, t; f32 s, t;
u32 modify;
f32 bc0, bc1; f32 bc0, bc1;
u32 modify;
}; };
void _initBuffer(Buffer & _buffer, GLuint _bufSize); void _initBuffer(Buffer & _buffer, GLuint _bufSize);

View File

@ -198,6 +198,13 @@ void GLInfo::init() {
} }
} }
coverage = dual_source_blending || ext_fetch || ext_fetch_arm;
if (coverage) {
GLint maxVertexAttribs = 0;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
coverage = maxVertexAttribs >= 10;
}
#ifdef EGL #ifdef EGL
if (isGLESX) if (isGLESX)
{ {

View File

@ -38,6 +38,7 @@ struct GLInfo {
bool eglImage = false; bool eglImage = false;
bool eglImageFramebuffer = false; bool eglImageFramebuffer = false;
bool dual_source_blending = false; bool dual_source_blending = false;
bool coverage = false;
Renderer renderer = Renderer::Other; Renderer renderer = Renderer::Other;
void init(); void init();

View File

@ -9,18 +9,22 @@ using namespace opengl;
UnbufferedDrawer::UnbufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray * _cachedAttribArray) UnbufferedDrawer::UnbufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray * _cachedAttribArray)
: m_glInfo(_glinfo) : m_glInfo(_glinfo)
, m_cachedAttribArray(_cachedAttribArray) , m_cachedAttribArray(_cachedAttribArray)
, m_useCoverage(_glinfo.coverage)
{ {
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::position, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::position, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::color, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::color, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::numlights, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::numlights, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false);
if (m_useCoverage) {
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, false);
}
m_attribsData.fill(nullptr); m_attribsData.fill(nullptr);
} }
@ -71,7 +75,7 @@ void UnbufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParame
glVertexAttribPointer(triangleAttrib::modify, 4, GL_BYTE, GL_FALSE, sizeof(SPVertex), ptr); glVertexAttribPointer(triangleAttrib::modify, 4, GL_BYTE, GL_FALSE, sizeof(SPVertex), ptr);
} }
{ if (m_useCoverage) {
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, true); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, true);
const void * ptr = &_params.vertices->bc0; const void * ptr = &_params.vertices->bc0;
if (_updateAttribPointer(triangleAttrib::barycoords, ptr)) if (_updateAttribPointer(triangleAttrib::barycoords, ptr))
@ -84,6 +88,7 @@ void UnbufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParame
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false);
if (m_useCoverage)
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, false);
if (config.frameBufferEmulation.N64DepthCompare != Config::dcCompatible) { if (config.frameBufferEmulation.N64DepthCompare != Config::dcCompatible) {
@ -143,7 +148,7 @@ void UnbufferedDrawer::drawRects(const graphics::Context::DrawRectParameters & _
} else } else
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false);
{ if (m_useCoverage) {
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, true); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, true);
const void * ptr = &_params.vertices->bc0; const void * ptr = &_params.vertices->bc0;
if (_updateAttribPointer(rectAttrib::barycoords, ptr)) if (_updateAttribPointer(rectAttrib::barycoords, ptr))
@ -154,6 +159,7 @@ void UnbufferedDrawer::drawRects(const graphics::Context::DrawRectParameters & _
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::color, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::color, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false);
if (m_useCoverage)
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, false);
glDrawArrays(GLenum(_params.mode), 0, _params.verticesCount); glDrawArrays(GLenum(_params.mode), 0, _params.verticesCount);
@ -177,6 +183,7 @@ void UnbufferedDrawer::drawLine(f32 _width, SPVertex * _vertices)
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, false);
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false);
if (m_useCoverage)
m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, false); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, false);
m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false);

View File

@ -24,6 +24,7 @@ namespace opengl {
const GLInfo & m_glInfo; const GLInfo & m_glInfo;
CachedVertexAttribArray * m_cachedAttribArray; CachedVertexAttribArray * m_cachedAttribArray;
std::array<const void*, MaxAttribIndex> m_attribsData; std::array<const void*, MaxAttribIndex> m_attribsData;
bool m_useCoverage = false;
}; };
} }