OpenGLRenderer: Implement face filling

This commit is contained in:
Jérôme Leclercq 2021-06-17 23:57:01 +02:00
parent 8625c0a7ac
commit b13c5c950a
8 changed files with 36 additions and 6 deletions

View File

@ -31,6 +31,7 @@ namespace Nz
inline GLenum ToOpenGL(BlendEquation blendEquation);
inline GLenum ToOpenGL(BlendFunc blendFunc);
inline GLenum ToOpenGL(FaceFilling filling);
inline GLenum ToOpenGL(FaceSide side);
inline GLenum ToOpenGL(FrontFace face);
inline GLenum ToOpenGL(PrimitiveMode primitiveMode);

View File

@ -74,6 +74,19 @@ namespace Nz
NazaraError("Unhandled BlendFunc 0x" + NumberToString(UnderlyingCast(blendFunc), 16));
return {};
}
inline GLenum ToOpenGL(FaceFilling side)
{
switch (side)
{
case FaceFilling::Fill: return GL_FILL;
case FaceFilling::Line: return GL_LINE;
case FaceFilling::Point: return GL_POINT;
}
NazaraError("Unhandled FaceFilling 0x" + NumberToString(UnderlyingCast(side), 16));
return {};
}
inline GLenum ToOpenGL(FaceSide side)
{

View File

@ -12,8 +12,12 @@
#include <GLES2/gl2ext.h>
// Define some OpenGL (not ES) extensions
#define GL_POINT 0x1B00
#define GL_LINE 0x1B01
#define GL_FILL 0x1B02
#define GL_SHADER_BINARY_FORMAT_SPIR_V_ARB 0x9551
#define GL_SPIR_V_BINARY_ARB 0x9552
typedef void (GL_APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const GLchar* pEntryPoint, GLuint numSpecializationConstants, const GLuint* pConstantIndex, const GLuint* pConstantValue);
// OpenGL core
@ -163,6 +167,8 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const G
\
extCb(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \
\
extCb(glPolygonMode, PFNGLPOLYGONMODEPROC) \
\
extCb(glMemoryBarrier, PFNGLMEMORYBARRIERPROC) \
extCb(glMemoryBarrierByRegion, PFNGLMEMORYBARRIERBYREGIONPROC) \
\

View File

@ -16,6 +16,7 @@ namespace Nz
struct RenderDeviceFeatures
{
bool anisotropicFiltering = false;
bool nonSolidFaceFilling = false;
};
struct RenderDeviceLimits

View File

@ -42,6 +42,7 @@ namespace Nz
RenderDeviceFeatures enabledFeatures;
enabledFeatures.anisotropicFiltering = renderDeviceInfo[bestRenderDeviceIndex].features.anisotropicFiltering;
enabledFeatures.nonSolidFaceFilling = renderDeviceInfo[bestRenderDeviceIndex].features.nonSolidFaceFilling;
m_renderDevice = renderer->InstanciateRenderDevice(bestRenderDeviceIndex, enabledFeatures);
if (!m_renderDevice)

View File

@ -56,6 +56,9 @@ namespace Nz
if ((params.type == GL::ContextType::OpenGL && glVersion >= 460) || m_referenceContext->IsExtensionSupported(GL::Extension::TextureFilterAnisotropic))
m_deviceInfo.features.anisotropicFiltering = true;
if (m_referenceContext->glPolygonMode) //< not supported in core OpenGL ES, but supported in OpenGL or with GL_NV_polygon_mode extension
m_deviceInfo.features.nonSolidFaceFilling = true;
// Limits
GLint minUboOffsetAlignment;
m_referenceContext->glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &minUboOffsetAlignment);

View File

@ -500,13 +500,11 @@ namespace Nz::GL
m_state.renderStates.frontFace = targetFrontFace;
}
/*
TODO: Use glPolyonMode if available (OpenGL)
if (m_state.renderStates.faceFilling != renderStates.faceFilling)
if (glPolygonMode && m_state.renderStates.faceFilling != renderStates.faceFilling)
{
glPolygonMode(GL_FRONT_AND_BACK, FaceFilling[states.faceFilling]);
glPolygonMode(GL_FRONT_AND_BACK, ToOpenGL(renderStates.faceFilling));
m_state.renderStates.faceFilling = renderStates.faceFilling;
}*/
}
if (renderStates.stencilTest)
{
@ -663,6 +661,12 @@ namespace Nz::GL
return true;
}
else if (function == "glPolygonMode")
{
constexpr std::size_t functionIndex = UnderlyingCast(FunctionIndex::glPolygonMode);
return loader.Load<PFNGLPOLYGONMODENVPROC, functionIndex>(glPolygonMode, "glPolygonModeNV", false, false);
}
return false;
}

View File

@ -54,6 +54,7 @@ namespace Nz
deviceInfo.name = physDevice.properties.deviceName;
deviceInfo.features.anisotropicFiltering = physDevice.features.samplerAnisotropy;
deviceInfo.features.nonSolidFaceFilling = physDevice.features.fillModeNonSolid;
deviceInfo.limits.minUniformBufferOffsetAlignment = physDevice.properties.limits.minUniformBufferOffsetAlignment;
@ -274,7 +275,7 @@ namespace Nz
VkValidationFeaturesEXT features = { VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT };
std::vector<VkValidationFeatureEnableEXT> enabledFeatures = {
std::array<VkValidationFeatureEnableEXT, 1> enabledFeatures = {
//VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT,
//VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT,
VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT