Merge branch 'OpenGL3-upgrade' into NDK

Conflicts:
	src/Nazara/Graphics/SkyboxBackground.cpp
	src/Nazara/Renderer/RenderTexture.cpp
	src/Nazara/Renderer/Renderer.cpp

Former-commit-id: e8914d4e32a689b7df365dca15a438f10722530c
This commit is contained in:
Lynix 2015-09-24 21:35:43 +02:00
commit 70ea6912e1
30 changed files with 185 additions and 1136 deletions

View File

@ -107,20 +107,10 @@ enum nzPixelBufferType
enum nzRendererCap enum nzRendererCap
{ {
nzRendererCap_AnisotropicFilter, nzRendererCap_AnisotropicFilter,
nzRendererCap_ConditionalRendering,
nzRendererCap_FP64, nzRendererCap_FP64,
nzRendererCap_HardwareBuffer,
nzRendererCap_Instancing, nzRendererCap_Instancing,
nzRendererCap_MultipleRenderTargets,
nzRendererCap_OcclusionQuery,
nzRendererCap_PixelBufferObject,
nzRendererCap_RenderTexture,
nzRendererCap_Texture3D,
nzRendererCap_TextureCubemap,
nzRendererCap_TextureMulti,
nzRendererCap_TextureNPOT,
nzRendererCap_Max = nzRendererCap_TextureNPOT nzRendererCap_Max = nzRendererCap_Instancing
}; };
enum nzRendererBufferFlags enum nzRendererBufferFlags

View File

@ -29,7 +29,6 @@ class NAZARA_RENDERER_API NzGpuQuery : NzNonCopyable
unsigned int GetOpenGLID() const; unsigned int GetOpenGLID() const;
static bool IsModeSupported(nzGpuQueryMode mode); static bool IsModeSupported(nzGpuQueryMode mode);
static bool IsSupported();
private: private:
nzGpuQueryMode m_mode; nzGpuQueryMode m_mode;

View File

@ -32,23 +32,15 @@ namespace GLX
enum nzOpenGLExtension enum nzOpenGLExtension
{ {
nzOpenGLExtension_AnisotropicFilter, nzOpenGLExtension_AnisotropicFilter,
nzOpenGLExtension_ConditionalRender,
nzOpenGLExtension_DebugOutput, nzOpenGLExtension_DebugOutput,
nzOpenGLExtension_DrawInstanced,
nzOpenGLExtension_FP64, nzOpenGLExtension_FP64,
nzOpenGLExtension_FrameBufferObject,
nzOpenGLExtension_GetProgramBinary, nzOpenGLExtension_GetProgramBinary,
nzOpenGLExtension_InstancedArray,
nzOpenGLExtension_PixelBufferObject,
nzOpenGLExtension_SamplerObjects,
nzOpenGLExtension_SeparateShaderObjects, nzOpenGLExtension_SeparateShaderObjects,
nzOpenGLExtension_Shader_ImageLoadStore, nzOpenGLExtension_Shader_ImageLoadStore,
nzOpenGLExtension_TextureArray,
nzOpenGLExtension_TextureCompression_s3tc, nzOpenGLExtension_TextureCompression_s3tc,
nzOpenGLExtension_TextureStorage, nzOpenGLExtension_TextureStorage,
nzOpenGLExtension_VertexArrayObjects,
nzOpenGLExtension_Max = nzOpenGLExtension_VertexArrayObjects nzOpenGLExtension_Max = nzOpenGLExtension_TextureStorage
}; };
class NzContext; class NzContext;

View File

@ -43,7 +43,6 @@ class NAZARA_RENDERER_API NzRenderBuffer : public NzRefCounted, NzNonCopyable
bool IsValid() const; bool IsValid() const;
static bool IsSupported();
template<typename... Args> static NzRenderBufferRef New(Args&&... args); template<typename... Args> static NzRenderBufferRef New(Args&&... args);
// Signals: // Signals:

View File

@ -61,7 +61,6 @@ class NAZARA_RENDERER_API NzRenderTexture : public NzRenderTarget, NzNonCopyable
static inline void Blit(NzRenderTexture* src, NzRenderTexture* dst, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false); static inline void Blit(NzRenderTexture* src, NzRenderTexture* dst, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false);
static void Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false); static void Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers = nzRendererBuffer_Color | nzRendererBuffer_Depth | nzRendererBuffer_Stencil, bool bilinearFilter = false);
static bool IsSupported();
protected: protected:
bool Activate() const override; bool Activate() const override;

View File

@ -102,7 +102,6 @@ class NAZARA_RENDERER_API NzTexture : public NzAbstractImage, public NzRefCounte
// Fonctions OpenGL // Fonctions OpenGL
unsigned int GetOpenGLID() const; unsigned int GetOpenGLID() const;
static unsigned int GetValidSize(unsigned int size);
static bool IsFormatSupported(nzPixelFormat format); static bool IsFormatSupported(nzPixelFormat format);
static bool IsMipmappingSupported(); static bool IsMipmappingSupported();
static bool IsTypeSupported(nzImageType type); static bool IsTypeSupported(nzImageType type);

View File

@ -8,27 +8,16 @@
#include <Nazara/Renderer/Renderer.hpp> #include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Graphics/Debug.hpp> #include <Nazara/Graphics/Debug.hpp>
NzAbstractRenderTechnique::NzAbstractRenderTechnique() NzAbstractRenderTechnique::NzAbstractRenderTechnique() :
m_instancingEnabled(true)
{ {
#ifdef NAZARA_DEBUG
if (!NzRenderer::IsInitialized())
{
NazaraError("NazaraRenderer is not initialized");
return;
}
#endif
m_instancingEnabled = NzRenderer::HasCapability(nzRendererCap_Instancing);
} }
NzAbstractRenderTechnique::~NzAbstractRenderTechnique() = default; NzAbstractRenderTechnique::~NzAbstractRenderTechnique() = default;
void NzAbstractRenderTechnique::EnableInstancing(bool instancing) void NzAbstractRenderTechnique::EnableInstancing(bool instancing)
{ {
if (NzRenderer::HasCapability(nzRendererCap_Instancing)) m_instancingEnabled = instancing;
m_instancingEnabled = instancing;
else if (instancing)
NazaraError("NazaraRenderer does not support instancing");
} }
NzString NzAbstractRenderTechnique::GetName() const NzString NzAbstractRenderTechnique::GetName() const

View File

@ -395,12 +395,8 @@ void NzDeferredRenderTechnique::SetPass(nzRenderPassType relativeTo, int positio
bool NzDeferredRenderTechnique::IsSupported() bool NzDeferredRenderTechnique::IsSupported()
{ {
// On ne va pas s'embêter à écrire un Deferred Renderer qui ne passe pas par le MRT, ce serait trop lent pour servir... // Depuis qu'OpenGL 3.3 est la version minimale, le Renderer supporte ce qu'il faut, mais par acquis de conscience...
return NzOpenGL::GetGLSLVersion() >= 140 && // On ne va pas s'embêter non plus avec le mode de compatibilité return NzRenderer::GetMaxColorAttachments() >= 4 && NzRenderer::GetMaxRenderTargets() >= 4;
NzRenderer::HasCapability(nzRendererCap_RenderTexture) &&
NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets) &&
NzRenderer::GetMaxColorAttachments() >= 4 &&
NzRenderer::GetMaxRenderTargets() >= 4;
} }
bool NzDeferredRenderTechnique::Resize(const NzVector2ui& dimensions) const bool NzDeferredRenderTechnique::Resize(const NzVector2ui& dimensions) const

View File

@ -16,21 +16,22 @@
namespace namespace
{ {
const nzUInt8 r_coreFragmentShader[] = { const nzUInt8 r_basicFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/core.frag.h> #include <Nazara/Graphics/Resources/Shaders/Basic/core.frag.h>
}; };
const nzUInt8 r_coreVertexShader[] = { const nzUInt8 r_basicVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/core.vert.h> #include <Nazara/Graphics/Resources/Shaders/Basic/core.vert.h>
}; };
const nzUInt8 r_compatibilityFragmentShader[] = { const nzUInt8 r_phongLightingFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.frag.h> #include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h>
}; };
const nzUInt8 r_compatibilityVertexShader[] = { const nzUInt8 r_phongLightingVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.vert.h> #include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h>
}; };
} }
bool NzMaterialParams::IsValid() const bool NzMaterialParams::IsValid() const
@ -722,24 +723,12 @@ bool NzMaterial::Initialize()
return false; return false;
} }
bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140);
// Basic shader // Basic shader
{ {
NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New(); NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New();
NzString fragmentShader; NzString fragmentShader(reinterpret_cast<const char*>(r_basicFragmentShader), sizeof(r_basicFragmentShader));
NzString vertexShader; NzString vertexShader(reinterpret_cast<const char*>(r_basicVertexShader), sizeof(r_basicVertexShader));
if (glsl140)
{
fragmentShader.Set(reinterpret_cast<const char*>(r_coreFragmentShader), sizeof(r_coreFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(r_coreVertexShader), sizeof(r_coreVertexShader));
}
else
{
fragmentShader.Set(reinterpret_cast<const char*>(r_compatibilityFragmentShader), sizeof(r_compatibilityFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(r_compatibilityVertexShader), sizeof(r_compatibilityVertexShader));
}
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING"); uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_INSTANCING FLAG_VERTEXCOLOR TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH"); uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_INSTANCING FLAG_VERTEXCOLOR TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
@ -751,34 +740,8 @@ bool NzMaterial::Initialize()
{ {
NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New(); NzUberShaderPreprocessorRef uberShader = NzUberShaderPreprocessor::New();
NzString fragmentShader; NzString fragmentShader(reinterpret_cast<const char*>(r_phongLightingFragmentShader), sizeof(r_phongLightingFragmentShader));
NzString vertexShader; NzString vertexShader(reinterpret_cast<const char*>(r_phongLightingVertexShader), sizeof(r_phongLightingVertexShader));
if (glsl140)
{
const nzUInt8 coreFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h>
};
const nzUInt8 coreVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h>
};
fragmentShader.Set(reinterpret_cast<const char*>(coreFragmentShader), sizeof(coreFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(coreVertexShader), sizeof(coreVertexShader));
}
else
{
const nzUInt8 compatibilityFragmentShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.frag.h>
};
const nzUInt8 compatibilityVertexShader[] = {
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.vert.h>
};
fragmentShader.Set(reinterpret_cast<const char*>(compatibilityFragmentShader), sizeof(compatibilityFragmentShader));
vertexShader.Set(reinterpret_cast<const char*>(compatibilityVertexShader), sizeof(compatibilityVertexShader));
}
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING"); uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_DEFERRED FLAG_INSTANCING FLAG_VERTEXCOLOR COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH"); uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_DEFERRED FLAG_INSTANCING FLAG_VERTEXCOLOR COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");

View File

@ -1,37 +0,0 @@
/********************Entrant********************/
varying vec2 vTexCoord;
varying vec4 vColor;
/********************Uniformes********************/
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
uniform vec2 InvTargetSize;
/********************Fonctions********************/
void main()
{
vec4 fragmentColor = MaterialDiffuse; * vColor;
#if AUTO_TEXCOORDS
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
#else
vec2 texCoord = vTexCoord;
#endif
#if DIFFUSE_MAPPING
fragmentColor *= texture2D(MaterialDiffuseMap, texCoord);
#endif
#if ALPHA_MAPPING
fragmentColor.a *= texture2D(MaterialAlphaMap, texCoord).r;
#endif
#if ALPHA_TEST
if (fragmentColor.a < MaterialAlphaThreshold)
discard;
#endif
gl_FragColor = fragmentColor;
}

View File

@ -1 +0,0 @@
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,118,97,114,121,105,110,103,32,118,101,99,52,32,118,67,111,108,111,114,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,32,42,32,118,67,111,108,111,114,59,13,10,13,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,35,101,108,115,101,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,9,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,13,10,125,

View File

@ -1,99 +0,0 @@
/********************Entrant********************/
#if FLAG_BILLBOARD
varying vec3 InstanceData0; // center
varying vec4 InstanceData1; // size | sin cos
varying vec4 InstanceData2; // color
#else
varying mat4 InstanceData0;
#endif
varying vec4 VertexColor;
varying vec3 VertexPosition;
varying vec2 VertexTexCoord;
/********************Sortant********************/
varying vec2 vTexCoord;
varying vec4 vColor;
/********************Uniformes********************/
uniform float VertexDepth;
uniform mat4 ViewProjMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_VERTEXCOLOR
vec4 color = VertexColor;
#else
vec4 color = vec4(1.0);
#endif
vec2 texCoords;
#if FLAG_BILLBOARD
#if FLAG_INSTANCING
vec3 billboardCenter = InstanceData0;
vec2 billboardSize = InstanceData1.xy;
vec2 billboardSinCos = InstanceData1.zw;
vec4 billboardColor = InstanceData2;
vec2 rotatedPosition;
rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x;
rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
color = billboardColor;
texCoords = VertexPosition.xy + vec2(0.5, 0.5);
#else
vec2 billboardCorner = VertexTexCoord - vec2(0.5, 0.5);
vec2 billboardSize = VertexUserdata0.xy;
vec2 billboardSinCos = VertexUserdata0.zw;
vec2 rotatedPosition;
rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x;
rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
#else
#if FLAG_INSTANCING
#if TRANSFORM
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
#endif
#endif
#else
#if TRANSFORM
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = vec4(VertexPosition, 1.0);
#endif
#endif
#endif
texCoords = VertexTexCoord;
#endif
vColor = color;
#if TEXTURE_MAPPING
vTexCoord = vec2(texCoords);
#endif
}

File diff suppressed because one or more lines are too long

View File

@ -1,237 +0,0 @@
#if FLAG_DEFERRED
#error Deferred Shading is not supported by compatibility shaders
#endif
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
#define LIGHT_SPOT 2
/********************Entrant********************/
varying mat3 vLightToWorld;
varying vec3 vNormal;
varying vec2 vTexCoord;
varying vec3 vWorldPos;
varying vec4 vColor;
/********************Uniformes********************/
struct Light
{
int type;
vec4 color;
vec2 factors;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
};
// Lumières
uniform Light Lights[3];
// Matériau
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialAmbient;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
uniform sampler2D MaterialEmissiveMap;
uniform sampler2D MaterialNormalMap;
uniform float MaterialShininess;
uniform vec4 MaterialSpecular;
uniform sampler2D MaterialSpecularMap;
// Autres
uniform vec3 EyePosition;
uniform vec4 SceneAmbient;
/********************Fonctions********************/
void main()
{
vec4 diffuseColor = MaterialDiffuse * vColor;
#if AUTO_TEXCOORDS
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
#else
vec2 texCoord = vTexCoord;
#endif
#if DIFFUSE_MAPPING
diffuseColor *= texture(MaterialDiffuseMap, texCoord);
#endif
#if ALPHA_MAPPING
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
#endif
#if ALPHA_TEST
if (diffuseColor.a < MaterialAlphaThreshold)
discard;
#endif
#if LIGHTING
vec3 lightAmbient = vec3(0.0);
vec3 lightDiffuse = vec3(0.0);
vec3 lightSpecular = vec3(0.0);
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
#else
vec3 normal = normalize(vNormal);
#endif
if (MaterialShininess > 0.0)
{
vec3 eyeVec = normalize(EyePosition - vWorldPos);
for (int i = 0; i < 3; ++i)
{
if (Lights[i].type == LIGHT_DIRECTIONAL)
{
vec3 lightDir = -Lights[i].parameters1.xyz;
// Ambient
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += specularFactor * Lights[i].color.rgb;
}
else if (Lights[i].type == LIGHT_POINT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * Lights[i].color.rgb;
}
else if (Lights[i].type == LIGHT_SPOT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * Lights[i].color.rgb;
}
}
}
else
{
for (int i = 0; i < 3; ++i)
{
if (Lights[i].type == LIGHT_DIRECTIONAL)
{
vec3 lightDir = -Lights[i].parameters1.xyz;
// Ambient
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
}
else if (Lights[i].type == LIGHT_POINT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
}
else if (Lights[i].type == LIGHT_SPOT)
{
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
float lightDirLength = length(lightDir);
lightDir /= lightDirLength; // Normalisation
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
// Ambient
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
float outerAngle = Lights[i].parameters3.y;
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
}
}
}
lightSpecular *= MaterialSpecular.rgb;
#if SPECULAR_MAPPING
lightSpecular *= texture(MaterialSpecularMap, texCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
#endif
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
#if EMISSIVE_MAPPING
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, texCoord).rgb;
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
#else
RenderTarget0 = fragmentColor;
#endif // EMISSIVE_MAPPING
#else
RenderTarget0 = diffuseColor;
#endif // LIGHTING
}

File diff suppressed because one or more lines are too long

View File

@ -1,135 +0,0 @@
/********************Entrant********************/
#if FLAG_BILLBOARD
varying vec3 InstanceData0; // center
varying vec4 InstanceData1; // size | sin cos
varying vec4 InstanceData2; // color
#else
varying mat4 InstanceData0;
#endif
varying vec3 VertexPosition;
varying vec3 VertexNormal;
varying vec3 VertexTangent;
varying vec2 VertexTexCoord;
/********************Sortant********************/
varying mat3 vLightToWorld;
varying vec3 vNormal;
varying vec2 vTexCoord;
varying vec3 vWorldPos;
varying vec4 vColor;
/********************Uniformes********************/
uniform float VertexDepth;
uniform mat4 ViewProjMatrix;
uniform mat4 WorldMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_VERTEXCOLOR
vec4 color = VertexColor;
#else
vec4 color = vec4(1.0);
#endif
vec2 texCoords;
#if FLAG_BILLBOARD
#if FLAG_INSTANCING
vec3 billboardCenter = InstanceData0;
vec2 billboardSize = InstanceData1.xy;
vec2 billboardSinCos = InstanceData1.zw;
vec4 billboardColor = InstanceData2;
vec2 rotatedPosition;
rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x;
rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
color = billboardColor;
texCoords = VertexPosition.xy + vec2(0.5, 0.5);
#else
vec2 billboardCorner = VertexTexCoord - vec2(0.5, 0.5);
vec2 billboardSize = VertexUserdata0.xy;
vec2 billboardSinCos = VertexUserdata0.zw;
vec2 rotatedPosition;
rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x;
rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
#else
#if FLAG_INSTANCING
#if TRANSFORM
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
#endif
#endif
#else
#if TRANSFORM
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = vec4(VertexPosition, 1.0);
#endif
#endif
#endif
texCoords = VertexTexCoord;
#endif
vColor = color;
#if LIGHTING
#if FLAG_INSTANCING
mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);
#else
mat3 rotationMatrix = mat3(WorldMatrix[0].xyz, WorldMatrix[1].xyz, WorldMatrix[2].xyz);
#endif
#if NORMAL_MAPPING
vec3 binormal = cross(VertexNormal, VertexTangent);
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
vLightToWorld[1] = normalize(rotationMatrix * binormal);
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
#else
vNormal = normalize(rotationMatrix * VertexNormal);
#endif
#endif
#if TEXTURE_MAPPING
vTexCoord = vec2(texCoords);
#endif
#if LIGHTING && PARALLAX_MAPPING
vViewDir = EyePosition - VertexPosition;
vViewDir *= vLightToWorld;
#endif
#if LIGHTING && !FLAG_DEFERRED
#if FLAG_INSTANCING
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
#else
vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));
#endif
#endif
}

File diff suppressed because one or more lines are too long

View File

@ -156,4 +156,4 @@ void NzSkyboxBackground::Uninitialize()
s_indexBuffer.Reset(); s_indexBuffer.Reset();
s_shader.Reset(); s_shader.Reset();
s_vertexBuffer.Reset(); s_vertexBuffer.Reset();
} }

View File

@ -11,20 +11,12 @@
#include <stdexcept> #include <stdexcept>
#include <Nazara/Renderer/Debug.hpp> #include <Nazara/Renderer/Debug.hpp>
NzGpuQuery::NzGpuQuery() : NzGpuQuery::NzGpuQuery()
m_id(0)
{ {
if (IsSupported()) NzContext::EnsureContext();
{
NzContext::EnsureContext();
glGenQueries(1, reinterpret_cast<GLuint*>(&m_id)); m_id = 0;
} glGenQueries(1, reinterpret_cast<GLuint*>(&m_id));
else
{
NazaraError("Occlusion queries not supported");
return;
}
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (!m_id) if (!m_id)
@ -110,15 +102,13 @@ bool NzGpuQuery::IsModeSupported(nzGpuQueryMode mode)
{ {
switch (mode) switch (mode)
{ {
case nzGpuQueryMode_AnySamplesPassed:
case nzGpuQueryMode_TimeElapsed:
return NzOpenGL::GetVersion() >= 330;
case nzGpuQueryMode_AnySamplesPassedConservative: case nzGpuQueryMode_AnySamplesPassedConservative:
return NzOpenGL::GetVersion() >= 430; return NzOpenGL::GetVersion() >= 430;
case nzGpuQueryMode_AnySamplesPassed:
case nzGpuQueryMode_PrimitiveGenerated: case nzGpuQueryMode_PrimitiveGenerated:
case nzGpuQueryMode_SamplesPassed: case nzGpuQueryMode_SamplesPassed:
case nzGpuQueryMode_TimeElapsed:
case nzGpuQueryMode_TransformFeedbackPrimitivesWritten: case nzGpuQueryMode_TransformFeedbackPrimitivesWritten:
return true; return true;
} }
@ -126,8 +116,3 @@ bool NzGpuQuery::IsModeSupported(nzGpuQueryMode mode)
NazaraError("Gpu Query mode not handled (0x" + NzString::Number(mode, 16) + ')'); NazaraError("Gpu Query mode not handled (0x" + NzString::Number(mode, 16) + ')');
return false; return false;
} }
bool NzGpuQuery::IsSupported()
{
return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery);
}

View File

@ -800,10 +800,10 @@ bool NzOpenGL::Initialize()
NazaraDebug("OpenGL version: " + NzString::Number(major) + '.' + NzString::Number(minor)); NazaraDebug("OpenGL version: " + NzString::Number(major) + '.' + NzString::Number(minor));
// Le moteur ne fonctionnera pas avec OpenGL 1.x, autant s'arrêter là si c'est le cas // Le moteur nécessite OpenGL 3.3, autant s'arrêter là si ce n'est pas le cas
if (s_openglVersion < 200) if (s_openglVersion < 330)
{ {
NazaraError("OpenGL " + NzString::Number(major) + '.' + NzString::Number(minor) + " detected (2.0 required). Please upgrade your drivers or your video card"); NazaraError("OpenGL " + NzString::Number(major) + '.' + NzString::Number(minor) + " detected (3.3 required). Please upgrade your drivers or your video card");
return false; return false;
} }
@ -832,10 +832,8 @@ bool NzOpenGL::Initialize()
s_glslVersion = major*100 + minor*10; // GLSL 3.3 => 330 s_glslVersion = major*100 + minor*10; // GLSL 3.3 => 330
// Possible uniquement dans le cas où le GLSL vient d'une extension d'OpenGL 1 // Normalement rejeté il y a un moment déjà, mais on doit s'attendre à tout de la part d'un driver...
// Ce qui est rejeté il y a un moment déjà, mais on doit s'attendre à tout de la part d'un driver... if (s_glslVersion < 330)
// (Exemple: Un driver OpenGL 2 mais ne supportant que le GLSL 100)
if (s_glslVersion < 110)
{ {
NazaraError("GLSL version is too low, please upgrade your drivers or your video card"); NazaraError("GLSL version is too low, please upgrade your drivers or your video card");
return false; return false;
@ -857,18 +855,26 @@ bool NzOpenGL::Initialize()
{ {
glActiveTexture = reinterpret_cast<PFNGLACTIVETEXTUREPROC>(LoadEntry("glActiveTexture")); glActiveTexture = reinterpret_cast<PFNGLACTIVETEXTUREPROC>(LoadEntry("glActiveTexture"));
glAttachShader = reinterpret_cast<PFNGLATTACHSHADERPROC>(LoadEntry("glAttachShader")); glAttachShader = reinterpret_cast<PFNGLATTACHSHADERPROC>(LoadEntry("glAttachShader"));
glBeginConditionalRender = reinterpret_cast<PFNGLBEGINCONDITIONALRENDERPROC>(LoadEntry("glBeginConditionalRender"));
glBeginQuery = reinterpret_cast<PFNGLBEGINQUERYPROC>(LoadEntry("glBeginQuery")); glBeginQuery = reinterpret_cast<PFNGLBEGINQUERYPROC>(LoadEntry("glBeginQuery"));
glBindAttribLocation = reinterpret_cast<PFNGLBINDATTRIBLOCATIONPROC>(LoadEntry("glBindAttribLocation")); glBindAttribLocation = reinterpret_cast<PFNGLBINDATTRIBLOCATIONPROC>(LoadEntry("glBindAttribLocation"));
glBindBuffer = reinterpret_cast<PFNGLBINDBUFFERPROC>(LoadEntry("glBindBuffer")); glBindBuffer = reinterpret_cast<PFNGLBINDBUFFERPROC>(LoadEntry("glBindBuffer"));
glBindFragDataLocation = reinterpret_cast<PFNGLBINDFRAGDATALOCATIONPROC>(LoadEntry("glBindFragDataLocation"));
glBindFramebuffer = reinterpret_cast<PFNGLBINDFRAMEBUFFERPROC>(LoadEntry("glBindFramebuffer"));
glBindRenderbuffer = reinterpret_cast<PFNGLBINDRENDERBUFFERPROC>(LoadEntry("glBindRenderbuffer"));
glBindSampler = reinterpret_cast<PFNGLBINDSAMPLERPROC>(LoadEntry("glBindSampler"));
glBindTexture = reinterpret_cast<PFNGLBINDTEXTUREPROC>(LoadEntry("glBindTexture")); glBindTexture = reinterpret_cast<PFNGLBINDTEXTUREPROC>(LoadEntry("glBindTexture"));
glBindVertexArray = reinterpret_cast<PFNGLBINDVERTEXARRAYPROC>(LoadEntry("glBindVertexArray"));
glBlendFunc = reinterpret_cast<PFNGLBLENDFUNCPROC>(LoadEntry("glBlendFunc")); glBlendFunc = reinterpret_cast<PFNGLBLENDFUNCPROC>(LoadEntry("glBlendFunc"));
glBlendFuncSeparate = reinterpret_cast<PFNGLBLENDFUNCSEPARATEPROC>(LoadEntry("glBlendFuncSeparate")); glBlendFuncSeparate = reinterpret_cast<PFNGLBLENDFUNCSEPARATEPROC>(LoadEntry("glBlendFuncSeparate"));
glBlitFramebuffer = reinterpret_cast<PFNGLBLITFRAMEBUFFERPROC>(LoadEntry("glBlitFramebuffer"));
glBufferData = reinterpret_cast<PFNGLBUFFERDATAPROC>(LoadEntry("glBufferData")); glBufferData = reinterpret_cast<PFNGLBUFFERDATAPROC>(LoadEntry("glBufferData"));
glBufferSubData = reinterpret_cast<PFNGLBUFFERSUBDATAPROC>(LoadEntry("glBufferSubData")); glBufferSubData = reinterpret_cast<PFNGLBUFFERSUBDATAPROC>(LoadEntry("glBufferSubData"));
glClear = reinterpret_cast<PFNGLCLEARPROC>(LoadEntry("glClear")); glClear = reinterpret_cast<PFNGLCLEARPROC>(LoadEntry("glClear"));
glClearColor = reinterpret_cast<PFNGLCLEARCOLORPROC>(LoadEntry("glClearColor")); glClearColor = reinterpret_cast<PFNGLCLEARCOLORPROC>(LoadEntry("glClearColor"));
glClearDepth = reinterpret_cast<PFNGLCLEARDEPTHPROC>(LoadEntry("glClearDepth")); glClearDepth = reinterpret_cast<PFNGLCLEARDEPTHPROC>(LoadEntry("glClearDepth"));
glClearStencil = reinterpret_cast<PFNGLCLEARSTENCILPROC>(LoadEntry("glClearStencil")); glClearStencil = reinterpret_cast<PFNGLCLEARSTENCILPROC>(LoadEntry("glClearStencil"));
glCheckFramebufferStatus = reinterpret_cast<PFNGLCHECKFRAMEBUFFERSTATUSPROC>(LoadEntry("glCheckFramebufferStatus"));
glCreateProgram = reinterpret_cast<PFNGLCREATEPROGRAMPROC>(LoadEntry("glCreateProgram")); glCreateProgram = reinterpret_cast<PFNGLCREATEPROGRAMPROC>(LoadEntry("glCreateProgram"));
glCreateShader = reinterpret_cast<PFNGLCREATESHADERPROC>(LoadEntry("glCreateShader")); glCreateShader = reinterpret_cast<PFNGLCREATESHADERPROC>(LoadEntry("glCreateShader"));
glColorMask = reinterpret_cast<PFNGLCOLORMASKPROC>(LoadEntry("glColorMask")); glColorMask = reinterpret_cast<PFNGLCOLORMASKPROC>(LoadEntry("glColorMask"));
@ -876,25 +882,43 @@ bool NzOpenGL::Initialize()
glCompileShader = reinterpret_cast<PFNGLCOMPILESHADERPROC>(LoadEntry("glCompileShader")); glCompileShader = reinterpret_cast<PFNGLCOMPILESHADERPROC>(LoadEntry("glCompileShader"));
glCopyTexSubImage2D = reinterpret_cast<PFNGLCOPYTEXSUBIMAGE2DPROC>(LoadEntry("glCopyTexSubImage2D")); glCopyTexSubImage2D = reinterpret_cast<PFNGLCOPYTEXSUBIMAGE2DPROC>(LoadEntry("glCopyTexSubImage2D"));
glDeleteBuffers = reinterpret_cast<PFNGLDELETEBUFFERSPROC>(LoadEntry("glDeleteBuffers")); glDeleteBuffers = reinterpret_cast<PFNGLDELETEBUFFERSPROC>(LoadEntry("glDeleteBuffers"));
glDeleteFramebuffers = reinterpret_cast<PFNGLDELETEFRAMEBUFFERSPROC>(LoadEntry("glDeleteFramebuffers"));
glDeleteQueries = reinterpret_cast<PFNGLDELETEQUERIESPROC>(LoadEntry("glDeleteQueries")); glDeleteQueries = reinterpret_cast<PFNGLDELETEQUERIESPROC>(LoadEntry("glDeleteQueries"));
glDeleteProgram = reinterpret_cast<PFNGLDELETEPROGRAMPROC>(LoadEntry("glDeleteProgram")); glDeleteProgram = reinterpret_cast<PFNGLDELETEPROGRAMPROC>(LoadEntry("glDeleteProgram"));
glDeleteRenderbuffers = reinterpret_cast<PFNGLDELETERENDERBUFFERSPROC>(LoadEntry("glDeleteRenderbuffers"));
glDeleteSamplers = reinterpret_cast<PFNGLDELETESAMPLERSPROC>(LoadEntry("glDeleteSamplers"));
glDeleteShader = reinterpret_cast<PFNGLDELETESHADERPROC>(LoadEntry("glDeleteShader")); glDeleteShader = reinterpret_cast<PFNGLDELETESHADERPROC>(LoadEntry("glDeleteShader"));
glDeleteTextures = reinterpret_cast<PFNGLDELETETEXTURESPROC>(LoadEntry("glDeleteTextures")); glDeleteTextures = reinterpret_cast<PFNGLDELETETEXTURESPROC>(LoadEntry("glDeleteTextures"));
glDeleteVertexArrays = reinterpret_cast<PFNGLDELETEVERTEXARRAYSPROC>(LoadEntry("glDeleteVertexArrays"));
glDepthFunc = reinterpret_cast<PFNGLDEPTHFUNCPROC>(LoadEntry("glDepthFunc")); glDepthFunc = reinterpret_cast<PFNGLDEPTHFUNCPROC>(LoadEntry("glDepthFunc"));
glDepthMask = reinterpret_cast<PFNGLDEPTHMASKPROC>(LoadEntry("glDepthMask")); glDepthMask = reinterpret_cast<PFNGLDEPTHMASKPROC>(LoadEntry("glDepthMask"));
glDisable = reinterpret_cast<PFNGLDISABLEPROC>(LoadEntry("glDisable")); glDisable = reinterpret_cast<PFNGLDISABLEPROC>(LoadEntry("glDisable"));
glDisableVertexAttribArray = reinterpret_cast<PFNGLDISABLEVERTEXATTRIBARRAYPROC>(LoadEntry("glDisableVertexAttribArray")); glDisableVertexAttribArray = reinterpret_cast<PFNGLDISABLEVERTEXATTRIBARRAYPROC>(LoadEntry("glDisableVertexAttribArray"));
glDrawArrays = reinterpret_cast<PFNGLDRAWARRAYSPROC>(LoadEntry("glDrawArrays")); glDrawArrays = reinterpret_cast<PFNGLDRAWARRAYSPROC>(LoadEntry("glDrawArrays"));
glDrawArraysInstanced = reinterpret_cast<PFNGLDRAWARRAYSINSTANCEDPROC>(LoadEntry("glDrawArraysInstanced"));
glDrawBuffer = reinterpret_cast<PFNGLDRAWBUFFERPROC>(LoadEntry("glDrawBuffer")); glDrawBuffer = reinterpret_cast<PFNGLDRAWBUFFERPROC>(LoadEntry("glDrawBuffer"));
glDrawBuffers = reinterpret_cast<PFNGLDRAWBUFFERSPROC>(LoadEntry("glDrawBuffers")); glDrawBuffers = reinterpret_cast<PFNGLDRAWBUFFERSPROC>(LoadEntry("glDrawBuffers"));
glDrawElements = reinterpret_cast<PFNGLDRAWELEMENTSPROC>(LoadEntry("glDrawElements")); glDrawElements = reinterpret_cast<PFNGLDRAWELEMENTSPROC>(LoadEntry("glDrawElements"));
glDrawElementsInstanced = reinterpret_cast<PFNGLDRAWELEMENTSINSTANCEDPROC>(LoadEntry("glDrawElementsInstanced"));
glEnable = reinterpret_cast<PFNGLENABLEPROC>(LoadEntry("glEnable")); glEnable = reinterpret_cast<PFNGLENABLEPROC>(LoadEntry("glEnable"));
glEnableVertexAttribArray = reinterpret_cast<PFNGLENABLEVERTEXATTRIBARRAYPROC>(LoadEntry("glEnableVertexAttribArray")); glEnableVertexAttribArray = reinterpret_cast<PFNGLENABLEVERTEXATTRIBARRAYPROC>(LoadEntry("glEnableVertexAttribArray"));
glEndConditionalRender = reinterpret_cast<PFNGLENDCONDITIONALRENDERPROC>(LoadEntry("glEndConditionalRender"));
glEndQuery = reinterpret_cast<PFNGLENDQUERYPROC>(LoadEntry("glEndQuery")); glEndQuery = reinterpret_cast<PFNGLENDQUERYPROC>(LoadEntry("glEndQuery"));
glFlush = reinterpret_cast<PFNGLFLUSHPROC>(LoadEntry("glFlush")); glFlush = reinterpret_cast<PFNGLFLUSHPROC>(LoadEntry("glFlush"));
glFramebufferRenderbuffer = reinterpret_cast<PFNGLFRAMEBUFFERRENDERBUFFERPROC>(LoadEntry("glFramebufferRenderbuffer"));
glFramebufferTexture = reinterpret_cast<PFNGLFRAMEBUFFERTEXTUREPROC>(LoadEntry("glFramebufferTexture"));
glFramebufferTexture1D = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE1DPROC>(LoadEntry("glFramebufferTexture1D"));
glFramebufferTexture2D = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DPROC>(LoadEntry("glFramebufferTexture2D"));
glFramebufferTexture3D = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE3DPROC>(LoadEntry("glFramebufferTexture3D"));
glFramebufferTextureLayer = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURELAYERPROC>(LoadEntry("glFramebufferTextureLayer"));
glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPPROC>(LoadEntry("glGenerateMipmap"));
glGenBuffers = reinterpret_cast<PFNGLGENBUFFERSPROC>(LoadEntry("glGenBuffers")); glGenBuffers = reinterpret_cast<PFNGLGENBUFFERSPROC>(LoadEntry("glGenBuffers"));
glGenFramebuffers = reinterpret_cast<PFNGLGENFRAMEBUFFERSPROC>(LoadEntry("glGenFramebuffers"));
glGenQueries = reinterpret_cast<PFNGLGENQUERIESPROC>(LoadEntry("glGenQueries")); glGenQueries = reinterpret_cast<PFNGLGENQUERIESPROC>(LoadEntry("glGenQueries"));
glGenRenderbuffers = reinterpret_cast<PFNGLGENRENDERBUFFERSPROC>(LoadEntry("glGenRenderbuffers"));
glGenSamplers = reinterpret_cast<PFNGLGENSAMPLERSPROC>(LoadEntry("glGenSamplers"));
glGenTextures = reinterpret_cast<PFNGLGENTEXTURESPROC>(LoadEntry("glGenTextures")); glGenTextures = reinterpret_cast<PFNGLGENTEXTURESPROC>(LoadEntry("glGenTextures"));
glGenVertexArrays = reinterpret_cast<PFNGLGENVERTEXARRAYSPROC>(LoadEntry("glGenVertexArrays"));
glGetActiveUniform = reinterpret_cast<PFNGLGETACTIVEUNIFORMPROC>(LoadEntry("glGetActiveUniform")); glGetActiveUniform = reinterpret_cast<PFNGLGETACTIVEUNIFORMPROC>(LoadEntry("glGetActiveUniform"));
glGetBooleanv = reinterpret_cast<PFNGLGETBOOLEANVPROC>(LoadEntry("glGetBooleanv")); glGetBooleanv = reinterpret_cast<PFNGLGETBOOLEANVPROC>(LoadEntry("glGetBooleanv"));
glGetBufferParameteriv = reinterpret_cast<PFNGLGETBUFFERPARAMETERIVPROC>(LoadEntry("glGetBufferParameteriv")); glGetBufferParameteriv = reinterpret_cast<PFNGLGETBUFFERPARAMETERIVPROC>(LoadEntry("glGetBufferParameteriv"));
@ -909,6 +933,7 @@ bool NzOpenGL::Initialize()
glGetShaderInfoLog = reinterpret_cast<PFNGLGETSHADERINFOLOGPROC>(LoadEntry("glGetShaderInfoLog")); glGetShaderInfoLog = reinterpret_cast<PFNGLGETSHADERINFOLOGPROC>(LoadEntry("glGetShaderInfoLog"));
glGetShaderiv = reinterpret_cast<PFNGLGETSHADERIVPROC>(LoadEntry("glGetShaderiv")); glGetShaderiv = reinterpret_cast<PFNGLGETSHADERIVPROC>(LoadEntry("glGetShaderiv"));
glGetShaderSource = reinterpret_cast<PFNGLGETSHADERSOURCEPROC>(LoadEntry("glGetShaderSource")); glGetShaderSource = reinterpret_cast<PFNGLGETSHADERSOURCEPROC>(LoadEntry("glGetShaderSource"));
glGetStringi = reinterpret_cast<PFNGLGETSTRINGIPROC>(LoadEntry("glGetStringi"));
glGetTexImage = reinterpret_cast<PFNGLGETTEXIMAGEPROC>(LoadEntry("glGetTexImage")); glGetTexImage = reinterpret_cast<PFNGLGETTEXIMAGEPROC>(LoadEntry("glGetTexImage"));
glGetTexLevelParameterfv = reinterpret_cast<PFNGLGETTEXLEVELPARAMETERFVPROC>(LoadEntry("glGetTexLevelParameterfv")); glGetTexLevelParameterfv = reinterpret_cast<PFNGLGETTEXLEVELPARAMETERFVPROC>(LoadEntry("glGetTexLevelParameterfv"));
glGetTexLevelParameteriv = reinterpret_cast<PFNGLGETTEXLEVELPARAMETERIVPROC>(LoadEntry("glGetTexLevelParameteriv")); glGetTexLevelParameteriv = reinterpret_cast<PFNGLGETTEXLEVELPARAMETERIVPROC>(LoadEntry("glGetTexLevelParameteriv"));
@ -919,10 +944,14 @@ bool NzOpenGL::Initialize()
glLineWidth = reinterpret_cast<PFNGLLINEWIDTHPROC>(LoadEntry("glLineWidth")); glLineWidth = reinterpret_cast<PFNGLLINEWIDTHPROC>(LoadEntry("glLineWidth"));
glLinkProgram = reinterpret_cast<PFNGLLINKPROGRAMPROC>(LoadEntry("glLinkProgram")); glLinkProgram = reinterpret_cast<PFNGLLINKPROGRAMPROC>(LoadEntry("glLinkProgram"));
glMapBuffer = reinterpret_cast<PFNGLMAPBUFFERPROC>(LoadEntry("glMapBuffer")); glMapBuffer = reinterpret_cast<PFNGLMAPBUFFERPROC>(LoadEntry("glMapBuffer"));
glMapBufferRange = reinterpret_cast<PFNGLMAPBUFFERRANGEPROC>(LoadEntry("glMapBufferRange"));
glPixelStorei = reinterpret_cast<PFNGLPIXELSTOREIPROC>(LoadEntry("glPixelStorei")); glPixelStorei = reinterpret_cast<PFNGLPIXELSTOREIPROC>(LoadEntry("glPixelStorei"));
glPointSize = reinterpret_cast<PFNGLPOINTSIZEPROC>(LoadEntry("glPointSize")); glPointSize = reinterpret_cast<PFNGLPOINTSIZEPROC>(LoadEntry("glPointSize"));
glPolygonMode = reinterpret_cast<PFNGLPOLYGONMODEPROC>(LoadEntry("glPolygonMode")); glPolygonMode = reinterpret_cast<PFNGLPOLYGONMODEPROC>(LoadEntry("glPolygonMode"));
glReadPixels = reinterpret_cast<PFNGLREADPIXELSPROC>(LoadEntry("glReadPixels")); glReadPixels = reinterpret_cast<PFNGLREADPIXELSPROC>(LoadEntry("glReadPixels"));
glRenderbufferStorage = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEPROC>(LoadEntry("glRenderbufferStorage"));
glSamplerParameterf = reinterpret_cast<PFNGLSAMPLERPARAMETERFPROC>(LoadEntry("glSamplerParameterf"));
glSamplerParameteri = reinterpret_cast<PFNGLSAMPLERPARAMETERIPROC>(LoadEntry("glSamplerParameteri"));
glScissor = reinterpret_cast<PFNGLSCISSORPROC>(LoadEntry("glScissor")); glScissor = reinterpret_cast<PFNGLSCISSORPROC>(LoadEntry("glScissor"));
glShaderSource = reinterpret_cast<PFNGLSHADERSOURCEPROC>(LoadEntry("glShaderSource")); glShaderSource = reinterpret_cast<PFNGLSHADERSOURCEPROC>(LoadEntry("glShaderSource"));
glStencilFunc = reinterpret_cast<PFNGLSTENCILFUNCPROC>(LoadEntry("glStencilFunc")); glStencilFunc = reinterpret_cast<PFNGLSTENCILFUNCPROC>(LoadEntry("glStencilFunc"));
@ -949,7 +978,9 @@ bool NzOpenGL::Initialize()
glUnmapBuffer = reinterpret_cast<PFNGLUNMAPBUFFERPROC>(LoadEntry("glUnmapBuffer")); glUnmapBuffer = reinterpret_cast<PFNGLUNMAPBUFFERPROC>(LoadEntry("glUnmapBuffer"));
glUseProgram = reinterpret_cast<PFNGLUSEPROGRAMPROC>(LoadEntry("glUseProgram")); glUseProgram = reinterpret_cast<PFNGLUSEPROGRAMPROC>(LoadEntry("glUseProgram"));
glVertexAttrib4f = reinterpret_cast<PFNGLVERTEXATTRIB4FPROC>(LoadEntry("glVertexAttrib4f")); glVertexAttrib4f = reinterpret_cast<PFNGLVERTEXATTRIB4FPROC>(LoadEntry("glVertexAttrib4f"));
glVertexAttribDivisor = reinterpret_cast<PFNGLVERTEXATTRIBDIVISORPROC>(LoadEntry("glVertexAttribDivisor"));
glVertexAttribPointer = reinterpret_cast<PFNGLVERTEXATTRIBPOINTERPROC>(LoadEntry("glVertexAttribPointer")); glVertexAttribPointer = reinterpret_cast<PFNGLVERTEXATTRIBPOINTERPROC>(LoadEntry("glVertexAttribPointer"));
glVertexAttribIPointer = reinterpret_cast<PFNGLVERTEXATTRIBIPOINTERPROC>(LoadEntry("glVertexAttribIPointer"));
glViewport = reinterpret_cast<PFNGLVIEWPORTPROC>(LoadEntry("glViewport")); glViewport = reinterpret_cast<PFNGLVIEWPORTPROC>(LoadEntry("glViewport"));
} }
catch (const std::exception& e) catch (const std::exception& e)
@ -961,16 +992,10 @@ bool NzOpenGL::Initialize()
/****************************************Extensions****************************************/ /****************************************Extensions****************************************/
// Fonctions optionnelles // Fonctions optionnelles
glBindFragDataLocation = reinterpret_cast<PFNGLBINDFRAGDATALOCATIONPROC>(LoadEntry("glBindFragDataLocation", false)); glBindFragDataLocation = reinterpret_cast<PFNGLBINDFRAGDATALOCATIONPROC>(LoadEntry("glBindFragDataLocation"));
if (!glBindFragDataLocation)
glBindFragDataLocation = reinterpret_cast<PFNGLBINDFRAGDATALOCATIONEXTPROC>(LoadEntry("glBindFragDataLocationEXT", false));
glDrawTexture = reinterpret_cast<PFNGLDRAWTEXTURENVPROC>(LoadEntry("glDrawTextureNV", false)); glDrawTexture = reinterpret_cast<PFNGLDRAWTEXTURENVPROC>(LoadEntry("glDrawTextureNV", false));
glFramebufferTexture = reinterpret_cast<PFNGLFRAMEBUFFERTEXTUREPROC>(LoadEntry("glFramebufferTexture", false));
glGetStringi = reinterpret_cast<PFNGLGETSTRINGIPROC>(LoadEntry("glGetStringi", false));
glInvalidateBufferData = reinterpret_cast<PFNGLINVALIDATEBUFFERDATAPROC>(LoadEntry("glInvalidateBufferData", false)); glInvalidateBufferData = reinterpret_cast<PFNGLINVALIDATEBUFFERDATAPROC>(LoadEntry("glInvalidateBufferData", false));
glMapBufferRange = reinterpret_cast<PFNGLMAPBUFFERRANGEPROC>(LoadEntry("glMapBufferRange", false));
glVertexAttribIPointer = reinterpret_cast<PFNGLVERTEXATTRIBIPOINTERPROC>(LoadEntry("glVertexAttribIPointer", false));
glVertexAttribLPointer = reinterpret_cast<PFNGLVERTEXATTRIBLPOINTERPROC>(LoadEntry("glVertexAttribLPointer", false)); glVertexAttribLPointer = reinterpret_cast<PFNGLVERTEXATTRIBLPOINTERPROC>(LoadEntry("glVertexAttribLPointer", false));
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
@ -985,8 +1010,7 @@ bool NzOpenGL::Initialize()
if (!glGetStringi || !LoadExtensions3()) if (!glGetStringi || !LoadExtensions3())
{ {
if (s_openglVersion >= 300) // Dans le cas contraire c'est normal NazaraWarning("Failed to load OpenGL 3 extension system, falling back to OpenGL 2 extension system...");
NazaraWarning("Failed to load OpenGL 3 extension system, switching to OpenGL 2 extension system...");
if (!LoadExtensionsString(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)))) if (!LoadExtensionsString(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))))
NazaraWarning("Failed to load extension system"); NazaraWarning("Failed to load extension system");
@ -1010,37 +1034,6 @@ bool NzOpenGL::Initialize()
// AnisotropicFilter // AnisotropicFilter
s_openGLextensions[nzOpenGLExtension_AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic"); s_openGLextensions[nzOpenGLExtension_AnisotropicFilter] = IsSupported("GL_EXT_texture_filter_anisotropic");
// ConditionalRender
if (s_openglVersion >= 300)
{
try
{
glBeginConditionalRender = reinterpret_cast<PFNGLBEGINCONDITIONALRENDERPROC>(LoadEntry("glBeginConditionalRender"));
glEndConditionalRender = reinterpret_cast<PFNGLENDCONDITIONALRENDERPROC>(LoadEntry("glEndConditionalRender"));
s_openGLextensions[nzOpenGLExtension_ConditionalRender] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load Conditional Render: " + NzString(e.what()));
}
}
if (!s_openGLextensions[nzOpenGLExtension_ConditionalRender] && IsSupported("GL_NV_conditional_render"))
{
try
{
glBeginConditionalRender = reinterpret_cast<PFNGLBEGINCONDITIONALRENDERPROC>(LoadEntry("glBeginConditionalRenderNV"));
glEndConditionalRender = reinterpret_cast<PFNGLENDCONDITIONALRENDERPROC>(LoadEntry("glEndConditionalRenderNV"));
s_openGLextensions[nzOpenGLExtension_ConditionalRender] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load GL_NV_conditional_render: " + NzString(e.what()));
}
}
// DebugOutput // DebugOutput
if (s_openglVersion >= 430 || IsSupported("GL_KHR_debug")) if (s_openglVersion >= 430 || IsSupported("GL_KHR_debug"))
{ {
@ -1076,37 +1069,6 @@ bool NzOpenGL::Initialize()
} }
} }
// DrawInstanced
if (s_openglVersion >= 310)
{
try
{
glDrawArraysInstanced = reinterpret_cast<PFNGLDRAWARRAYSINSTANCEDPROC>(LoadEntry("glDrawArraysInstanced"));
glDrawElementsInstanced = reinterpret_cast<PFNGLDRAWELEMENTSINSTANCEDPROC>(LoadEntry("glDrawElementsInstanced"));
s_openGLextensions[nzOpenGLExtension_DrawInstanced] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load Draw Instanced: " + NzString(e.what()));
}
}
if (!s_openGLextensions[nzOpenGLExtension_DrawInstanced] && IsSupported("GL_ARB_draw_instanced"))
{
try
{
glDrawArraysInstanced = reinterpret_cast<PFNGLDRAWARRAYSINSTANCEDARBPROC>(LoadEntry("glDrawArraysInstancedARB"));
glDrawElementsInstanced = reinterpret_cast<PFNGLDRAWELEMENTSINSTANCEDARBPROC>(LoadEntry("glDrawElementsInstancedARB"));
s_openGLextensions[nzOpenGLExtension_DrawInstanced] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load GL_ARB_draw_instanced: " + NzString(e.what()));
}
}
// FP64 // FP64
if (s_openglVersion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64")) if (s_openglVersion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64"))
{ {
@ -1126,35 +1088,6 @@ bool NzOpenGL::Initialize()
} }
} }
// FrameBufferObject
if (s_openglVersion >= 300 || IsSupported("GL_ARB_framebuffer_object"))
{
try
{
glBindFramebuffer = reinterpret_cast<PFNGLBINDFRAMEBUFFERPROC>(LoadEntry("glBindFramebuffer"));
glBindRenderbuffer = reinterpret_cast<PFNGLBINDRENDERBUFFERPROC>(LoadEntry("glBindRenderbuffer"));
glBlitFramebuffer = reinterpret_cast<PFNGLBLITFRAMEBUFFERPROC>(LoadEntry("glBlitFramebuffer"));
glCheckFramebufferStatus = reinterpret_cast<PFNGLCHECKFRAMEBUFFERSTATUSPROC>(LoadEntry("glCheckFramebufferStatus"));
glDeleteFramebuffers = reinterpret_cast<PFNGLDELETEFRAMEBUFFERSPROC>(LoadEntry("glDeleteFramebuffers"));
glDeleteRenderbuffers = reinterpret_cast<PFNGLDELETERENDERBUFFERSPROC>(LoadEntry("glDeleteRenderbuffers"));
glFramebufferRenderbuffer = reinterpret_cast<PFNGLFRAMEBUFFERRENDERBUFFERPROC>(LoadEntry("glFramebufferRenderbuffer"));
glFramebufferTexture1D = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE1DPROC>(LoadEntry("glFramebufferTexture1D"));
glFramebufferTexture2D = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE2DPROC>(LoadEntry("glFramebufferTexture2D"));
glFramebufferTexture3D = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURE3DPROC>(LoadEntry("glFramebufferTexture3D"));
glFramebufferTextureLayer = reinterpret_cast<PFNGLFRAMEBUFFERTEXTURELAYERPROC>(LoadEntry("glFramebufferTextureLayer"));
glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPPROC>(LoadEntry("glGenerateMipmap"));
glGenFramebuffers = reinterpret_cast<PFNGLGENFRAMEBUFFERSPROC>(LoadEntry("glGenFramebuffers"));
glGenRenderbuffers = reinterpret_cast<PFNGLGENRENDERBUFFERSPROC>(LoadEntry("glGenRenderbuffers"));
glRenderbufferStorage = reinterpret_cast<PFNGLRENDERBUFFERSTORAGEPROC>(LoadEntry("glRenderbufferStorage"));
s_openGLextensions[nzOpenGLExtension_FrameBufferObject] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")");
}
}
// GetProgramBinary // GetProgramBinary
if (s_openglVersion >= 410 || IsSupported("GL_ARB_get_program_binary")) if (s_openglVersion >= 410 || IsSupported("GL_ARB_get_program_binary"))
{ {
@ -1172,57 +1105,6 @@ bool NzOpenGL::Initialize()
} }
} }
// InstancedArray
if (s_openglVersion >= 330)
{
try
{
glVertexAttribDivisor = reinterpret_cast<PFNGLVERTEXATTRIBDIVISORPROC>(LoadEntry("glVertexAttribDivisor"));
s_openGLextensions[nzOpenGLExtension_InstancedArray] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load Instanced Array: " + NzString(e.what()));
}
}
if (!s_openGLextensions[nzOpenGLExtension_InstancedArray] && IsSupported("GL_ARB_instanced_arrays"))
{
try
{
glVertexAttribDivisor = reinterpret_cast<PFNGLVERTEXATTRIBDIVISORARBPROC>(LoadEntry("glVertexAttribDivisorARB"));
s_openGLextensions[nzOpenGLExtension_InstancedArray] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load GL_ARB_instanced_arrays: " + NzString(e.what()));
}
}
// PixelBufferObject
s_openGLextensions[nzOpenGLExtension_PixelBufferObject] = (s_openglVersion >= 210 || IsSupported("GL_ARB_pixel_buffer_object"));
// SamplerObjects
if (s_openglVersion >= 330 || IsSupported("GL_ARB_sampler_objects"))
{
try
{
glBindSampler = reinterpret_cast<PFNGLBINDSAMPLERPROC>(LoadEntry("glBindSampler"));
glDeleteSamplers = reinterpret_cast<PFNGLDELETESAMPLERSPROC>(LoadEntry("glDeleteSamplers"));
glGenSamplers = reinterpret_cast<PFNGLGENSAMPLERSPROC>(LoadEntry("glGenSamplers"));
glSamplerParameterf = reinterpret_cast<PFNGLSAMPLERPARAMETERFPROC>(LoadEntry("glSamplerParameterf"));
glSamplerParameteri = reinterpret_cast<PFNGLSAMPLERPARAMETERIPROC>(LoadEntry("glSamplerParameteri"));
s_openGLextensions[nzOpenGLExtension_SamplerObjects] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load ARB_sampler_objects: (" + NzString(e.what()) + ")");
}
}
// SeparateShaderObjects // SeparateShaderObjects
if (s_openglVersion >= 400 || IsSupported("GL_ARB_separate_shader_objects")) if (s_openglVersion >= 400 || IsSupported("GL_ARB_separate_shader_objects"))
{ {
@ -1262,9 +1144,6 @@ bool NzOpenGL::Initialize()
// Shader_ImageLoadStore // Shader_ImageLoadStore
s_openGLextensions[nzOpenGLExtension_Shader_ImageLoadStore] = (s_openglVersion >= 420 || IsSupported("GL_ARB_shader_image_load_store")); s_openGLextensions[nzOpenGLExtension_Shader_ImageLoadStore] = (s_openglVersion >= 420 || IsSupported("GL_ARB_shader_image_load_store"));
// TextureArray
s_openGLextensions[nzOpenGLExtension_TextureArray] = (s_openglVersion >= 300 || IsSupported("GL_EXT_texture_array"));
// TextureCompression_s3tc // TextureCompression_s3tc
s_openGLextensions[nzOpenGLExtension_TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc"); s_openGLextensions[nzOpenGLExtension_TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc");
@ -1285,27 +1164,6 @@ bool NzOpenGL::Initialize()
} }
} }
// VertexArrayObject
if (s_openglVersion >= 300 || IsSupported("GL_ARB_vertex_array_object"))
{
try
{
glBindVertexArray = reinterpret_cast<PFNGLBINDVERTEXARRAYPROC>(LoadEntry("glBindVertexArray"));
glDeleteVertexArrays = reinterpret_cast<PFNGLDELETEVERTEXARRAYSPROC>(LoadEntry("glDeleteVertexArrays"));
glGenVertexArrays = reinterpret_cast<PFNGLGENVERTEXARRAYSPROC>(LoadEntry("glGenVertexArrays"));
s_openGLextensions[nzOpenGLExtension_VertexArrayObjects] = true;
}
catch (const std::exception& e)
{
NazaraWarning("Failed to load ARB_vertex_array_object: " + NzString(e.what()));
}
}
// Fonctions de substitut
if (!glGenerateMipmap)
glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPEXTPROC>(LoadEntry("glGenerateMipmapEXT", false));
/******************************Initialisation*****************************/ /******************************Initialisation*****************************/
s_contextStates = nullptr; s_contextStates = nullptr;

View File

@ -111,11 +111,6 @@ bool NzRenderBuffer::IsValid() const
return m_id != 0; return m_id != 0;
} }
bool NzRenderBuffer::IsSupported()
{
return NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
}
bool NzRenderBuffer::Initialize() bool NzRenderBuffer::Initialize()
{ {
if (!NzRenderBufferLibrary::Initialize()) if (!NzRenderBufferLibrary::Initialize())

View File

@ -299,12 +299,6 @@ bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 i
bool NzRenderTexture::Create(bool lock) bool NzRenderTexture::Create(bool lock)
{ {
if (!IsSupported())
{
NazaraError("Render textures not supported");
return false;
}
Destroy(); Destroy();
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE
@ -655,11 +649,6 @@ bool NzRenderTexture::HasContext() const
return false; return false;
} }
bool NzRenderTexture::IsSupported()
{
return NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
}
void NzRenderTexture::Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers, bool bilinearFilter) void NzRenderTexture::Blit(NzRenderTexture* src, NzRectui srcRect, NzRenderTexture* dst, NzRectui dstRect, nzUInt32 buffers, bool bilinearFilter)
{ {
NazaraAssert(src && src->IsValid(), "Invalid source render texture"); NazaraAssert(src && src->IsValid(), "Invalid source render texture");

View File

@ -33,6 +33,8 @@
#include <vector> #include <vector>
#include <Nazara/Renderer/Debug.hpp> #include <Nazara/Renderer/Debug.hpp>
///TODO: Manager les VAO (permettre plusieurs draw calls sans rebinder le VAO)
namespace namespace
{ {
const nzUInt8 r_coreFragmentShader[] = { const nzUInt8 r_coreFragmentShader[] = {
@ -43,14 +45,6 @@ namespace
#include <Nazara/Renderer/Resources/Shaders/Debug/core.vert.h> #include <Nazara/Renderer/Resources/Shaders/Debug/core.vert.h>
}; };
const nzUInt8 r_compatibilityFragmentShader[] = {
#include <Nazara/Renderer/Resources/Shaders/Debug/compatibility.frag.h>
};
const nzUInt8 r_compatibilityVertexShader[] = {
#include <Nazara/Renderer/Resources/Shaders/Debug/compatibility.vert.h>
};
enum ObjectType enum ObjectType
{ {
ObjectType_Context, ObjectType_Context,
@ -122,8 +116,6 @@ namespace
const NzVertexBuffer* s_vertexBuffer; const NzVertexBuffer* s_vertexBuffer;
bool s_capabilities[nzRendererCap_Max+1]; bool s_capabilities[nzRendererCap_Max+1];
bool s_instancing; bool s_instancing;
bool s_useSamplerObjects;
bool s_useVertexArrayObjects;
unsigned int s_maxColorAttachments; unsigned int s_maxColorAttachments;
unsigned int s_maxRenderTarget; unsigned int s_maxRenderTarget;
unsigned int s_maxTextureSize; unsigned int s_maxTextureSize;
@ -141,14 +133,6 @@ void NzRenderer::BeginCondition(const NzGpuQuery& query, nzGpuQueryCondition con
} }
#endif #endif
#if NAZARA_RENDERER_SAFE
if (!s_capabilities[nzRendererCap_ConditionalRendering])
{
NazaraError("Conditional rendering is not supported");
return;
}
#endif
glBeginConditionalRender(query.GetOpenGLID(), NzOpenGL::QueryCondition[condition]); glBeginConditionalRender(query.GetOpenGLID(), NzOpenGL::QueryCondition[condition]);
} }
@ -205,9 +189,7 @@ void NzRenderer::DrawFullscreenQuad()
} }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
if (s_useVertexArrayObjects)
glBindVertexArray(0);
} }
void NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount) void NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount)
@ -257,9 +239,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode mode, unsigned int firstI
} }
glDrawElements(NzOpenGL::PrimitiveMode[mode], indexCount, type, offset); glDrawElements(NzOpenGL::PrimitiveMode[mode], indexCount, type, offset);
glBindVertexArray(0);
if (s_useVertexArrayObjects)
glBindVertexArray(0);
} }
void NzRenderer::DrawIndexedPrimitivesInstanced(unsigned int instanceCount, nzPrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount) void NzRenderer::DrawIndexedPrimitivesInstanced(unsigned int instanceCount, nzPrimitiveMode mode, unsigned int firstIndex, unsigned int indexCount)
@ -279,12 +259,6 @@ void NzRenderer::DrawIndexedPrimitivesInstanced(unsigned int instanceCount, nzPr
#endif #endif
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE
if (!s_capabilities[nzRendererCap_Instancing])
{
NazaraError("Instancing not supported");
return;
}
if (!s_indexBuffer) if (!s_indexBuffer)
{ {
NazaraError("No index buffer"); NazaraError("No index buffer");
@ -328,9 +302,7 @@ void NzRenderer::DrawIndexedPrimitivesInstanced(unsigned int instanceCount, nzPr
} }
glDrawElementsInstanced(NzOpenGL::PrimitiveMode[mode], indexCount, type, offset, instanceCount); glDrawElementsInstanced(NzOpenGL::PrimitiveMode[mode], indexCount, type, offset, instanceCount);
glBindVertexArray(0);
if (s_useVertexArrayObjects)
glBindVertexArray(0);
} }
void NzRenderer::DrawPrimitives(nzPrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount) void NzRenderer::DrawPrimitives(nzPrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount)
@ -358,9 +330,7 @@ void NzRenderer::DrawPrimitives(nzPrimitiveMode mode, unsigned int firstVertex,
} }
glDrawArrays(NzOpenGL::PrimitiveMode[mode], firstVertex, vertexCount); glDrawArrays(NzOpenGL::PrimitiveMode[mode], firstVertex, vertexCount);
glBindVertexArray(0);
if (s_useVertexArrayObjects)
glBindVertexArray(0);
} }
void NzRenderer::DrawPrimitivesInstanced(unsigned int instanceCount, nzPrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount) void NzRenderer::DrawPrimitivesInstanced(unsigned int instanceCount, nzPrimitiveMode mode, unsigned int firstVertex, unsigned int vertexCount)
@ -380,12 +350,6 @@ void NzRenderer::DrawPrimitivesInstanced(unsigned int instanceCount, nzPrimitive
#endif #endif
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE
if (!s_capabilities[nzRendererCap_Instancing])
{
NazaraError("Instancing not supported");
return;
}
if (instanceCount == 0) if (instanceCount == 0)
{ {
NazaraError("Instance count must be over zero"); NazaraError("Instance count must be over zero");
@ -409,9 +373,7 @@ void NzRenderer::DrawPrimitivesInstanced(unsigned int instanceCount, nzPrimitive
} }
glDrawArraysInstanced(NzOpenGL::PrimitiveMode[mode], firstVertex, vertexCount, instanceCount); glDrawArraysInstanced(NzOpenGL::PrimitiveMode[mode], firstVertex, vertexCount, instanceCount);
glBindVertexArray(0);
if (s_useVertexArrayObjects)
glBindVertexArray(0);
} }
void NzRenderer::Enable(nzRendererParameter parameter, bool enable) void NzRenderer::Enable(nzRendererParameter parameter, bool enable)
@ -443,14 +405,6 @@ void NzRenderer::EndCondition()
} }
#endif #endif
#if NAZARA_RENDERER_SAFE
if (!s_capabilities[nzRendererCap_ConditionalRendering])
{
NazaraError("Conditional rendering is not supported");
return;
}
#endif
glEndConditionalRender(); glEndConditionalRender();
} }
@ -474,14 +428,6 @@ nzRendererComparison NzRenderer::GetDepthFunc()
NzVertexBuffer* NzRenderer::GetInstanceBuffer() NzVertexBuffer* NzRenderer::GetInstanceBuffer()
{ {
#if NAZARA_RENDERER_SAFE
if (!s_capabilities[nzRendererCap_Instancing])
{
NazaraError("Instancing not supported");
return nullptr;
}
#endif
s_updateFlags |= Update_VAO; s_updateFlags |= Update_VAO;
return &s_instanceBuffer; return &s_instanceBuffer;
} }
@ -629,19 +575,9 @@ bool NzRenderer::Initialize()
} }
// Récupération des capacités d'OpenGL // Récupération des capacités d'OpenGL
s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter); s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter);
s_capabilities[nzRendererCap_ConditionalRendering] = NzOpenGL::IsSupported(nzOpenGLExtension_ConditionalRender); s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(nzOpenGLExtension_FP64);
s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(nzOpenGLExtension_FP64); s_capabilities[nzRendererCap_Instancing] = true; // Supporté par OpenGL 3.3
s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5
s_capabilities[nzRendererCap_Instancing] = NzOpenGL::IsSupported(nzOpenGLExtension_DrawInstanced) && NzOpenGL::IsSupported(nzOpenGLExtension_InstancedArray);
s_capabilities[nzRendererCap_MultipleRenderTargets] = (glBindFragDataLocation != nullptr); // Natif depuis OpenGL 2.0 mais inutile sans glBindFragDataLocation
s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5
s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(nzOpenGLExtension_PixelBufferObject);
s_capabilities[nzRendererCap_RenderTexture] = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
s_capabilities[nzRendererCap_Texture3D] = true; // Natif depuis OpenGL 1.2
s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3
s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3
s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0
NzContext::EnsureContext(); NzContext::EnsureContext();
@ -655,39 +591,21 @@ bool NzRenderer::Initialize()
else else
s_maxAnisotropyLevel = 1; s_maxAnisotropyLevel = 1;
if (s_capabilities[nzRendererCap_RenderTexture]) GLint maxColorAttachments;
{ glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
GLint maxColorAttachments; s_maxColorAttachments = static_cast<unsigned int>(maxColorAttachments);
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
s_maxColorAttachments = static_cast<unsigned int>(maxColorAttachments); GLint maxDrawBuffers;
} glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
else s_maxRenderTarget = static_cast<unsigned int>(maxDrawBuffers);
s_maxColorAttachments = 1;
if (s_capabilities[nzRendererCap_MultipleRenderTargets]) GLint maxTextureUnits;
{ glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
GLint maxDrawBuffers; s_maxTextureUnit = static_cast<unsigned int>(maxTextureUnits);
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
s_maxRenderTarget = static_cast<unsigned int>(maxDrawBuffers);
}
else
s_maxRenderTarget = 1;
if (s_capabilities[nzRendererCap_TextureMulti])
{
GLint maxTextureUnits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
s_maxTextureUnit = static_cast<unsigned int>(maxTextureUnits);
}
else
s_maxTextureUnit = 1;
GLint maxTextureSize; GLint maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
s_maxTextureSize = maxTextureSize; s_maxTextureSize = static_cast<unsigned int>(maxTextureSize);
GLint maxVertexAttribs; GLint maxVertexAttribs;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
@ -700,8 +618,6 @@ bool NzRenderer::Initialize()
s_target = nullptr; s_target = nullptr;
s_targetSize.Set(0U); s_targetSize.Set(0U);
s_textureUnits.resize(s_maxTextureUnit); s_textureUnits.resize(s_maxTextureUnit);
s_useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects);
s_useVertexArrayObjects = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects);
s_updateFlags = Update_Matrices | Update_Shader | Update_VAO; s_updateFlags = Update_Matrices | Update_Shader | Update_VAO;
s_vertexBuffer = nullptr; s_vertexBuffer = nullptr;
@ -775,32 +691,13 @@ bool NzRenderer::Initialize()
return false; return false;
} }
const char* fragmentShader; if (!debugShader->AttachStageFromSource(nzShaderStage_Fragment, reinterpret_cast<const char*>(r_coreFragmentShader), sizeof(r_coreFragmentShader)))
const char* vertexShader;
unsigned int fragmentShaderLength;
unsigned int vertexShaderLength;
if (NzOpenGL::GetGLSLVersion() >= 140)
{
fragmentShader = reinterpret_cast<const char*>(r_coreFragmentShader);
fragmentShaderLength = sizeof(r_coreFragmentShader);
vertexShader = reinterpret_cast<const char*>(r_coreVertexShader);
vertexShaderLength = sizeof(r_coreVertexShader);
}
else
{
fragmentShader = reinterpret_cast<const char*>(r_compatibilityFragmentShader);
fragmentShaderLength = sizeof(r_compatibilityFragmentShader);
vertexShader = reinterpret_cast<const char*>(r_compatibilityVertexShader);
vertexShaderLength = sizeof(r_compatibilityVertexShader);
}
if (!debugShader->AttachStageFromSource(nzShaderStage_Fragment, fragmentShader, fragmentShaderLength))
{ {
NazaraError("Failed to attach fragment stage"); NazaraError("Failed to attach fragment stage");
return false; return false;
} }
if (!debugShader->AttachStageFromSource(nzShaderStage_Vertex, vertexShader, vertexShaderLength)) if (!debugShader->AttachStageFromSource(nzShaderStage_Vertex, reinterpret_cast<const char*>(r_coreVertexShader), sizeof(r_coreVertexShader)))
{ {
NazaraError("Failed to attach vertex stage"); NazaraError("Failed to attach vertex stage");
return false; return false;
@ -1549,31 +1446,14 @@ bool NzRenderer::EnsureStateUpdate()
{ {
if (s_updateFlags & Update_Textures) if (s_updateFlags & Update_Textures)
{ {
if (s_useSamplerObjects) for (unsigned int i : s_dirtyTextureUnits)
{ {
for (unsigned int i : s_dirtyTextureUnits) TextureUnit& unit = s_textureUnits[i];
{
TextureUnit& unit = s_textureUnits[i];
if (unit.texture && !unit.samplerUpdated) if (unit.texture && !unit.samplerUpdated)
{
unit.sampler.Bind(i);
unit.samplerUpdated = true;
}
}
}
else
{
for (unsigned int i : s_dirtyTextureUnits)
{ {
TextureUnit& unit = s_textureUnits[i]; unit.sampler.Bind(i);
unit.samplerUpdated = true;
if (unit.texture && !unit.samplerUpdated)
{
NzOpenGL::BindTextureUnit(i);
unit.sampler.Apply(unit.texture);
unit.samplerUpdated = true;
}
} }
} }
@ -1608,73 +1488,52 @@ bool NzRenderer::EnsureStateUpdate()
} }
#endif #endif
bool update; // Note: Les VAOs ne sont pas partagés entre les contextes, nous avons donc un tableau de VAOs par contexte
VAO_Map::iterator vaoIt; const NzContext* context = NzContext::GetCurrent();
// Si les VAOs sont supportés, on entoure nos appels par ceux-ci auto it = s_vaos.find(context);
if (s_useVertexArrayObjects) if (it == s_vaos.end())
{ {
// Note: Les VAOs ne sont pas partagés entre les contextes, nous avons donc un tableau de VAOs par contexte Context_Entry entry;
const NzContext* context = NzContext::GetCurrent(); entry.onReleaseSlot.Connect(context->OnContextRelease, OnContextRelease);
auto it = s_vaos.find(context); it = s_vaos.insert(std::make_pair(context, std::move(entry))).first;
if (it == s_vaos.end())
{
Context_Entry entry;
entry.onReleaseSlot.Connect(context->OnContextRelease, OnContextRelease);
it = s_vaos.insert(std::make_pair(context, std::move(entry))).first;
}
VAO_Map& vaoMap = it->second.vaoMap;
// Notre clé est composée de ce qui définit un VAO
const NzVertexDeclaration* vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
const NzVertexDeclaration* instancingDeclaration = (s_instancing) ? s_instanceBuffer.GetVertexDeclaration() : nullptr;
VAO_Key key(s_indexBuffer, s_vertexBuffer, vertexDeclaration, instancingDeclaration);
// On recherche un VAO existant avec notre configuration
vaoIt = vaoMap.find(key);
if (vaoIt == vaoMap.end())
{
// On créé notre VAO
glGenVertexArrays(1, &s_currentVAO);
glBindVertexArray(s_currentVAO);
// On l'ajoute à notre liste
VAO_Entry entry;
entry.vao = s_currentVAO;
// Connect the slots
if (s_indexBuffer)
entry.onIndexBufferReleaseSlot.Connect(s_indexBuffer->OnIndexBufferRelease, OnIndexBufferRelease);
if (instancingDeclaration)
entry.onInstancingDeclarationReleaseSlot.Connect(instancingDeclaration->OnVertexDeclarationRelease, OnVertexDeclarationRelease);
entry.onVertexBufferReleaseSlot.Connect(s_vertexBuffer->OnVertexBufferRelease, OnVertexBufferRelease);
entry.onVertexDeclarationReleaseSlot.Connect(vertexDeclaration->OnVertexDeclarationRelease, OnVertexDeclarationRelease);
vaoIt = vaoMap.insert(std::make_pair(key, std::move(entry))).first;
// Et on indique qu'on veut le programmer
update = true;
}
else
{
// Notre VAO existe déjà, il est donc inutile de le reprogrammer
s_currentVAO = vaoIt->second.vao;
update = false;
}
} }
else
update = true; // Fallback si les VAOs ne sont pas supportés
bool updateFailed = false; VAO_Map& vaoMap = it->second.vaoMap;
if (update) // Notre clé est composée de ce qui définit un VAO
const NzVertexDeclaration* vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
const NzVertexDeclaration* instancingDeclaration = (s_instancing) ? s_instanceBuffer.GetVertexDeclaration() : nullptr;
VAO_Key key(s_indexBuffer, s_vertexBuffer, vertexDeclaration, instancingDeclaration);
// On recherche un VAO existant avec notre configuration
auto vaoIt = vaoMap.find(key);
if (vaoIt == vaoMap.end())
{ {
// On créé notre VAO
glGenVertexArrays(1, &s_currentVAO);
glBindVertexArray(s_currentVAO);
// On l'ajoute à notre liste
VAO_Entry entry;
entry.vao = s_currentVAO;
// Connect the slots
if (s_indexBuffer)
entry.onIndexBufferReleaseSlot.Connect(s_indexBuffer->OnIndexBufferRelease, OnIndexBufferRelease);
if (instancingDeclaration)
entry.onInstancingDeclarationReleaseSlot.Connect(instancingDeclaration->OnVertexDeclarationRelease, OnVertexDeclarationRelease);
entry.onVertexBufferReleaseSlot.Connect(s_vertexBuffer->OnVertexBufferRelease, OnVertexBufferRelease);
entry.onVertexDeclarationReleaseSlot.Connect(vertexDeclaration->OnVertexDeclarationRelease, OnVertexDeclarationRelease);
vaoIt = vaoMap.insert(std::make_pair(key, std::move(entry))).first;
// And begin to program it
bool updateFailed = false;
// Pour éviter la duplication de code, on va utiliser une astuce via une boucle for // Pour éviter la duplication de code, on va utiliser une astuce via une boucle for
for (unsigned int i = 0; i < (s_instancing ? 2U : 1U); ++i) for (unsigned int i = 0; i < (s_instancing ? 2U : 1U); ++i)
{ {
@ -1714,11 +1573,11 @@ bool NzRenderer::EnsureStateUpdate()
case nzComponentType_Color: case nzComponentType_Color:
{ {
glVertexAttribPointer(NzOpenGL::VertexComponentIndex[j], glVertexAttribPointer(NzOpenGL::VertexComponentIndex[j],
NzUtility::ComponentCount[type], NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type], NzOpenGL::ComponentType[type],
GL_TRUE, GL_TRUE,
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
break; break;
} }
@ -1729,10 +1588,10 @@ bool NzRenderer::EnsureStateUpdate()
case nzComponentType_Double4: case nzComponentType_Double4:
{ {
glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[j], glVertexAttribLPointer(NzOpenGL::VertexComponentIndex[j],
NzUtility::ComponentCount[type], NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type], NzOpenGL::ComponentType[type],
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
break; break;
} }
@ -1743,11 +1602,11 @@ bool NzRenderer::EnsureStateUpdate()
case nzComponentType_Float4: case nzComponentType_Float4:
{ {
glVertexAttribPointer(NzOpenGL::VertexComponentIndex[j], glVertexAttribPointer(NzOpenGL::VertexComponentIndex[j],
NzUtility::ComponentCount[type], NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type], NzOpenGL::ComponentType[type],
GL_FALSE, GL_FALSE,
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
break; break;
} }
@ -1758,10 +1617,10 @@ bool NzRenderer::EnsureStateUpdate()
case nzComponentType_Int4: case nzComponentType_Int4:
{ {
glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[j], glVertexAttribIPointer(NzOpenGL::VertexComponentIndex[j],
NzUtility::ComponentCount[type], NzUtility::ComponentCount[type],
NzOpenGL::ComponentType[type], NzOpenGL::ComponentType[type],
stride, stride,
reinterpret_cast<void*>(bufferOffset + offset)); reinterpret_cast<void*>(bufferOffset + offset));
break; break;
} }
@ -1772,6 +1631,7 @@ bool NzRenderer::EnsureStateUpdate()
break; break;
} }
} }
// Les attributs d'instancing ont un diviseur spécifique (pour dépendre de l'instance en cours) // Les attributs d'instancing ont un diviseur spécifique (pour dépendre de l'instance en cours)
if (i == 1) if (i == 1)
glVertexAttribDivisor(NzOpenGL::VertexComponentIndex[j], 1); glVertexAttribDivisor(NzOpenGL::VertexComponentIndex[j], 1);
@ -1801,46 +1661,40 @@ bool NzRenderer::EnsureStateUpdate()
// On invalide les bindings des buffers (car nous les avons défini manuellement) // On invalide les bindings des buffers (car nous les avons défini manuellement)
NzOpenGL::SetBuffer(nzBufferType_Index, 0); NzOpenGL::SetBuffer(nzBufferType_Index, 0);
NzOpenGL::SetBuffer(nzBufferType_Vertex, 0); NzOpenGL::SetBuffer(nzBufferType_Vertex, 0);
}
if (s_useVertexArrayObjects) if (updateFailed)
{
if (update)
{ {
if (updateFailed) // La création de notre VAO a échoué, libérons-le et marquons-le comme problématique
{ glDeleteVertexArrays(1, &vaoIt->second.vao);
// La création de notre VAO a échoué, libérons-le et marquons-le comme problématique vaoIt->second.vao = 0;
glDeleteVertexArrays(1, &vaoIt->second.vao); s_currentVAO = 0;
vaoIt->second.vao = 0;
s_currentVAO = 0;
}
else
glBindVertexArray(0); // On marque la fin de la construction du VAO en le débindant
} }
else
// En cas de non-support des VAOs, les attributs doivent être respécifiés à chaque frame glBindVertexArray(0); // On marque la fin de la construction du VAO en le débindant
s_updateFlags &= ~Update_VAO;
} }
else
// Notre VAO existe déjà, il est donc inutile de le reprogrammer
s_currentVAO = vaoIt->second.vao;
// En cas de non-support des VAOs, les attributs doivent être respécifiés à chaque frame
s_updateFlags &= ~Update_VAO;
} }
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (s_updateFlags != Update_None && !s_useVertexArrayObjects && s_updateFlags != Update_VAO) if (s_updateFlags != Update_None && s_updateFlags != Update_VAO)
NazaraWarning("Update flags not fully cleared"); NazaraWarning("Update flags not fully cleared");
#endif #endif
} }
// On bind notre VAO // On bind notre VAO
if (s_useVertexArrayObjects) if (!s_currentVAO)
{ {
if (!s_currentVAO) NazaraError("Failed to create VAO");
{ return false;
NazaraError("Failed to create VAO");
return false;
}
glBindVertexArray(s_currentVAO);
} }
glBindVertexArray(s_currentVAO);
// On vérifie que les textures actuellement bindées sont bien nos textures // On vérifie que les textures actuellement bindées sont bien nos textures
// Ceci à cause du fait qu'il est possible que des opérations sur les textures aient eu lieu // Ceci à cause du fait qu'il est possible que des opérations sur les textures aient eu lieu
// entre le dernier rendu et maintenant // entre le dernier rendu et maintenant

View File

@ -1,10 +0,0 @@
#version 110
/********************Uniformes********************/
uniform vec4 Color;
/********************Fonctions********************/
void main()
{
gl_FragColor = Color;
}

View File

@ -1 +0,0 @@
35,118,101,114,115,105,111,110,32,49,49,48,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,67,111,108,111,114,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,67,111,108,111,114,59,13,10,125,

View File

@ -1,13 +0,0 @@
#version 110
/********************Entrant********************/
varying vec3 VertexPosition;
/********************Uniformes********************/
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
}

View File

@ -1 +0,0 @@
35,118,101,114,115,105,111,110,32,49,49,48,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,97,114,121,105,110,103,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,125,13,10,

View File

@ -157,17 +157,14 @@ bool NzShader::Create()
glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata3], "VertexUserdata3"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata3], "VertexUserdata3");
glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata4], "VertexUserdata4"); glBindAttribLocation(m_program, NzOpenGL::VertexComponentIndex[nzVertexComponent_Userdata4], "VertexUserdata4");
if (NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets)) NzString uniform;
{ uniform = "RenderTarget";
NzString uniform;
uniform = "RenderTarget";
unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets(); unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets();
for (unsigned int i = 0; i < maxRenderTargets; ++i) for (unsigned int i = 0; i < maxRenderTargets; ++i)
{ {
NzString uniformName = uniform + NzString::Number(i); NzString uniformName = uniform + NzString::Number(i);
glBindFragDataLocation(m_program, i, uniformName.GetConstBuffer()); glBindFragDataLocation(m_program, i, uniformName.GetConstBuffer());
}
} }
if (NzOpenGL::IsSupported(nzOpenGLExtension_GetProgramBinary)) if (NzOpenGL::IsSupported(nzOpenGLExtension_GetProgramBinary))

View File

@ -220,12 +220,10 @@ bool NzShaderStage::IsSupported(nzShaderStage stage)
switch (stage) switch (stage)
{ {
case nzShaderStage_Fragment: case nzShaderStage_Fragment:
case nzShaderStage_Geometry:
case nzShaderStage_Vertex: case nzShaderStage_Vertex:
return true; return true;
case nzShaderStage_Geometry:
return NzOpenGL::GetVersion() >= 320;
default: default:
NazaraError("Shader stage not handled (0x" + NzString::Number(stage, 16) + ')'); NazaraError("Shader stage not handled (0x" + NzString::Number(stage, 16) + ')');
return false; return false;

View File

@ -165,12 +165,12 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
} }
m_impl = new NzTextureImpl; m_impl = new NzTextureImpl;
m_impl->depth = GetValidSize(depth); m_impl->depth = depth;
m_impl->format = format; m_impl->format = format;
m_impl->height = GetValidSize(height); m_impl->height = height;
m_impl->levelCount = levelCount; m_impl->levelCount = levelCount;
m_impl->type = type; m_impl->type = type;
m_impl->width = GetValidSize(width); m_impl->width = width;
glGenTextures(1, &m_impl->id); glGenTextures(1, &m_impl->id);
NzOpenGL::BindTexture(m_impl->type, m_impl->id); NzOpenGL::BindTexture(m_impl->type, m_impl->id);
@ -1035,20 +1035,6 @@ unsigned int NzTexture::GetOpenGLID() const
return m_impl->id; return m_impl->id;
} }
unsigned int NzTexture::GetValidSize(unsigned int size)
{
if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT))
return size;
else
{
unsigned int pot = 1;
while (pot < size)
pot <<= 1;
return pot;
}
}
bool NzTexture::IsFormatSupported(nzPixelFormat format) bool NzTexture::IsFormatSupported(nzPixelFormat format)
{ {
switch (format) switch (format)
@ -1101,14 +1087,14 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
case nzPixelFormat_RGBA32F: case nzPixelFormat_RGBA32F:
case nzPixelFormat_RGBA32I: case nzPixelFormat_RGBA32I:
case nzPixelFormat_RGBA32UI: case nzPixelFormat_RGBA32UI:
return NzOpenGL::GetVersion() >= 300; return true;
// Formats de profondeur (Supportés avec les FBOs) // Formats de profondeur (Supportés avec les FBOs)
case nzPixelFormat_Depth16: case nzPixelFormat_Depth16:
case nzPixelFormat_Depth24: case nzPixelFormat_Depth24:
case nzPixelFormat_Depth32: case nzPixelFormat_Depth32:
case nzPixelFormat_Depth24Stencil8: case nzPixelFormat_Depth24Stencil8:
return NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject); return true;
// Formats de stencil (Non supportés pour les textures) // Formats de stencil (Non supportés pour les textures)
case nzPixelFormat_Stencil1: case nzPixelFormat_Stencil1:
@ -1141,14 +1127,12 @@ bool NzTexture::IsTypeSupported(nzImageType type)
switch (type) switch (type)
{ {
case nzImageType_1D: case nzImageType_1D:
case nzImageType_1D_Array:
case nzImageType_2D: case nzImageType_2D:
case nzImageType_2D_Array:
case nzImageType_3D: case nzImageType_3D:
case nzImageType_Cubemap: case nzImageType_Cubemap:
return true; // Tous supportés nativement dans OpenGL 2 return true; // Tous supportés nativement dans OpenGL 3
case nzImageType_1D_Array:
case nzImageType_2D_Array:
return NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray);
} }
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');