Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,22 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYENGINE_RENDERDLL_XRENDERD3D9_DXGL_IMPLEMENTATION_APPLEGPUINFOUTILS_H
#define CRYINCLUDE_CRYENGINE_RENDERDLL_XRENDERD3D9_DXGL_IMPLEMENTATION_APPLEGPUINFOUTILS_H
#pragma once
// Return -1 on failure and availabe VRAM otherwise
long GetVRAMForDisplay(const int dspNum);
#endif // CRYINCLUDE_CRYENGINE_RENDERDLL_XRENDERD3D9_DXGL_IMPLEMENTATION_APPLEGPUINFOUTILS_H
@@ -0,0 +1,86 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "AppleGPUInfoUtils.h"
#include <Cocoa/Cocoa.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreGraphics/CoreGraphics.h>
// this file needs to be sparate since CryEngine headers conflict with the
// Cocoa definitions
// this will be removed in the next version of OS X, but for now
// we can still use it.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
long GetVRAMForDisplay(const int dspNum)
{
CGError err = CGDisplayNoErr;
io_service_t *dspPorts = NULL;
CGDirectDisplayID *displays = NULL;
CGDisplayCount dspCount = 0;
CFTypeRef typeCode;
uint32_t vram = 0;
// How many active displays do we have?
err = CGGetActiveDisplayList(0, NULL, &dspCount);
if (err != kCGErrorSuccess)
return -1;
// If the display number is higher than the available display count, return
if (dspCount < dspNum)
return -1;
// Allocate enough memory to hold all the display IDs we have
displays = (CGDirectDisplayID*)calloc((size_t)dspCount, sizeof(CGDirectDisplayID));
// Allocate memory for our service ports
dspPorts = (io_service_t*)calloc((size_t)dspCount, sizeof(io_service_t));
// Get the list of active displays
err = CGGetActiveDisplayList(dspCount,
displays,
&dspCount);
if (err == kCGErrorSuccess)
{
// Get the service port for the display
dspPorts[dspNum] = CGDisplayIOServicePort(displays[dspNum]);
// Ask IOKit for the VRAM size property
typeCode = IORegistryEntryCreateCFProperty(dspPorts[dspNum],
CFSTR(kIOFBMemorySizeKey),
kCFAllocatorDefault,
kNilOptions);
// Ensure we have valid data from IOKit
if(typeCode && CFGetTypeID(typeCode) == CFNumberGetTypeID())
{
// If so, convert the CFNumber into a plain unsigned long
CFNumberGetValue((CFNumberRef)typeCode, kCFNumberSInt32Type, &vram);
if(typeCode)
CFRelease(typeCode);
}
}
free(displays);
free(dspPorts);
// Return the total number of displays we found
return (long)vram;
}
#pragma clang diagnostic pop
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "RenderDll_precompiled.h"
// For definitions
#include <CryDXGL.hpp>
#define NO_INCLUDE_GL_FEATURES
#include <Implementation/GLCommon.hpp>
#undef NO_INCLUDE_GL_FEATURES
// Need to explicitly include glad with the IMPLEMENTATION defines
#if defined(DXGL_USE_LOADER_GLAD)
# if DXGLES && !defined(DXGL_ES_SUBSET)
# define GLAD_GLES2_IMPLEMENTATION
# include <glad/gles2.h>
# undef GLAD_GLES2_IMPLEMENTATION
# else
# define GLAD_GL_IMPLEMENTATION
# include <glad/gl.h>
# undef GLAD_GL_IMPLEMENTATION
# endif
# if defined(DXGL_USE_WGL)
# define GLAD_WGL_IMPLEMENTATION
# include <glad/wgl.h>
# undef GLAD_WGL_IMPLEMENTATION
# elif defined(DXGL_USE_EGL)
# define GLAD_EGL_IMPLEMENTATION
# include <glad/egl.h>
# undef GLAD_EGL_IMPLEMENTATION
# elif defined(DXGL_USE_GLX)
# define GLAD_GLX_IMPLEMENTATION
# include <glad/glx.h>
# undef GLAD_GLX_IMPLEMENTATION
# endif
#endif
@@ -0,0 +1,311 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "RenderDll_precompiled.h"
#include <Implementation/GLBlitFramebufferHelper.hpp>
#include <Implementation/GLBlitShaders.hpp>
#include <Implementation/GLContext.hpp>
#if DXGL_INPUT_GLSL && DXGL_GLSL_FROM_HLSLCROSSCOMPILER
#include <hlslcc.hpp>
#endif //DXGL_INPUT_GLSL && DXGL_GLSL_FROM_HLSLCROSSCOMPILER
#include <hlslcc_bin.hpp>
namespace NCryOpenGL
{
GLBlitFramebufferHelper::GLBlitFramebufferHelper(CContext& context)
: m_context(context)
, m_initialized(false)
, m_UVMatrixCache(ZERO)
{
ZeroMemory(&m_samplerState, sizeof(m_samplerState));
}
GLBlitFramebufferHelper::~GLBlitFramebufferHelper()
{
Reset();
}
bool GLBlitFramebufferHelper::Initialize()
{
if (m_initialized)
{
return true;
}
m_vertexShader.m_eType = eST_Vertex;
m_fragmentShader.m_eType = eST_Fragment;
size_t vsLength = strlen(s_blitVertexShader) + 1;
size_t fsLength = strlen(s_blitFragmentShader) + 1;
size_t vsDataSize = GLSL_RESOURCE_SIZE + vsLength;
size_t fsDataSize = GLSL_SAMPLER_SIZE + fsLength;
// In order to reuse the code to compile the vertex/fragment shaders and initialize the resources
// we add some DXBC metadata to the shaders data.
AZStd::vector<uint8> buffer(AZStd::max(vsDataSize, fsDataSize));
SDXBCOutputBuffer vertStream(buffer.data(), buffer.data() + buffer.size());
const char* uniformBufferPos = strstr(s_blitVertexShader, s_uniformBufferName);
if (!uniformBufferPos)
{
Reset();
return false;
}
uint32 uniformBufferOffset = static_cast<uint32>(uniformBufferPos - s_blitVertexShader);
DXBCWriteUint32(vertStream, DXBC::EncodeResourceIndex(0));
DXBCWriteUint32(vertStream, DXBC::EncodeEmbeddedName(uniformBufferOffset, strlen(s_uniformBufferName)));
vertStream.Write(s_blitVertexShader, vsLength);
m_vertexShader.m_akVersions[eSV_Normal].m_kReflection.m_uNumUniformBuffers = 1;
m_vertexShader.m_akVersions[eSV_Normal].m_kReflection.m_uGLSLSourceOffset = GLSL_RESOURCE_SIZE;
m_vertexShader.m_akVersions[eSV_Normal].m_kSource.SetData(reinterpret_cast<const char*>(buffer.data()), vsDataSize);
SDXBCOutputBuffer fragStream(buffer.data(), buffer.data() + buffer.size());
const char* textureName = strstr(s_blitFragmentShader, s_tex0SamplerName);
if (!textureName)
{
Reset();
return false;
}
uint32 textureOffset = static_cast<uint32>(textureName - s_blitFragmentShader);
DXBCWriteUint32(fragStream, DXBC::EncodeTextureData(0, 0, 0, true, false));
DXBCWriteUint32(fragStream, DXBC::EncodeEmbeddedName(textureOffset, strlen(s_tex0SamplerName)));
DXBCWriteUint32(fragStream, 0);
fragStream.Write(s_blitFragmentShader, fsLength);
m_fragmentShader.m_akVersions[eSV_Normal].m_kReflection.m_uNumSamplers = 1;
m_fragmentShader.m_akVersions[eSV_Normal].m_kReflection.m_uGLSLSourceOffset = GLSL_SAMPLER_SIZE;
m_fragmentShader.m_akVersions[eSV_Normal].m_kSource.SetData(reinterpret_cast<const char*>(buffer.data()), buffer.size());
SShaderReflectionParameter paramReflection;
paramReflection.m_kDesc.SemanticName = s_vertexInput0;
paramReflection.m_kDesc.SemanticIndex = 0;
paramReflection.m_kDesc.Register = 0;
paramReflection.m_kDesc.ComponentType = D3D_REGISTER_COMPONENT_FLOAT32;
m_vertexShader.m_akVersions[eSV_Normal].m_kReflection.m_kInputs.push_back(paramReflection);
// Pos.x, Pos.y, U, V
const float QUAD[] =
{
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
};
D3D11_BUFFER_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.ByteWidth = sizeof(QUAD);
desc.Usage = D3D11_USAGE_IMMUTABLE;
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
D3D11_SUBRESOURCE_DATA data;
ZeroMemory(&data, sizeof(data));
data.pSysMem = &QUAD;
m_vertexBuffer = CreateBuffer(desc, &data, &m_context);
if (!m_vertexBuffer)
{
Reset();
return false;
}
ZeroMemory(&desc, sizeof(desc));
m_UVMatrixCache.SetIdentity();
desc.ByteWidth = sizeof(m_UVMatrixCache);
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
ZeroMemory(&data, sizeof(data));
data.pSysMem = m_UVMatrixCache.GetData();
m_constantBuffer = CreateBuffer(desc, &data, &m_context);
if (!m_constantBuffer)
{
Reset();
return false;
}
D3D11_INPUT_ELEMENT_DESC inputDesc;
inputDesc.SemanticName = s_vertexInput0;
inputDesc.SemanticIndex = 0;
inputDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
inputDesc.InputSlot = 0;
inputDesc.AlignedByteOffset = 0;
inputDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
inputDesc.InstanceDataStepRate = 0;
m_layout = CreateInputLayout(&inputDesc, 1, m_vertexShader.m_akVersions[eSV_Normal].m_kReflection, m_context.m_pDevice);
if (!m_layout)
{
Reset();
return false;
}
D3D11_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(samplerDesc));
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
if (!InitializeSamplerState(samplerDesc, m_samplerState, &m_context))
{
Reset();
return false;
}
m_minFilterCache = GL_NEAREST;
m_magFilterCache = GL_NEAREST;
m_depthStencilState.m_bDepthTestingEnabled = false;
m_depthStencilState.m_bStencilTestingEnabled = false;
m_depthStencilState.m_bDepthWriteMask = false;
m_rasterState.m_bCullingEnabled = false;
m_rasterState.m_bDepthClipEnabled = true;
m_rasterState.m_bPolygonOffsetEnabled = false;
m_rasterState.m_eFrontFaceMode = GL_CCW;
#if !DXGLES
m_rasterState.m_ePolygonMode = GL_FILL;
m_rasterState.m_bMultisampleEnabled = false;
m_rasterState.m_bLineSmoothEnabled = false;
#endif
m_blendState.m_bAlphaToCoverageEnable = false;
m_blendState.m_bIndependentBlendEnable = false;
for (int i = 0; i < DXGL_ARRAY_SIZE(m_blendState.m_kTargets); ++i)
{
STargetBlendState& targetBlendState = m_blendState.m_kTargets[i];
targetBlendState.m_bEnable = false;
targetBlendState.m_bSeparateAlpha = false;
for (int j = 0; j < DXGL_ARRAY_SIZE(targetBlendState.m_kWriteMask.m_abRGBA); ++j)
{
targetBlendState.m_kWriteMask.m_abRGBA[j] = true;
}
}
m_initialized = true;
return m_initialized;
}
bool GLBlitFramebufferHelper::BlitTexture(SShaderTextureView* srcTexture,
SFrameBufferObject& dstFBO,
GLenum dstColorBuffer,
GLint srcXMin, GLint srcYMin, GLint srcXMax, GLint srcYMax,
GLint dstXMin, GLint dstYMin, GLint dstXMax, GLint dstYMax,
GLenum minFilter, GLenum magFilter)
{
PROFILE_LABEL_SCOPE("BlitTexture");
if (!Initialize())
{
AZ_Assert(false, "Failed to initialize GLBlitFrameBufferHelper");
return false;
}
float textWidth = static_cast<float>(srcTexture->m_pTexture->m_iWidth);
float textHeight = static_cast<float>(srcTexture->m_pTexture->m_iHeight);
Vec3 scale(1.0f);
scale.x = (srcXMax - srcXMin) / textWidth;
scale.y = (srcYMax - srcYMin) / textHeight;
Vec3 translate(0.f);
translate.x = srcXMin / textWidth;
translate.y = srcYMin / textHeight;
Matrix34 UVMatrix = Matrix34::CreateScale(scale);
UVMatrix.SetTranslation(translate);
// Check if we need to update the constant buffer
if (!Matrix34::IsEquivalent(m_UVMatrixCache, UVMatrix))
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
// Map buffer and discard previous content
if (!(*m_constantBuffer->m_pfMapSubresource)(m_constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource, &m_context))
{
AZ_Assert(false, "Failed to map constant buffer");
return false;
}
memcpy(mappedResource.pData, UVMatrix.GetData(), sizeof(UVMatrix));
(*m_constantBuffer->m_pfUnmapSubresource)(m_constantBuffer, 0, &m_context);
m_UVMatrixCache = UVMatrix;
}
// Check if we need to update the sampler
if (m_minFilterCache != minFilter)
{
glSamplerParameteri(m_samplerState.m_uSamplerObjectNoMip, GL_TEXTURE_MIN_FILTER, minFilter);
glSamplerParameteri(m_samplerState.m_uSamplerObjectMip, GL_TEXTURE_MIN_FILTER, minFilter);
}
if (m_magFilterCache != magFilter)
{
glSamplerParameteri(m_samplerState.m_uSamplerObjectNoMip, GL_TEXTURE_MAG_FILTER, magFilter);
glSamplerParameteri(m_samplerState.m_uSamplerObjectMip, GL_TEXTURE_MIN_FILTER, minFilter);
}
D3D11_VIEWPORT viewport;
viewport.TopLeftX = static_cast<FLOAT>(dstXMin);
viewport.TopLeftY = static_cast<FLOAT>(dstYMin);
viewport.Width = static_cast<FLOAT>(dstXMax - dstXMin);
viewport.Height = static_cast<FLOAT>(dstYMax - dstYMin);
viewport.MinDepth = 0.f;
viewport.MaxDepth = 1.f;
// Set context states
m_context.SetViewports(1, &viewport);
m_context.SetDepthStencilState(m_depthStencilState, 0);
m_context.SetRasterizerState(m_rasterState);
m_context.SetBlendState(m_blendState);
m_context.SetVertexBuffer(0, m_vertexBuffer, sizeof(float) * 4, 0);
m_context.SetInputLayout(m_layout);
m_context.SetShader(&m_vertexShader, eST_Vertex);
m_context.SetShader(&m_fragmentShader, eST_Fragment);
m_context.SetSampler(&m_samplerState, eST_Fragment, 0);
m_context.SetShaderTexture(srcTexture, eST_Fragment, 0);
m_context.SetConstantBuffer(m_constantBuffer, SBufferRange(0, sizeof(UVMatrix)), eST_Vertex, 0);
#if !DXGL_SUPPORT_DRAW_WITH_BASE_VERTEX
m_context.SetVertexOffset(0);
#endif
// Flush context states
m_context.FlushInputAssemblerState();
m_context.FlushPipelineState();
m_context.FlushTextureUnits();
m_context.FlushUniformBufferUnits();
// We manually bind the draw framebuffer and enable the correct draw buffer
m_context.BindDrawFrameBuffer(dstFBO.m_kName);
SFrameBufferObject::TColorAttachmentMask kDstDrawMask(false);
if (GL_COLOR_ATTACHMENT0 <= dstColorBuffer && (dstColorBuffer - GL_COLOR_ATTACHMENT0) < SFrameBufferConfiguration::MAX_COLOR_ATTACHMENTS)
{
kDstDrawMask.Set(dstColorBuffer - GL_COLOR_ATTACHMENT0, true);
}
if (CACHE_VAR(dstFBO.m_kDrawMaskCache, kDstDrawMask))
{
glDrawBuffers(1, &dstColorBuffer);
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
return true;
}
void GLBlitFramebufferHelper::Reset()
{
m_vertexBuffer = nullptr;
m_constantBuffer = nullptr;
m_layout = nullptr;
ResetSamplerState(m_samplerState);
m_initialized = false;
}
}
@@ -0,0 +1,67 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <Implementation/GLCommon.hpp>
#include <Implementation/GLState.hpp>
#include <Implementation/GLResource.hpp>
#include <Implementation/GLShader.hpp>
namespace NCryOpenGL
{
class CContext;
// Helper class to blit a texture into a framebuffer using a shader.
// This should only be used if glBlitFramebuffer is not an option.
class GLBlitFramebufferHelper
{
public:
explicit GLBlitFramebufferHelper(CContext& context);
~GLBlitFramebufferHelper();
bool BlitTexture(SShaderTextureView* srcTexture,
SFrameBufferObject& dstFBO,
GLenum dstColorBuffer,
GLint srcXMin, GLint srcYMin, GLint srcXMax, GLint srcYMax,
GLint dstXMin, GLint dstYMin, GLint dstXMax, GLint dstYMax,
GLenum minFilter, GLenum magFilter);
private:
bool Initialize();
void Reset();
// Shader source code definitions
static const char* s_uniformBufferName;
static const char* s_tex0SamplerName;
static const char* s_vertexInput0;
static const char* s_blitVertexShader;
static const char* s_blitFragmentShader;
bool m_initialized;
CContext& m_context;
SShader m_vertexShader;
SShader m_fragmentShader;
SBufferPtr m_vertexBuffer;
SBufferPtr m_constantBuffer;
SInputLayoutPtr m_layout;
SSamplerState m_samplerState;
SDepthStencilState m_depthStencilState;
SRasterizerState m_rasterState;
SBlendState m_blendState;
// Cache variables
GLenum m_minFilterCache;
GLenum m_magFilterCache;
Matrix34 m_UVMatrixCache;
};
}
@@ -0,0 +1,43 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
namespace NCryOpenGL
{
const char* GLBlitFramebufferHelper::s_uniformBufferName = "vcPER_BATCH";
const char* GLBlitFramebufferHelper::s_tex0SamplerName = "text0";
const char* GLBlitFramebufferHelper::s_vertexInput0 = "Input0";
const char* GLBlitFramebufferHelper::s_blitVertexShader =
"precision highp float;"
"layout(std140) uniform;"
"layout(location = 0) in highp vec4 Input0;"
"layout(location = 0) out highp vec4 VtxOutput0;"
"uniform vcPER_BATCH"
"{"
" mat4x3 UVMatrix;"
"};"
"void main()"
"{"
" gl_Position = vec4(Input0.xy, 0, 1);"
" VtxOutput0 = vec3(Input0.zw, 1.0) * UVMatrix;"
"}";
const char* GLBlitFramebufferHelper::s_blitFragmentShader =
"precision highp float;"
"layout(location = 0) in highp vec4 VtxOutput0;"
"layout(location = 0) out vec4 Output0;"
"uniform sampler2D text0;"
"void main()"
"{"
" Output0 = texture(text0, VtxOutput0.xy);"
"}";
}
@@ -0,0 +1,79 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declares the types and functions that implement the
// OpenGL rendering functionality of DXGL
#ifndef __GLCOMMON__
#define __GLCOMMON__
#include "GLPlatform.hpp"
#define DXGLES DXGLES_REQUIRED_VERSION > 0
//This is also defined in CryDXGL.hpp
#if DXGLES && !defined(OPENGL_ES)
#define OPENGL_ES
#endif //DXGLES && !defined(OPENGL_ES)
#ifdef WIN32
#include <WinGDI.h>
#endif //WIN32
#define DXGL_NSIGHT_VERSION_3_0 30
#define DXGL_NSIGHT_VERSION_3_1 31
#define DXGL_NSIGHT_VERSION_3_2 32
#define DXGL_NSIGHT_VERSION_4_0 40
#define DXGL_NSIGHT_VERSION_4_1 41
#define DXGL_NSIGHT_VERSION_4_5 45
#define DXGL_SUPPORT_NSIGHT_VERSION 0
#define DXGL_SUPPORT_APITRACE 0
#define DXGL_SUPPORT_VOGL 0
#define DXGL_GLSL_FROM_HLSLCROSSCOMPILER 1
// Uncomment to enable temporary fix for AMD drivers with a fixed number of texture units
// #define DXGL_MAX_TEXTURE_UNITS 32
#define DXGL_SUPPORT_NSIGHT(_Version) (DXGL_SUPPORT_NSIGHT_VERSION == DXGL_NSIGHT_VERSION_ ## _Version)
#define DXGL_SUPPORT_NSIGHT_SINCE(_Version) (DXGL_SUPPORT_NSIGHT_VERSION && DXGL_SUPPORT_NSIGHT_VERSION <= DXGL_NSIGHT_VERSION_ ## _Version)
#define DXGL_TRACE_CALLS 0
#define DXGL_TRACE_CALLS_FLUSH 0
#define DXGL_CHECK_ERRORS 0
#ifndef NO_INCLUDE_GL_FEATURES
#include "GLFeatures.hpp"
#if defined(AZ_RESTRICTED_PLATFORM)
#include AZ_RESTRICTED_FILE(GLCommon_hpp)
#endif
namespace NCryOpenGL
{
#if defined(DXGL_USE_EGL)
struct SDisplayConnection;
typedef _smart_ptr<SDisplayConnection> TWindowContext;
typedef EGLContext TRenderingContext;
#elif defined(WIN32)
typedef HDC TWindowContext;
typedef HGLRC TRenderingContext;
#else
#error "Platform specific context not defined"
#endif
}
#endif // NO_INCLUDE_GL_FEATURES
#endif //__GLCOMMON__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,926 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declaration of the type CContext.
#ifndef __GLCONTEXT__
#define __GLCONTEXT__
#include "GLCommon.hpp"
#include "GLFormat.hpp"
#include "GLState.hpp"
#include "GLResource.hpp"
#include "GLShader.hpp"
#include "GLView.hpp"
#include "GLBlitFramebufferHelper.hpp"
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzFramework/API/ApplicationAPI.h>
namespace NCryOpenGL
{
enum
{
// Slots are the virtual binding points accessible through the Direct3D interface
MAX_STAGE_TEXTURE_SLOTS = D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
MAX_STAGE_SAMPLER_SLOTS = D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT,
MAX_STAGE_IMAGE_SLOTS = D3D11_PS_CS_UAV_REGISTER_COUNT,
MAX_STAGE_STORAGE_BUFFER_SLOTS = D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
MAX_STAGE_CONSTANT_BUFFER_SLOTS = D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
MAX_TEXTURE_SLOTS = eST_NUM * MAX_STAGE_TEXTURE_SLOTS,
MAX_SAMPLER_SLOTS = eST_NUM * MAX_STAGE_SAMPLER_SLOTS,
MAX_IMAGE_SLOTS = eST_NUM * MAX_STAGE_IMAGE_SLOTS,
MAX_STORAGE_BUFFER_SLOTS = eST_NUM * MAX_STAGE_STORAGE_BUFFER_SLOTS,
MAX_CONSTANT_BUFFER_SLOTS = eST_NUM * MAX_STAGE_CONSTANT_BUFFER_SLOTS,
// Units are the actual OpenGL binding points for resources - these are maximum numbers -
// the actual supported counts are queried at runtime.
MAX_TEXTURE_UNITS = eST_NUM * 64,
MAX_IMAGE_UNITS = eST_NUM * 8,
MAX_STORAGE_BUFFER_UNITS = eST_NUM * 64,
MAX_UNIFORM_BUFFER_UNITS = eST_NUM * 16,
MAX_VERTEX_ATTRIBUTES = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
#if DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
MAX_VERTEX_ATTRIB_BINDINGS = MAX_VERTEX_ATTRIBUTES,
#endif //DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
#if DXGL_STREAMING_CONSTANT_BUFFERS
MAX_PREVIOUS_FRAMES = 4,
#endif // DXGL_STREAMING_CONSTANT_BUFFERS
};
COMPILE_TIME_ASSERT((uint32)MAX_TEXTURE_SLOTS <= (uint32)SUnitMap::MAX_TEXTURE_SLOT_IN_MAP);
COMPILE_TIME_ASSERT((uint32)MAX_SAMPLER_SLOTS <= (uint32)SUnitMap::MAX_SAMPLER_SLOT_IN_MAP);
COMPILE_TIME_ASSERT((uint32)MAX_TEXTURE_UNITS <= (uint32)SUnitMap::MAX_TEXTURE_UNIT_IN_MAP);
inline uint32 TextureSlot(EShaderType eStage, uint32 uIndex) { return uIndex + eStage * MAX_STAGE_TEXTURE_SLOTS; }
inline uint32 SamplerSlot(EShaderType eStage, uint32 uIndex) { return uIndex + eStage * MAX_STAGE_SAMPLER_SLOTS; }
inline uint32 ImageSlot(EShaderType eStage, uint32 uIndex) { return uIndex + eStage * MAX_STAGE_IMAGE_SLOTS; }
inline uint32 StorageBufferSlot(EShaderType eStage, uint32 uIndex) { return uIndex + eStage * MAX_STAGE_STORAGE_BUFFER_SLOTS; }
inline uint32 ConstantBufferSlot(EShaderType eStage, uint32 uIndex) { return uIndex + eStage * MAX_STAGE_CONSTANT_BUFFER_SLOTS; }
struct SGlobalConfig
{
#if DXGL_STREAMING_CONSTANT_BUFFERS
static int iStreamingConstantBuffersMode;
static int iStreamingConstantBuffersPersistentMap;
static int iStreamingConstantBuffersGranularity;
static int iStreamingConstantBuffersGrowth;
static int iStreamingConstantBuffersMaxUnits;
#endif
static int iMinFramePoolSize;
static int iMaxFramePoolSize;
static int iBufferUploadMode;
#if DXGL_ENABLE_SHADER_TRACING
static int iShaderTracingMode;
static int iShaderTracingHash;
static int iVertexTracingID;
static int iPixelTracingX;
static int iPixelTracingY;
#endif
static void RegisterVariables();
static void SetIHVDefaults();
};
// The reference values for the stencil operations
struct SStencilRefCache
{
// Stencil reference value for front-facing polygons and non-polygons
GLint m_iFrontFacesReference;
// Stencil reference value for back-facing polygons
GLint m_iBackFacesReference;
};
// Additional OpenGL internal state that is implicitly mapped to the depth stencil state
struct SDepthStencilCache
: SDepthStencilState
{
SStencilRefCache m_kStencilRef;
};
typedef SBlendState SBlendCache;
// Additional OpenGL internal state that is implicitly mapped to the rasterizer state
struct SRasterizerCache
: SRasterizerState
{
bool m_bPolygonOffsetFillEnabled;
#if !DXGLES
bool m_bPolygonOffsetLineEnabled;
#endif //!DXGLES
};
// Additional OpenGL internal state that is implicitly mapped to the texture unit state
struct STextureUnitCache
{
CResourceName m_kTextureName;
GLenum m_eTextureTarget;
GLuint m_uSampler;
};
struct STextureSlot
{
SShaderTextureBasedView* m_pView;
STextureSlot()
: m_pView(NULL)
{
}
bool operator==(const STextureSlot& kOther) const
{
return m_pView == kOther.m_pView;
}
bool operator!=(const STextureSlot& kOther) const
{
return !operator==(kOther);
}
};
struct SSamplerSlot
{
SSamplerState* m_pSampler;
SSamplerSlot(SSamplerState* pSampler = NULL)
: m_pSampler(pSampler)
{
}
bool operator==(const SSamplerSlot& kOther) const
{
return m_pSampler == kOther.m_pSampler;
}
bool operator!=(const SSamplerSlot& kOther) const
{
return !operator==(kOther);
}
};
struct STextureUnitContext
{
STextureUnitCache m_kCurrentUnitState;
std::vector<STexture*> m_kModifiedTextures;
};
#if DXGL_SUPPORT_SHADER_IMAGES
struct SImageUnitCache
{
CResourceName m_kTextureName;
SShaderImageViewConfiguration m_kConfiguration;
};
#endif //DXGL_SUPPORT_SHADER_IMAGES
// Additional OpenGL internal state that is implicitly mapped to the input assembler state
struct SInputAssemblerCache
{
typedef uint32 TAttributeBitMask;
// Bit mask with 1 in the position of every vertex attribute enabled
TAttributeBitMask m_uVertexAttribsEnabled;
GLuint m_auVertexAttribDivisors[MAX_VERTEX_ATTRIBUTES];
struct SVertexAttribPointer
{
GLint m_iSize;
GLenum m_eType;
GLboolean m_bNormalized;
GLsizei m_iStride;
GLvoid* m_pPointer;
GLboolean m_bInteger;
bool operator == (const SVertexAttribPointer& kOther) const
{
return
m_iSize == kOther.m_iSize &&
m_eType == kOther.m_eType &&
m_bNormalized == kOther.m_bNormalized &&
m_iStride == kOther.m_iStride &&
m_pPointer == kOther.m_pPointer &&
m_bInteger == kOther.m_bInteger;
}
bool operator != (const SVertexAttribPointer& kOther) const
{
return !operator==(kOther);
}
};
SVertexAttribPointer m_auVertexAttribPointer[MAX_VERTEX_ATTRIBUTES];
struct SVertexAttribFormat
{
GLint m_iSize;
GLuint m_uRelativeOffset;
GLenum m_eType;
GLboolean m_bNormalized;
GLboolean m_bInteger;
bool operator == (const SVertexAttribFormat& kOther) const
{
return
m_iSize == kOther.m_iSize &&
m_uRelativeOffset == kOther.m_uRelativeOffset &&
m_eType == kOther.m_eType &&
m_bNormalized == kOther.m_bNormalized &&
m_bInteger == kOther.m_bInteger;
}
bool operator != (const SVertexAttribFormat& kOther) const
{
return !operator==(kOther);
}
};
SVertexAttribFormat m_aVertexAttribFormats[MAX_VERTEX_ATTRIBUTES];
GLuint m_auVertexBindingIndices[MAX_VERTEX_ATTRIBUTES];
#if DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
// vertex buffer bindings (note that we don't cache buffer, offset and stride since those change for each call to glBindVertexBuffers
GLuint m_auVertexBindingDivisors[MAX_VERTEX_ATTRIB_BINDINGS];
// watermark so we can avoid sending redundant state
GLint m_iLastNonZeroBindingSlot;
#endif //DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
};
struct SInputAssemblerSlot
{
SBuffer* m_pVertexBuffer;
uint32 m_uStride;
uint32 m_uOffset;
SInputAssemblerSlot()
: m_pVertexBuffer(NULL)
, m_uStride(0)
, m_uOffset(0)
{
}
};
struct SColor
{
GLfloat m_afRGBA[4];
inline bool operator==(const SColor& kOther) const
{
return memcmp(m_afRGBA, kOther.m_afRGBA, sizeof(m_afRGBA)) == 0;
}
inline bool operator!=(const SColor& kOther) const
{
return !operator==(kOther);
}
};
struct SIndexedBufferBinding
{
CResourceName m_kName;
SBufferRange m_kRange;
SIndexedBufferBinding(const CResourceName& kName = CResourceName(), SBufferRange kRange = SBufferRange())
: m_kName(kName)
, m_kRange(kRange)
{
}
bool operator==(const SIndexedBufferBinding& kOther) const
{
return
m_kName == kOther.m_kName &&
m_kRange == kOther.m_kRange;
}
bool operator!=(const SIndexedBufferBinding& kOther) const
{
return !operator==(kOther);
}
};
typedef SIndexedBufferBinding TIndexedBufferBinding;
#if DXGL_SUPPORT_VIEWPORT_ARRAY
typedef GLdouble TDepthRangeValue;
typedef GLfloat TViewportValue;
#else
typedef GLclampf TDepthRangeValue;
typedef GLuint TViewportValue;
#endif
// The state that is not directly mapped to any of the DirectX 11 states
struct SImplicitStateCache
{
// The name of the frame buffer currently to GL_DRAW_FRAMEBUFFER
CResourceName m_kDrawFrameBuffer;
// The name of the frame buffer currently to GL_READ_FRAMEBUFFER
CResourceName m_kReadFrameBuffer;
#if !DXGLES
// The enable state of GL_FRAMEBUFFER_SRGB
bool m_bFrameBufferSRGBEnabled;
#endif //!DXGLES
#if DXGL_SUPPORT_MULTISAMPLED_TEXTURES
bool m_bSampleMaskEnabled;
GLbitfield m_aSampleMask;
#endif //DXGL_SUPPORT_MULTISAMPLED_TEXTURES
SColor m_akBlendColor;
// Viewport xy ranges
TViewportValue m_akViewportData[DXGL_NUM_SUPPORTED_VIEWPORTS * 4];
// Viewport depth ranges
TDepthRangeValue m_akDepthRangeData[DXGL_NUM_SUPPORTED_VIEWPORTS * 2];
#if DXGL_SUPPORT_TESSELLATION
GLint m_iNumPatchControlPoints;
#endif //DXGL_SUPPORT_TESSELLATION
// The buffer currently bound to each buffer target
CResourceName m_akBuffersBound[eBB_NUM];
// The buffer range currently bound to each indexed buffer
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
TIndexedBufferBinding m_akStorageBuffersBound[MAX_STORAGE_BUFFER_UNITS];
#endif //DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
TIndexedBufferBinding m_akUniformBuffersBound[MAX_UNIFORM_BUFFER_UNITS];
// Pixelstore values
GLint m_iUnpackRowLength;
GLint m_iUnpackImageHeight;
GLint m_iUnpackAlignment;
GLint m_iPackRowLength;
#if !DXGLES
GLint m_iPackImageHeight;
#endif //!DXGLES
GLint m_iPackAlignment;
GLenum m_glActiveTexture;
};
// Stores the current state of an OpenGL so that the device can lazily update
// states without the overhead of calling glGet* functions.
struct SStateCache
: SImplicitStateCache
{
SBlendCache m_kBlend;
SDepthStencilCache m_kDepthStencil;
SRasterizerCache m_kRasterizer;
SStencilRefCache m_kStencilRef;
STextureUnitCache m_akTextureUnits[MAX_TEXTURE_UNITS];
#if DXGL_SUPPORT_SHADER_IMAGES
SImageUnitCache m_akImageUnits[MAX_IMAGE_UNITS];
#endif //DXGL_SUPPORT_SHADER_IMAGES
SInputAssemblerCache m_kInputAssembler;
GLint m_akGLScissorData[DXGL_NUM_SUPPORTED_SCISSOR_RECTS * 4];
};
#if DXGL_ENABLE_SHADER_TRACING
struct SVertexShaderTraceHeader
{
uint32 m_uVertexID;
};
struct SFragmentShaderTraceHeader
{
float m_afFragmentCoordX;
float m_afFragmentCoordY;
};
struct SVertexShaderTraceInfo
{
SVertexShaderTraceHeader m_kHeader;
uint32 m_uVertexIndex;
};
struct SFragmentShaderTraceInfo
{
SFragmentShaderTraceHeader m_kHeader;
uint32 m_uFragmentCoordX;
uint32 m_uFragmentCoordY;
};
#endif //DXGL_ENABLE_SHADER_TRACING
#if DXGL_STREAMING_CONSTANT_BUFFERS
struct SConstantBufferSlot
{
SBuffer* m_pBuffer;
SBufferRange m_kRange;
SConstantBufferSlot()
: m_pBuffer(NULL) {}
};
typedef SConstantBufferSlot TConstantBufferSlot;
struct SContextFrame
{
GLsync m_pEndFence;
uint32 m_uRefCount;
SContextFrame** m_pFreeHead;
SContextFrame* m_pNext;
SContextFrame(SContextFrame** pFreeHead)
: m_uRefCount(0)
, m_pFreeHead(pFreeHead)
, m_pEndFence(NULL)
{
}
~SContextFrame()
{
m_pNext = *m_pFreeHead;
* m_pFreeHead = this;
}
void AddRef()
{
++m_uRefCount;
}
void Release()
{
if (--m_uRefCount == 0)
{
this->~SContextFrame();
}
}
};
struct SStreamingBuffer
{
CResourceName m_kName;
uint32 m_uSectionCapacity;
uint32 m_uRequestedSectionSize;
uint32 m_uNextPosition;
uint32 m_uEndPosition;
#if DXGL_SUPPORT_BUFFER_STORAGE
GLvoid* m_pMappedData;
#endif
SStreamingBuffer()
: m_uSectionCapacity(0)
, m_uRequestedSectionSize(0)
, m_uNextPosition(0)
, m_uEndPosition(0)
#if DXGL_SUPPORT_BUFFER_STORAGE
, m_pMappedData(NULL)
#endif
{
}
~SStreamingBuffer()
{
if (m_kName.IsValid())
{
GLuint uName(m_kName.GetName());
glDeleteBuffers(1, &uName);
}
}
};
struct SStreamingBufferContext
{
SContextFramePtr m_spCurrentFrame;
SContextFramePtr m_aspPreviousFrames[MAX_PREVIOUS_FRAMES];
SContextFrame* m_pFreeFramesHead;
std::vector<SContextFrame*> m_kFramePools;
uint32 m_uPreviousFrameIndex, m_uNumPreviousFrames;
#if DXGL_SUPPORT_BUFFER_STORAGE
bool m_bFlushNeeded;
#endif
SStreamingBuffer m_akStreamingBuffers[MAX_UNIFORM_BUFFER_UNITS];
uint32 m_uNumStreamingBuffersUnits;
SStreamingBufferContext();
~SStreamingBufferContext();
void SwitchFrame(CDevice* pDevice);
void UpdateStreamingSizes(CDevice* pDevice);
void UploadAndBindUniformData(CContext* pContext, const SConstantBufferSlot& kSlot, uint32 uUnit);
void FlushUniformData();
};
#else
typedef TIndexedBufferBinding TConstantBufferSlot;
#endif
class CContext
: public SList::TListEntry
, public AzFramework::ApplicationLifecycleEvents::Bus::Handler
{
#if DXGL_STREAMING_CONSTANT_BUFFERS
friend struct SStreamingBufferContext;
#endif
public:
enum ContextType
{
RenderingType, // Context used to render to a window
ResourceType, // Context used for loading resources
NumContextTypes // Must be last one
};
CContext(
CDevice* pDevice,
const TRenderingContext& kRenderingContext,
const TWindowContext& kDefaultWindowContext,
uint32 uIndex,
ContextType type);
~CContext();
bool Initialize();
// Context management
uint32 IncReservationCount() { return ++m_uReservationCount; }
uint32 DecReservationCount() { return --m_uReservationCount; }
const TRenderingContext& GetRenderingContext() { return m_kRenderingContext; }
const TWindowContext& GetWindowContext() { return m_kWindowContext; }
CDevice* GetDevice() { return m_pDevice; }
uint32 GetIndex() { return m_uIndex; }
ContextType GetType() const { return m_type; }
CContext* GetReservedContext() { return m_pReservedContext; }
void SetReservedContext(CContext* pReservedContext) { m_pReservedContext = pReservedContext; }
void SetWindowContext(const TWindowContext& kWindowContext);
// Explicit state
bool SetBlendState(const SBlendState& kState);
bool SetRasterizerState(const SRasterizerState& kState);
bool SetDepthStencilState(const SDepthStencilState& kDepthStencilState, GLint iStencilRef);
void SetBlendColor(GLfloat afRed, GLfloat fGreen, GLfloat fBlue, GLfloat fAlpha);
void SetSampleMask(GLbitfield aSampleMask);
void SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY eTopology);
void SetViewports(uint32 uNumViewports, const D3D11_VIEWPORT* pViewports);
void SetScissorRects(uint32 uNumRects, const D3D11_RECT* pRects);
void SetRenderTargets(uint32 uNumRTViews, SOutputMergerView** apRenderTargetViews, SOutputMergerView* pDepthStencilView);
void SetShader(SShader* pShader, uint32 uStage);
void SetInputLayout(SInputLayout* pInputLayout);
void SetVertexBuffer(uint32 uSlot, SBuffer* pVertexBuffer, uint32 uStride, uint32 uOffset);
void SetIndexBuffer(SBuffer* pIndexBuffer, GLenum eIndexType, GLuint uIndexStride, GLuint uOffset);
void SetShaderResourceView(SShaderView* pShaderResourceView, uint32 uStage, uint32 uIndex);
void SetUnorderedAccessView(SShaderView* pUnorderedResourceView, uint32 uStage, uint32 uIndex);
void SetSampler(SSamplerState* pState, uint32 uStage, uint32 uIndex);
void SetConstantBuffer(SBuffer* pConstantBuffer, SBufferRange kRange, uint32 uStage, uint32 uIndex);
// Implicit state
void SetShaderTexture(SShaderTextureBasedView* pView, uint32 uStage, uint32 uIndex);
#if DXGL_SUPPORT_SHADER_IMAGES
void SetShaderImage(SShaderImageView* pView, uint32 uStage, uint32 uIndex);
#endif
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
void SetShaderBuffer(SShaderBufferView* pView, uint32 uStage, uint32 uIndex);
#endif
void SetUnpackRowLength(GLint iValue);
void SetUnpackImageHeight(GLint iValue);
void SetUnpackAlignment(GLint iValue);
void SetPackRowLength(GLint iValue);
void SetPackImageHeight(GLint iValue);
void SetPackAlignment(GLint iValue);
GLenum BindBuffer(const CResourceName& kBufferName, EBufferBinding eBinding);
GLenum BindBuffer(SBuffer* pBuffer, EBufferBinding eBinding);
// Commands
void ClearRenderTarget(SOutputMergerView* pRenderTargetView, const float afColor[4]);
void ClearDepthStencil(SOutputMergerView* pDepthStencilView, bool bClearDepth, bool bClearStencil, float fDepthValue, uint8 uStencilValue);
void DrawIndexed(uint32 uIndexCount, uint32 uStartIndexLocation, uint32 uBaseVertexLocation);
void Draw(uint32 uVertexCount, uint32 uStartVertexLocation);
void DrawIndexedInstanced(uint32 uIndexCountPerInstance, uint32 uInstanceCount, uint32 uStartIndexLocation, uint32 uBaseVertexLocation, uint32 uStartInstanceLocation);
void DrawInstanced(uint32 uVertexCountPerInstance, uint32 uInstanceCount, uint32 uStartVertexLocation, uint32 uStartInstanceLocation);
#if DXGL_SUPPORT_COMPUTE
void Dispatch(uint32 uGroupX, uint32 uGroupY, uint32 uGroupZ);
void DispatchIndirect(uint32 uIndirectOffset);
#endif
void Flush();
// Cached objects
_smart_ptr<SFrameBuffer> AllocateFrameBuffer(const SFrameBufferConfiguration& kConfiguration);
void RemoveFrameBuffer(SFrameBuffer* pFrameBuffer, SOutputMergerView* pInvalidView);
_smart_ptr<SPipeline> AllocatePipeline(const SPipelineConfiguration& kConfiguration);
void RemovePipeline(SPipeline* pPipeline, SShader* pInvalidShader);
_smart_ptr<SUnitMap> AllocateUnitMap(_smart_ptr<SUnitMap> spConfiguration);
// Copying
void BlitFrameBuffer(SFrameBufferObject& kSrcFBO, SFrameBufferObject& kDstFBO, GLenum eSrcColorBuffer, GLenum eDstColorBuffer, GLint iSrcXMin, GLint iSrcYMin, GLint iSrcXMax, GLint iSrcYMax, GLint iDstXMin, GLint iDstYMin, GLint iDstXMax, GLint iDstYMax, GLbitfield uMask, GLenum eFilter);
bool BlitOutputMergerView(SOutputMergerView* pSrcView, SOutputMergerView* pDstView, GLint iSrcXMin, GLint iSrcYMin, GLint iSrcXMax, GLint iSrcYMax, GLint iDstXMin, GLint iDstYMin, GLint iDstXMax, GLint iDstYMax, GLbitfield uMask, GLenum eFilter);
void ReadbackFrameBufferAttachment(SFrameBufferObject& kFBO, GLenum eColorBuffer, GLint iXMin, GLint iYMin, GLsizei iWidth, GLint iHeight, GLenum eBaseFormat, GLenum eDataType, GLvoid* pvData);
bool ReadBackOutputMergerView(SOutputMergerView* pView, GLint iXMin, GLint iYMin, GLsizei iWidth, GLint iHeight, GLvoid* pvData);
#if DXGL_ENABLE_SHADER_TRACING
void TogglePixelTracing(bool bEnable, uint32 uShaderHash, uint32 uPixelX = 0, uint32 uPixelY = 0);
void ToggleVertexTracing(bool bEnable, uint32 uShaderHash, uint32 uVertexID = 0);
#endif
#if DXGL_TRACE_CALLS
void CallTraceWrite(const char* szTrace);
void CallTraceFlush();
#endif
const CResourceName& GetCopyPixelBuffer() { AZ_Assert(m_kCopyPixelBuffer.IsValid(), "Invalid copy pixel buffer."); return m_kCopyPixelBuffer; }
inline void NamedBufferDataFast(CResourceName kBufferName, GLsizeiptr iSize, const void* pData, GLenum eUsage);
inline void NamedBufferSubDataFast(CResourceName kBufferName, GLintptr iOffset, GLsizeiptr iSize, const void* pData);
inline GLvoid* MapNamedBufferRangeFast(CResourceName kBufferName, GLintptr iOffset, GLsizeiptr iLength, GLbitfield uAccess);
inline GLboolean UnmapNamedBufferFast(CResourceName kBufferName);
// Confetti Begin: David Srour
// Since binding framebuffers is deferred, we have to ensure that enabling/disabling PLS extension comes after binings.
inline void TogglePLS(bool const enable);
// Should only be called by DXGL layer only.
// This should not be called directly by and should never have to be exposed
// to the higher abstractions of the engine.
void UpdatePlsState(bool const preFramebufferBind);
// Confetti End: David Srour
private:
bool GetBlendCache(SBlendCache& kCache);
bool GetDepthStencilCache(SDepthStencilCache& kDepthStencilCache);
bool GetRasterizerCache(SRasterizerCache& kCache);
bool GetTextureUnitCache(uint32 uUnit, STextureUnitCache& kCache);
#if DXGL_SUPPORT_SHADER_IMAGES
bool GetImageUnitCache(uint32 uUnit, SImageUnitCache& kCache);
#endif
bool GetInputAssemblerCache(SInputAssemblerCache& kCache);
bool GetImplicitStateCache(SImplicitStateCache& kCache);
bool InitializePipeline(SPipeline* pPipeline);
void BindUniformBuffer(const TIndexedBufferBinding& kBufferRange, uint32 uUnit);
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
void BindStorageBuffer(const TIndexedBufferBinding& kBufferRange, uint32 uUnit);
#endif
#if DXGL_SUPPORT_SHADER_IMAGES
void BindImage(const CResourceName& kName, SShaderImageViewConfiguration kConfiguration, uint32 uUnit);
#endif
void BindDrawFrameBuffer(const CResourceName& kName);
void BindReadFrameBuffer(const CResourceName& kName);
void SetNumPatchControlPoints(GLint uNumControlPoints);
#if !DXGL_SUPPORT_DRAW_WITH_BASE_VERTEX
void SetVertexOffset(uint32 uVertexOffset);
#endif
void FlushDrawState();
#if DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
void FlushInputAssemblerStateVab();
#endif
void FlushInputAssemblerState();
void FlushFrameBufferState();
void FlushPipelineState();
#if DXGL_SUPPORT_COMPUTE
void FlushDispatchState();
#endif
void FlushTextureUnits();
void FlushUniformBufferUnits();
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
void FlushStorageBufferUnits();
#endif
#if DXGL_SUPPORT_SHADER_IMAGES
void FlushImageUnits();
#endif
void FlushResourceUnits();
#if DXGL_ENABLE_SHADER_TRACING
void FlushShaderTracingState();
#endif
#if defined(ANDROID)
void FlushFrameBufferDontCareState(bool bOnBind);
#endif
#if defined(DXGL_USE_LAZY_CLEAR)
void FlushFrameBufferLazyClearState();
#endif
void SwitchFrame();
#if DXGL_ENABLE_SHADER_TRACING
void PrepareTraceHeader(uint32 uFirstVertex, uint32 uFirstIndex);
void BeginTrace(uint32 uFirstVertex, uint32 uFirstIndex);
void EndTrace();
#endif
void OnApplicationWindowCreated() override;
void OnApplicationWindowDestroy() override;
protected:
typedef AZStd::pair<uint32, ColorF> ClearColorArg;
void ClearDepthStencilInternal(bool clearDepth, bool clearStencil, float depthValue, uint8 stencilValue);
void ClearRenderTargetInternal(const AZStd::vector<ClearColorArg>& args);
private:
uint32 m_uIndex;
CContext* m_pReservedContext;
CDevice* m_pDevice;
TRenderingContext m_kRenderingContext;
TWindowContext m_kWindowContext;
uint32 m_uReservationCount;
SStateCache m_kStateCache;
GLenum m_ePrimitiveTopologyMode;
GLenum m_eIndexType;
GLuint m_uIndexStride;
GLuint m_uIndexOffset;
SPipelinePtr m_spPipeline;
SFrameBufferPtr m_spFrameBuffer;
GLuint m_uGlobalVAO;
STextureUnitContext m_kTextureUnitContext;
// State that is only synchronized during draw calls
SFrameBufferConfiguration m_kFrameBufferConfig;
SPipelineConfiguration m_kPipelineConfiguration;
SInputLayout* m_pInputLayout;
SInputAssemblerSlot m_akInputAssemblerSlots[MAX_VERTEX_ATTRIBUTES];
STextureSlot m_akTextureSlots[MAX_TEXTURE_SLOTS];
SSamplerSlot m_akSamplerSlots[MAX_SAMPLER_SLOTS];
#if DXGL_SUPPORT_SHADER_IMAGES
SImageUnitCache m_akImageSlots[MAX_IMAGE_SLOTS];
#endif
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
TIndexedBufferBinding m_akStorageBufferSlots[MAX_STORAGE_BUFFER_SLOTS];
#endif
TConstantBufferSlot m_akConstantBufferSlots[MAX_CONSTANT_BUFFER_SLOTS];
SUnitMap* m_apResourceUnitMaps[eRUT_NUM];
#if DXGL_STREAMING_CONSTANT_BUFFERS
SStreamingBufferContext m_kStreamingBuffers;
#endif
#if !DXGL_SUPPORT_DRAW_WITH_BASE_VERTEX
uint32 m_uVertexOffset;
#endif
// Flags that tell which parts of the state need to be synchronized during the next draw call
bool m_bFrameBufferStateDirty;
bool m_bPipelineDirty;
bool m_bInputLayoutDirty;
bool m_bInputAssemblerSlotsDirty;
bool m_abResourceUnitsDirty[eRUT_NUM];
// Confetti Begin: David Srour
// Since binding framebuffers is deferred, we have to ensure that :
// - enabling PLS extension comes after biding FBO.
// - disabling PLS extension before biding FBO.
enum PLS_STATE
{
PLS_IGNORE = 0,
PLS_ENABLE,
PLS_DISABLE
};
PLS_STATE m_PlsExtensionState;
// Confetti End: David Srour
#if DXGL_ENABLE_SHADER_TRACING
CResourceName m_kShaderTracingBuffer;
TIndexedBufferBinding m_kReplacedStorageBuffer;
EShaderType m_eStageTracing;
uint32 m_uShaderTraceHash;
uint32 m_uShaderTraceCount;
union
{
SVertexShaderTraceInfo m_kVertex;
SFragmentShaderTraceInfo m_kFragment;
} m_kStageTracingInfo;
#endif //DXGL_ENABLE_SHADER_TRACING
#if DXGL_TRACE_CALLS
STraceFile m_kCallTrace;
#endif
CResourceName m_kCopyPixelBuffer;
SPipelineCompilationBuffer m_kPipelineCompilationBuffer;
// Hash maps of persistent frame buffers, pipelines and sampler unit maps that can be re-used every time
// a compatible configuration is requested.
struct SFrameBufferCache* m_pFrameBufferCache;
struct SPipelineCache* m_pPipelineCache;
struct SUnitMapCache* m_pUnitMapCache;
ContextType m_type;
public:
// Blit a texture into a framebuffer using a shader instead of the glBlitFramebuffer function.
// If possible use Context::BlitFrameBuffer instead.
bool BlitTextureToFrameBuffer(SShaderTextureView* srcTexture,
SFrameBufferObject& kDstFBO,
GLenum eDstColorBuffer,
GLint iSrcXMin, GLint iSrcYMin, GLint iSrcXMax, GLint iSrcYMax,
GLint iDstXMin, GLint iDstYMin, GLint iDstXMax, GLint iDstYMax,
GLenum minFilter, GLenum magFilter)
{
return m_blitHelper.BlitTexture(srcTexture, kDstFBO, eDstColorBuffer,
iSrcXMin, iSrcYMin, iSrcXMax, iSrcYMax,
iDstXMin, iDstYMin, iDstXMax, iDstYMax,
minFilter, magFilter);
}
private:
friend class GLBlitFramebufferHelper;
GLBlitFramebufferHelper m_blitHelper;
};
template <typename T>
inline bool RefreshCache(T& kCache, T kState)
{
bool bDirty(kCache != kState);
kCache = kState;
return bDirty;
}
#define CACHE_VAR(_Cache, _State) RefreshCache(_Cache, _State)
#define CACHE_FIELD(_Cache, _State, _Member) RefreshCache((_Cache)._Member, (_State)._Member)
inline void CContext::NamedBufferDataFast(CResourceName kBufferName, GLsizeiptr iSize, const void* pData, GLenum eUsage)
{
#if defined(glNamedBufferDataEXT) || !defined(USE_FAST_NAMED_APPROXIMATION)
glNamedBufferDataEXT(kBufferName.GetName(), iSize, pData, eUsage);
#else
if (CACHE_VAR(m_kStateCache.m_akBuffersBound[eBB_CopyWrite], kBufferName))
{
glBindBuffer(GL_COPY_WRITE_BUFFER, kBufferName.GetName());
}
glBufferData(GL_COPY_WRITE_BUFFER, iSize, pData, eUsage);
#endif
}
inline void CContext::NamedBufferSubDataFast(CResourceName kBufferName, GLintptr iOffset, GLsizeiptr iSize, const void* pData)
{
#if defined(glNamedBufferSubDataEXT) || !defined(USE_FAST_NAMED_APPROXIMATION)
glNamedBufferSubDataEXT(kBufferName.GetName(), iOffset, iSize, pData);
#else
if (CACHE_VAR(m_kStateCache.m_akBuffersBound[eBB_CopyWrite], kBufferName))
{
glBindBuffer(GL_COPY_WRITE_BUFFER, kBufferName.GetName());
}
glBufferSubData(GL_COPY_WRITE_BUFFER, iOffset, iSize, pData);
#endif
}
inline GLvoid* CContext::MapNamedBufferRangeFast(CResourceName kBufferName, GLintptr iOffset, GLsizeiptr iLength, GLbitfield uAccess)
{
#if defined(glMapNamedBufferRangeEXT) || !defined(USE_FAST_NAMED_APPROXIMATION)
return glMapNamedBufferRangeEXT(kBufferName.GetName(), iOffset, iLength, uAccess);
#else
if (CACHE_VAR(m_kStateCache.m_akBuffersBound[eBB_CopyWrite], kBufferName))
{
glBindBuffer(GL_COPY_WRITE_BUFFER, kBufferName.GetName());
}
return glMapBufferRange(GL_COPY_WRITE_BUFFER, iOffset, iLength, uAccess);
#endif
}
inline GLboolean CContext::UnmapNamedBufferFast(CResourceName kBufferName)
{
#if defined(glUnmapNamedBufferEXT) || !defined(USE_FAST_NAMED_APPROXIMATION)
return glUnmapNamedBufferEXT(kBufferName.GetName());
#else
if (CACHE_VAR(m_kStateCache.m_akBuffersBound[eBB_CopyWrite], kBufferName))
{
glBindBuffer(GL_COPY_WRITE_BUFFER, kBufferName.GetName());
}
return glUnmapBuffer(GL_COPY_WRITE_BUFFER);
#endif
}
inline void CContext::TogglePLS(bool const enable)
{
// 0 = don't do anything, 1 = enable, 2 = disable
// Toggling the extension must be done in a deferred manner. See m_PlsExtensionState' decleration for further details.
if (enable)
{
m_PlsExtensionState = PLS_ENABLE;
}
else
{
m_PlsExtensionState = PLS_DISABLE;
}
}
}
#endif
@@ -0,0 +1,201 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Platform specific DXGL requirements implementation relying
// on CryCommon and CrySystem.
#ifndef __GLCRYPLATFORM__
#define __GLCRYPLATFORM__
#include "DriverD3D.h"
#include <AzCore/IO/FileIO.h>
#include <AzFramework/IO/FileOperations.h>
namespace NCryOpenGL
{
inline void* Malloc(size_t size)
{
return CryModuleMalloc(size);
}
inline void* Calloc(size_t num, size_t size)
{
return CryModuleCalloc(num, size);
}
inline void* Realloc(void* memblock, size_t size)
{
return CryModuleRealloc(memblock, size);
}
inline void Free(void* memblock)
{
CryModuleFree(memblock);
}
inline void* Memalign(size_t size, size_t alignment)
{
return CryModuleMemalign(size, alignment);
}
inline void MemalignFree(void* memblock)
{
return CryModuleMemalignFree(memblock);
}
void LogMessage(ELogSeverity eSeverity, const char* szFormat, ...) PRINTF_PARAMS(2, 3);
inline void LogMessage(ELogSeverity eSeverity, const char* szFormat, ...)
{
EValidatorSeverity eValidatorSeverity(VALIDATOR_COMMENT);
switch (eSeverity)
{
case eLS_Error:
eValidatorSeverity = VALIDATOR_ERROR;
break;
case eLS_Warning:
eValidatorSeverity = VALIDATOR_WARNING;
break;
case eLS_Info:
eValidatorSeverity = VALIDATOR_COMMENT;
break;
}
va_list kArgs;
va_start(kArgs, szFormat);
GetISystem()->WarningV(VALIDATOR_MODULE_RENDERER, eValidatorSeverity, 0, 0, szFormat, kArgs);
va_end(kArgs);
}
inline void BreakUnique(const char* file, uint32 line, const char* functionName)
{
AZ_Error("OpenGL Layer", false, "Unimplemented DirectX function %s being called in OpenGL in file %s line %d. Continuing but rendering artifacts may be present.", functionName, file, line);
}
inline uint32 GetCRC32(const void* pData, size_t uSize)
{
return CCrc32::Compute(pData, uSize);
}
inline LONG Exchange(LONG volatile* piDestination, LONG iExchange)
{
#if defined(WIN32)
return InterlockedExchange(piDestination, iExchange);
#else
LONG iOldValue(__sync_lock_test_and_set(piDestination, iExchange));
__sync_synchronize();
return iOldValue;
#endif
}
inline LONG CompareExchange(LONG volatile* piDestination, LONG iExchange, LONG iComparand)
{
return CryInterlockedCompareExchange(piDestination, iExchange, iComparand);
}
inline LONG AtomicIncrement(LONG volatile* piDestination)
{
return CryInterlockedIncrement(reinterpret_cast<int volatile*>(piDestination));
}
inline LONG AtomicDecrement(LONG volatile* piDestination)
{
return CryInterlockedDecrement(reinterpret_cast<int volatile*>(piDestination));
}
typedef CryCriticalSection TCriticalSection;
inline void LockCriticalSection(TCriticalSection* pCriticalSection)
{
pCriticalSection->Lock();
}
inline void UnlockCriticalSection(TCriticalSection* pCriticalSection)
{
pCriticalSection->Unlock();
}
struct STraceFile
{
STraceFile()
: m_fileHandle(AZ::IO::InvalidHandle)
{
}
~STraceFile()
{
if (m_fileHandle != AZ::IO::InvalidHandle)
{
gEnv->pCryPak->FClose(m_fileHandle);
}
}
bool Open(const char* szFileName, bool bBinary)
{
static const char* s_szTraceDirectory = "DXGLTrace";
if (m_fileHandle != AZ::IO::InvalidHandle)
{
return false;
}
char acFullPath[MAX_PATH];
sprintf_s(acFullPath, "%s/%s", s_szTraceDirectory, szFileName);
const char* szMode(bBinary ? "wb" : "w");
m_fileHandle = gEnv->pCryPak->FOpen(acFullPath, szMode);
if (m_fileHandle != AZ::IO::InvalidHandle)
{
return true;
}
gEnv->pCryPak->MakeDir(s_szTraceDirectory, 0);
m_fileHandle = gEnv->pCryPak->FOpen(acFullPath, szMode);
return m_fileHandle != AZ::IO::InvalidHandle;
}
void Write(const void* pvData, uint32 uSize)
{
gEnv->pCryPak->FWrite(pvData, (size_t)uSize, 1, m_fileHandle);
}
void Printf(const char* szFormat, ...)
{
va_list kArgs;
va_start(kArgs, szFormat);
AZ::IO::PrintV(m_fileHandle, szFormat, kArgs);
va_end(kArgs);
}
AZ::IO::HandleType m_fileHandle;
};
inline void RegisterConfigVariable(const char* szName, int* piVariable, int iDefaultValue)
{
gEnv->pConsole->Register(szName, piVariable, iDefaultValue);
}
inline void PushProfileLabel(const char* szName)
{
PROFILE_LABEL_PUSH(szName);
}
inline void PopProfileLabel(const char* szName)
{
PROFILE_LABEL_POP(szName);
}
}
#endif //__GLCRYPLATFORM__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,379 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declaration of the type CDevice and the functions to
// initialize OpenGL contexts and detect hardware
// capabilities.
#ifndef __GLDEVICE__
#define __GLDEVICE__
#if defined(AZ_RESTRICTED_PLATFORM)
#undef AZ_RESTRICTED_SECTION
#define GLDEVICE_HPP_SECTION_1 1
#define GLDEVICE_HPP_SECTION_2 2
#endif
#include "GLCommon.hpp"
#include "GLContext.hpp"
#include <AzFramework/API/ApplicationAPI.h>
#include <AzCore/std/containers/map.h>
// EGL Windows are pointers on some platforms and integers on other platforms, so we can't globally use nullptr
#if defined(AZ_PLATFORM_LINUX)
#define EGL_NULL_VALUE 0
#else
#define EGL_NULL_VALUE nullptr
#endif
namespace NCryOpenGL
{
// Optional device context features
enum EFeature
{
eF_ComputeShader,
eF_IndexedBoolState,
eF_StencilOnlyFormat,
eF_MultiSampledTextures,
eF_DrawIndirect,
eF_StencilTextures,
eF_AtomicCounters,
eF_DispatchIndirect,
eF_ShaderImages,
eF_VertexAttribBinding,
eF_TextureViews,
eF_DepthClipping,
eF_SeparablePrograms,
eF_TextureBorderClamp,
eF_TextureAnisotropicFiltering,
eF_BufferStorage,
eF_MultiBind,
eF_DebugOutput,
eF_DualSourceBlending,
eF_IndependentBlending,
eF_CopyImage,
eF_NUM // Must be last one
};
struct SResourceUnitCapabilities
{
GLint m_aiMaxTotal;
GLint m_aiMaxPerStage[eST_NUM];
};
// Hardware capabilities of a device context
struct SCapabilities
{
GLint m_iMaxSamples;
GLint m_iMaxVertexAttribs;
GLint m_maxRenderTargets;
GLint m_plsSizeInBytes; // 0 when PLS is not supported
RenderCapabilities::FrameBufferFetchMask m_frameBufferFetchSupport;
SResourceUnitCapabilities m_akResourceUnits[eRUT_NUM];
GLint m_iUniformBufferOffsetAlignment;
GLint m_iMaxUniformBlockSize;
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
GLint m_iShaderStorageBufferOffsetAlignment;
#endif
// vertex attrib binding
GLint m_iMaxVertexAttribBindings;
GLint m_iMaxVertexAttribRelativeOffset;
// The supported usage for each GI format (union of D3D11_FORMAT_SUPPORT flags)
uint32 m_auFormatSupport[eGIF_NUM];
// Some drivers implementation of glCopyImageSubData does not work on cube map faces as specified by the standard
bool m_bCopyImageWorksOnCubeMapFaces;
};
struct SVersion
{
int32 m_uMajorVersion;
int32 m_uMinorVersion;
SVersion()
: m_uMajorVersion(0)
, m_uMinorVersion(0)
{}
SVersion(int32 version)
{
m_uMajorVersion = version / 100;
m_uMinorVersion = (version / 10) % 10;
}
uint32 ToUint() const
{
return m_uMajorVersion * 100 + m_uMinorVersion * 10;
}
};
struct SPixelFormatSpec
{
const SUncompressedLayout* m_pLayout;
uint32 m_uNumSamples;
bool m_bSRGB;
};
struct SFrameBufferSpec
: SPixelFormatSpec
{
uint32 m_uWidth;
uint32 m_uHeight;
};
typedef SBitMask<eF_NUM, SUnsafeBitMaskWord> TFeatures;
struct SFeatureSpec
{
TFeatures m_kFeatures;
SVersion m_kVersion;
};
struct SDisplayMode
{
uint32 m_uWidth;
uint32 m_uHeight;
uint32 m_uFrequency;
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION GLDEVICE_HPP_SECTION_1
#include AZ_RESTRICTED_FILE(GLDevice_hpp)
#endif
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
#elif defined(WIN32)
uint32 m_uBitsPerPixel;
#elif defined(ANDROID)
int32_t m_nativeFormat;
#endif
};
struct SResourceUnitPartitionBound
{
uint32 m_uFirstUnit; // Lowest unit index used
uint32 m_uNumUnits; // Number of contiguous unit indices used
};
typedef SResourceUnitPartitionBound TPipelineResourceUnitPartitionBound[eST_NUM];
#if defined(DXGL_USE_EGL)
typedef std::pair<EGLNativeDisplayType, EGLNativeWindowType> EGLNativePlatform;
typedef AZStd::shared_ptr<EGLNativePlatform> TNativeDisplay;
#else
typedef TWindowContext TNativeDisplay;
#endif
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION GLDEVICE_HPP_SECTION_2
#include AZ_RESTRICTED_FILE(GLDevice_hpp)
#endif
#if defined(DXGL_USE_EGL)
DXGL_DECLARE_REF_COUNTED(struct, SDisplayConnection)
{
public:
static SDisplayConnection* Create(const SPixelFormatSpec& kPixelFormatSpec, const TNativeDisplay& kDefaultNativeDisplay);
SDisplayConnection();
~SDisplayConnection();
bool Init(const SPixelFormatSpec& pixelFormatSpec, const TNativeDisplay& defaultNativeDisplay);
bool MakeCurrent(const TRenderingContext context) const;
bool SwapBuffers(const TRenderingContext context);
void SetWindow(EGLNativeWindowType window);
EGLDisplay GetDisplay() const { return m_display; }
EGLConfig GetConfig() const { return m_config; }
EGLDisplay GetSurface() const { return m_surface; }
EGLNativeWindowType GetWindow() const { return m_window; }
protected:
bool CreateSurface();
bool DestroySurface();
#if defined(AZ_PLATFORM_LINUX)
bool CreateX11Window();
#endif
EGLDisplay m_display;
EGLSurface m_surface;
EGLConfig m_config;
EGLNativeWindowType m_window;
bool m_dirtyFlag;
mutable AZStd::mutex m_mutex; // Synchronize window destroy/create events.
};
#endif //defined(DXGL_USE_EGL)
DXGL_DECLARE_REF_COUNTED(struct, SOutput)
{
string m_strDeviceID;
string m_strDeviceName;
std::vector<SDisplayMode> m_kModes;
SDisplayMode m_kDesktopMode;
};
DXGL_DECLARE_REF_COUNTED(struct, SAdapter)
{
string m_strRenderer;
string m_strVendor;
string m_strVersion;
SVersion m_sVersion;
SCapabilities m_kCapabilities;
std::vector<SOutputPtr> m_kOutputs;
TFeatures m_kFeatures;
size_t m_uVRAMBytes;
unsigned int m_eDriverVendor;
AZStd::unordered_set<size_t> m_kExtensions;
void AddExtension(const AZStd::string& kExtension)
{
m_kExtensions.insert(AZStd::hash<AZStd::string>()(kExtension));
}
bool HasExtension(const AZStd::string& kExtension) const
{
return m_kExtensions.find(AZStd::hash<AZStd::string>()(kExtension)) != m_kExtensions.end();
}
};
DXGL_DECLARE_REF_COUNTED(class, CDevice)
, public AzFramework::ApplicationLifecycleEvents::Bus::Handler
{
public:
CDevice(SAdapter * pAdapter, const SFeatureSpec&kFeatureSpec, const SPixelFormatSpec&kPixelFormatSpec);
~CDevice();
#if !DXGL_FULL_EMULATION
static void Configure(uint32 uNumSharedContexts);
#endif //!DXGL_FULL_EMULATION
#if !defined(WIN32)
static bool CreateWindow(const char* title, uint32 width, uint32 height, bool fullscreen, HWND * handle);
static void DestroyWindow(HWND handle);
static void InitWindow(HWND handle, uint32 width, uint32 height);
#endif
bool Initialize(const TNativeDisplay&kDefaultNativeDisplay);
void Shutdown();
bool Present(const TWindowContext&kTargetWindowContext);
CContext* ReserveContext();
void ReleaseContext();
CContext* AllocateContext(CContext::ContextType type = CContext::ResourceType);
void FreeContext(CContext * pContext);
void BindContext(CContext * pContext);
void UnbindContext(CContext * pContext);
void SetCurrentContext(CContext * pContext);
CContext* GetCurrentContext();
uint32 GetMaxContextCount();
void IssueFrameFences();
bool FlushFrameFence(uint32 uContext) { return m_kContextFenceIssued.Set(uContext, false); }
SResourceNamePool& GetTextureNamePool() { return m_kTextureNamePool; }
SResourceNamePool& GetBufferNamePool() { return m_kBufferNamePool; }
SResourceNamePool& GetFrameBufferNamePool() { return m_kFrameBufferNamePool; }
const SIndexPartition& GetResourceUnitPartition(EResourceUnitType eType, uint32 uID) { return m_kResourceUnitPartitions[eType][uID]; }
uint32 GetNumResourceUnitPartitions(EResourceUnitType eType) { return (uint32)m_kResourceUnitPartitions[eType].size(); }
bool SetFullScreenState(const SFrameBufferSpec&kFrameBufferSpec, bool bFullScreen, SOutput * pOutput);
bool ResizeTarget(const SDisplayMode&kTargetMode);
void SetBackBufferTexture(SDefaultFrameBufferTexture * pBackTexture);
SAdapter* GetAdapter() { return m_spAdapter; }
const TWindowContext& GetDefaultWindowContext() { return m_kDefaultWindowContext; }
const SFeatureSpec& GetFeatureSpec() { return m_kFeatureSpec; }
const SPixelFormatSpec& GetPixelFormatSpec() { return m_kPixelFormatSpec; }
bool IsFeatureSupported(EFeature feature) const;
static CDevice* GetCurrentDevice() { return ms_pCurrentDevice; }
protected:
typedef std::vector<CContext*> TContexts;
typedef std::vector<SIndexPartition> TPartitions;
void InitializeResourceUnitPartitions();
void PartitionResourceIndices(
EResourceUnitType eUnitType,
const TPipelineResourceUnitPartitionBound * akPartitionBounds,
uint32 uNumPartitions);
static bool CreateRenderingContexts(
TWindowContext & kWindowContext,
std::vector<TRenderingContext>&kRenderingContexts,
const SFeatureSpec&kFeatureSpec,
const SPixelFormatSpec&kPixelFormat,
const TNativeDisplay &kNativeDisplay);
static bool MakeCurrent(const TWindowContext&kWindowContext, TRenderingContext kRenderingContext);
void OnApplicationWindowCreated() override;
void OnApplicationWindowRedrawNeeded() override;
static uint32 ms_uNumContextsPerDevice;
static CDevice* ms_pCurrentDevice;
SOutputPtr m_spFullScreenOutput;
SAdapterPtr m_spAdapter;
SFeatureSpec m_kFeatureSpec;
SPixelFormatSpec m_kPixelFormatSpec;
TWindowContext m_kDefaultWindowContext;
TNativeDisplay m_kDefaultNativeDisplay;
TContexts m_kContexts;
SList m_kFreeContexts[CContext::NumContextTypes];
void* m_pCurrentContextTLS;
SBitMask<MAX_NUM_CONTEXT_PER_DEVICE, SSpinlockBitMaskWord> m_kContextFenceIssued;
SResourceNamePool m_kTextureNamePool;
SResourceNamePool m_kBufferNamePool;
SResourceNamePool m_kFrameBufferNamePool;
TPartitions m_kResourceUnitPartitions[eRUT_NUM];
typedef AZStd::map<HWND, std::pair<uint32, uint32>> WindowSizeList;
static WindowSizeList m_windowSizes;
uint64 m_texturesStreamingFunctorId;
};
bool FeatureLevelToFeatureSpec(SFeatureSpec& kContextSpec, D3D_FEATURE_LEVEL eFeatureLevel, NCryOpenGL::SAdapter* pGLAdapter);
void GetStandardPixelFormatSpec(SPixelFormatSpec& kPixelFormatSpec);
bool SwapChainDescToFrameBufferSpec(SFrameBufferSpec& kFrameBufferSpec, const DXGI_SWAP_CHAIN_DESC& kSwapChainDesc);
bool GetNativeDisplay(TNativeDisplay& kNativeDisplay, HWND kWindowHandle);
bool CreateWindowContext(TWindowContext& kWindowContext, const SFeatureSpec& kFeatureSpec, const SPixelFormatSpec& kPixelFormatSpec, const TNativeDisplay& kNativeDisplay);
void ReleaseWindowContext(TWindowContext& kWindowContext);
uint32 DetectGIFormatSupport(EGIFormat eGIFormat);
bool DetectFeaturesAndCapabilities(TFeatures& kFeatures, SCapabilities& kCapabilities, const SVersion& version);
bool DetectAdapters(std::vector<SAdapterPtr>& kAdapters);
bool CheckAdapterCapabilities(const SAdapter& kAdapter, AZStd::string* pErrorMsg = nullptr);
bool DetectOutputs(const SAdapter& kAdapter, std::vector<SOutputPtr>& kOutputs);
bool CheckFormatMultisampleSupport(SAdapter* pAdapter, EGIFormat eFormat, uint32 uNumSamples);
void GetDXGIModeDesc(DXGI_MODE_DESC* pDXGIModeDesc, const SDisplayMode& kDisplayMode);
bool GetDisplayMode(SDisplayMode* pDisplayMode, const DXGI_MODE_DESC& kDXGIModeDesc);
}
#endif //__GLDEVICE__
@@ -0,0 +1,148 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#undef glUseProgramStages
EXTENSION_FUNC(glUseProgramStages, glUseProgramStagesEXT, void, GLuint, GLbitfield, GLuint)
#define glUseProgramStages DXGL_EXT_FUNCPTR(glUseProgramStages)
#undef glActiveShaderProgram
EXTENSION_FUNC(glActiveShaderProgram, glActiveShaderProgramEXT, void, GLuint, GLuint)
#define glActiveShaderProgram DXGL_EXT_FUNCPTR(glActiveShaderProgram)
#undef glCreateShaderProgramv
EXTENSION_FUNC(glCreateShaderProgramv, glCreateShaderProgramvEXT, GLuint, GLenum, GLsizei, const GLchar**)
#define glCreateShaderProgramv DXGL_EXT_FUNCPTR(glCreateShaderProgramv)
#undef glBindProgramPipeline
EXTENSION_FUNC(glBindProgramPipeline, glBindProgramPipelineEXT, void, GLuint)
#define glBindProgramPipeline DXGL_EXT_FUNCPTR(glBindProgramPipeline)
#undef glDeleteProgramPipelines
EXTENSION_FUNC(glDeleteProgramPipelines, glDeleteProgramPipelinesEXT, void, GLsizei, const GLuint*)
#define glDeleteProgramPipelines DXGL_EXT_FUNCPTR(glDeleteProgramPipelines)
#undef glGenProgramPipelines
EXTENSION_FUNC(glGenProgramPipelines, glGenProgramPipelinesEXT, void, GLsizei, GLuint*)
#define glGenProgramPipelines DXGL_EXT_FUNCPTR(glGenProgramPipelines)
#undef glIsProgramPipeline
EXTENSION_FUNC(glIsProgramPipeline, glIsProgramPipelineEXT, GLboolean, GLuint)
#define glIsProgramPipeline DXGL_EXT_FUNCPTR(glIsProgramPipeline)
#undef glProgramParameteri
EXTENSION_FUNC(glProgramParameteri, glProgramParameteriEXT, void, GLuint, GLenum, GLint)
#define glProgramParameteri DXGL_EXT_FUNCPTR(glProgramParameteri)
#undef glGetProgramPipelineiv
EXTENSION_FUNC(glGetProgramPipelineiv, glGetProgramPipelineivEXT, void, GLuint, GLenum, GLint*)
#define glGetProgramPipelineiv DXGL_EXT_FUNCPTR(glGetProgramPipelineiv)
#undef glValidateProgramPipeline
EXTENSION_FUNC(glValidateProgramPipeline, glValidateProgramPipelineEXT, void, GLuint)
#define glValidateProgramPipeline DXGL_EXT_FUNCPTR(glValidateProgramPipeline)
#undef glGetProgramPipelineInfoLog
EXTENSION_FUNC(glGetProgramPipelineInfoLog, glGetProgramPipelineInfoLogEXT, void, GLuint, GLsizei, GLsizei*, GLchar*)
#define glGetProgramPipelineInfoLog DXGL_EXT_FUNCPTR(glGetProgramPipelineInfoLog)
#undef glProgramUniform1i
EXTENSION_FUNC(glProgramUniform1i, glProgramUniform1iEXT, void, GLuint, GLint, GLint)
#define glProgramUniform1i DXGL_EXT_FUNCPTR(glProgramUniform1i)
#undef glProgramUniform2i
EXTENSION_FUNC(glProgramUniform2i, glProgramUniform2iEXT, void, GLuint, GLint, GLint, GLint)
#define glProgramUniform2i DXGL_EXT_FUNCPTR(glProgramUniform2i)
#undef glProgramUniform3i
EXTENSION_FUNC(glProgramUniform3i, glProgramUniform3iEXT, void, GLuint, GLint, GLint, GLint, GLint)
#define glProgramUniform3i DXGL_EXT_FUNCPTR(glProgramUniform3i)
#undef glProgramUniform4i
EXTENSION_FUNC(glProgramUniform4i, glProgramUniform4iEXT, void, GLuint, GLint, GLint, GLint, GLint, GLint)
#define glProgramUniform4i DXGL_EXT_FUNCPTR(glProgramUniform4i)
#undef glProgramUniform1f
EXTENSION_FUNC(glProgramUniform1f, glProgramUniform1fEXT, void, GLuint, GLint, GLfloat)
#define glProgramUniform1f DXGL_EXT_FUNCPTR(glProgramUniform1f)
#undef glProgramUniform2f
EXTENSION_FUNC(glProgramUniform2f, glProgramUniform2fEXT, void, GLuint, GLint, GLfloat, GLfloat)
#define glProgramUniform2f DXGL_EXT_FUNCPTR(glProgramUniform2f)
#undef glProgramUniform3f
EXTENSION_FUNC(glProgramUniform3f, glProgramUniform3fEXT, void, GLuint, GLint, GLfloat, GLfloat, GLfloat)
#define glProgramUniform3f DXGL_EXT_FUNCPTR(glProgramUniform3f)
#undef glProgramUniform4f
EXTENSION_FUNC(glProgramUniform4f, glProgramUniform4fEXT, void, GLuint, GLint, GLfloat, GLfloat, GLfloat, GLfloat)
#define glProgramUniform4f DXGL_EXT_FUNCPTR(glProgramUniform4f)
#undef glProgramUniform1ui
EXTENSION_FUNC(glProgramUniform1ui, glProgramUniform1uiEXT, void, GLuint, GLint, GLuint)
#define glProgramUniform1ui DXGL_EXT_FUNCPTR(glProgramUniform1ui)
#undef glProgramUniform2ui
EXTENSION_FUNC(glProgramUniform2ui, glProgramUniform2uiEXT, void, GLuint, GLint, GLuint, GLuint)
#define glProgramUniform2ui DXGL_EXT_FUNCPTR(glProgramUniform2ui)
#undef glProgramUniform3ui
EXTENSION_FUNC(glProgramUniform3ui, glProgramUniform3uiEXT, void, GLuint, GLint, GLuint, GLuint, GLuint)
#define glProgramUniform3ui DXGL_EXT_FUNCPTR(glProgramUniform3ui)
#undef glProgramUniform4ui
EXTENSION_FUNC(glProgramUniform4ui, glProgramUniform4uiEXT, void, GLuint, GLint, GLuint, GLuint, GLuint, GLuint)
#define glProgramUniform4ui DXGL_EXT_FUNCPTR(glProgramUniform4ui)
#undef glProgramUniform1iv
EXTENSION_FUNC(glProgramUniform1iv, glProgramUniform1ivEXT, void, GLuint, GLint, GLsizei, const GLint*)
#define glProgramUniform1iv DXGL_EXT_FUNCPTR(glProgramUniform1iv)
#undef glProgramUniform2iv
EXTENSION_FUNC(glProgramUniform2iv, glProgramUniform2ivEXT, void, GLuint, GLint, GLsizei, const GLint*)
#define glProgramUniform2iv DXGL_EXT_FUNCPTR(glProgramUniform2iv)
#undef glProgramUniform3iv
EXTENSION_FUNC(glProgramUniform3iv, glProgramUniform3ivEXT, void, GLuint, GLint, GLsizei, const GLint*)
#define glProgramUniform3iv DXGL_EXT_FUNCPTR(glProgramUniform3iv)
#undef glProgramUniform4iv
EXTENSION_FUNC(glProgramUniform4iv, glProgramUniform4ivEXT, void, GLuint, GLint, GLsizei, const GLint*)
#define glProgramUniform4iv DXGL_EXT_FUNCPTR(glProgramUniform4iv)
#undef glProgramUniform1fv
EXTENSION_FUNC(glProgramUniform1fv, glProgramUniform1fvEXT, void, GLuint, GLint, GLsizei, const GLfloat*)
#define glProgramUniform1fv DXGL_EXT_FUNCPTR(glProgramUniform1fv)
#undef glProgramUniform2fv
EXTENSION_FUNC(glProgramUniform2fv, glProgramUniform2fvEXT, void, GLuint, GLint, GLsizei, const GLfloat*)
#define glProgramUniform2fv DXGL_EXT_FUNCPTR(glProgramUniform2fv)
#undef glProgramUniform3fv
EXTENSION_FUNC(glProgramUniform3fv, glProgramUniform3fvEXT, void, GLuint, GLint, GLsizei, const GLfloat*)
#define glProgramUniform3fv DXGL_EXT_FUNCPTR(glProgramUniform3fv)
#undef glProgramUniform4fv
EXTENSION_FUNC(glProgramUniform4fv, glProgramUniform4fvEXT, void, GLuint, GLint, GLsizei, const GLfloat*)
#define glProgramUniform4fv DXGL_EXT_FUNCPTR(glProgramUniform4fv)
#undef glProgramUniform1uiv
EXTENSION_FUNC(glProgramUniform1uiv, glProgramUniform1uivEXT, void, GLuint, GLint, GLsizei, const GLuint*)
#define glProgramUniform1uiv DXGL_EXT_FUNCPTR(glProgramUniform1uiv)
#undef glProgramUniform2uiv
EXTENSION_FUNC(glProgramUniform2uiv, glProgramUniform2uivEXT, void, GLuint, GLint, GLsizei, const GLuint*)
#define glProgramUniform2uiv DXGL_EXT_FUNCPTR(glProgramUniform2uiv)
#undef glProgramUniform3uiv
EXTENSION_FUNC(glProgramUniform3uiv, glProgramUniform3uivEXT, void, GLuint, GLint, GLsizei, const GLuint*)
#define glProgramUniform3uiv DXGL_EXT_FUNCPTR(glProgramUniform3uiv)
#undef glProgramUniform4uiv
EXTENSION_FUNC(glProgramUniform4uiv, glProgramUniform4uivEXT, void, GLuint, GLint, GLsizei, const GLuint*)
#define glProgramUniform4uiv DXGL_EXT_FUNCPTR(glProgramUniform4uiv)
#undef glProgramUniformMatrix2fv
EXTENSION_FUNC(glProgramUniformMatrix2fv, glProgramUniformMatrix2fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix2fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix2fv)
#undef glProgramUniformMatrix3fv
EXTENSION_FUNC(glProgramUniformMatrix3fv, glProgramUniformMatrix3fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix3fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix3fv)
#undef glProgramUniformMatrix4fv
EXTENSION_FUNC(glProgramUniformMatrix4fv, glProgramUniformMatrix4fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix4fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix4fv)
#undef glProgramUniformMatrix2x3fv
EXTENSION_FUNC(glProgramUniformMatrix2x3fv, glProgramUniformMatrix2x3fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix2x3fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix2x3fv)
#undef glProgramUniformMatrix3x2fv
EXTENSION_FUNC(glProgramUniformMatrix3x2fv, glProgramUniformMatrix3x2fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix3x2fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix3x2fv)
#undef glProgramUniformMatrix2x4fv
EXTENSION_FUNC(glProgramUniformMatrix2x4fv, glProgramUniformMatrix2x4fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix2x4fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix2x4fv)
#undef glProgramUniformMatrix4x2fv
EXTENSION_FUNC(glProgramUniformMatrix4x2fv, glProgramUniformMatrix4x2fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix4x2fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix4x2fv)
#undef glProgramUniformMatrix3x4fv
EXTENSION_FUNC(glProgramUniformMatrix3x4fv, glProgramUniformMatrix3x4fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix3x4fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix3x4fv)
#undef glProgramUniformMatrix4x3fv
EXTENSION_FUNC(glProgramUniformMatrix4x3fv, glProgramUniformMatrix4x3fvEXT, void, GLuint, GLint, GLsizei, GLboolean, const GLfloat*)
#define glProgramUniformMatrix4x3fv DXGL_EXT_FUNCPTR(glProgramUniformMatrix4x3fv)
#undef glCopyImageSubData
EXTENSION_FUNC(glCopyImageSubData, glCopyImageSubDataEXT, void, GLuint, GLenum, GLint, GLint, GLint, GLint, GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei)
#define glCopyImageSubData DXGL_EXT_FUNCPTR(glCopyImageSubData)
@@ -0,0 +1,92 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
//
// GLExtensions.hpp
// CryEngine
//
// Created by Duhon, Eric on 10/29/14.
//
//
#ifndef CryEngine_GLExtensions_hpp
#define CryEngine_GLExtensions_hpp
#pragma once
#if DXGL_INPUT_GLSL && DXGL_GLSL_FROM_HLSLCROSSCOMPILER
#include "hlslcc.hpp"
#include "hlslcc_bin.hpp"
#endif //DXGL_INPUT_GLSL && DXGL_GLSL_FROM_HLSLCROSSCOMPILER
#if DXGLES && DXGLES_VERSION == DXGLES_VERSION_30 && defined(GL_EXT_separate_shader_objects) && defined(IOS)
// On OpenGL ES separate shader programs are available as an extesion, so we
// just define the normal api here to avoid ifdefing the entire code
#define GL_VERTEX_SHADER_BIT GL_VERTEX_SHADER_BIT_EXT
#define GL_FRAGMENT_SHADER_BIT GL_FRAGMENT_SHADER_BIT_EXT
#define GL_ALL_SHADER_BITS GL_ALL_SHADER_BITS_EXT
#define GL_PROGRAM_SEPARABLE GL_PROGRAM_SEPARABLE_EXT
#define GL_ACTIVE_PROGRAM GL_ACTIVE_PROGRAM_EXT
#define GL_PROGRAM_PIPELINE_BINDING GL_PROGRAM_PIPELINE_BINDING_EXT
#define glUseProgramStages glUseProgramStagesEXT
#define glActiveShaderProgram glActiveShaderProgramEXT
#define glCreateShaderProgramv glCreateShaderProgramvEXT
#define glBindProgramPipeline glBindProgramPipelineEXT
#define glDeleteProgramPipelines glDeleteProgramPipelinesEXT
#define glGenProgramPipelines glGenProgramPipelinesEXT
#define glIsProgramPipeline glIsProgramPipelineEXT
#define glProgramParameteri glProgramParameteriEXT
#define glGetProgramPipelineiv glGetProgramPipelineivEXT
#define glValidateProgramPipeline glValidateProgramPipelineEXT
#define glGetProgramPipelineInfoLog glGetProgramPipelineInfoLogEXT
#define glProgramUniform1i glProgramUniform1iEXT
#define glProgramUniform2i glProgramUniform2iEXT
#define glProgramUniform2i glProgramUniform2iEXT
#define glProgramUniform2i glProgramUniform2iEXT
#define glProgramUniform1f glProgramUniform1fEXT
#define glProgramUniform2f glProgramUniform2fEXT
#define glProgramUniform3f glProgramUniform3fEXT
#define glProgramUniform4f glProgramUniform4fEXT
#define glProgramUniform1ui glProgramUniform1uiEXT
#define glProgramUniform2ui glProgramUniform2uiEXT
#define glProgramUniform3ui glProgramUniform3uiEXT
#define glProgramUniform4ui glProgramUniform4uiEXT
#define glProgramUniform1iv glProgramUniform1ivEXT
#define glProgramUniform2iv glProgramUniform2ivEXT
#define glProgramUniform3iv glProgramUniform3ivEXT
#define glProgramUniform4iv glProgramUniform4ivEXT
#define glProgramUniform1fv glProgramUniform1fvEXT
#define glProgramUniform2fv glProgramUniform2fvEXT
#define glProgramUniform3fv glProgramUniform3fvEXT
#define glProgramUniform4fv glProgramUniform4fvEXT
#define glProgramUniform1uiv glProgramUniform1uivEXT
#define glProgramUniform2uiv glProgramUniform2uivEXT
#define glProgramUniform3uiv glProgramUniform3uivEXT
#define glProgramUniform4uiv glProgramUniform4uivEXT
#define glProgramUniformMatrix2fv glProgramUniformMatrix2fvEXT
#define glProgramUniformMatrix3fv glProgramUniformMatrix3fvEXT
#define glProgramUniformMatrix4fv glProgramUniformMatrix4fvEXT
#define glProgramUniformMatrix2x3fv glProgramUniformMatrix2x3fvEXT
#define glProgramUniformMatrix3x2fv glProgramUniformMatrix3x2fvEXT
#define glProgramUniformMatrix2x4fv glProgramUniformMatrix2x4fvEXT
#define glProgramUniformMatrix4x2fv glProgramUniformMatrix4x2fvEXT
#define glProgramUniformMatrix3x4fv glProgramUniformMatrix3x4fvEXT
#define glProgramUniformMatrix4x3fv glProgramUniformMatrix4x3fvEXT
#endif
#endif
@@ -0,0 +1,791 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : OpenGL feature detection and emulation
#ifndef __GLFEATURES__
#define __GLFEATURES__
#if DXGL_TRACE_CALLS || DXGL_CHECK_ERRORS
# include "GLInstrument.hpp"
#else
# define DXGL_UNWRAPPED_FUNCTION(_Name) _Name
#endif
#if defined(AZ_RESTRICTED_PLATFORM)
#undef AZ_RESTRICTED_SECTION
#define GLFEATURES_HPP_SECTION_1 1
#endif
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION GLFEATURES_HPP_SECTION_1
#include AZ_RESTRICTED_FILE(GLFeatures_hpp)
#endif
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
#elif defined(DXGL_USE_LOADER_GLAD)
# define DXGL_EXTENSION_LOADER 1
# if DXGLES && !defined(DXGL_ES_SUBSET)
# include <glad/gles2.h>
# else
# include <glad/gl.h>
# endif
# define DXGL_GL_EXTENSION_SUPPORTED(_Extension) (GLAD_GL_ ## _Extension == 1)
# define DXGL_GL_LOADER_FUNCTION_PTR(_Func) (glad_ ## _Func)
# define DXGL_GL_LOADER_FUNCTION_PTR_PREFIX(_Func) DXGL_GL_LOADER_FUNCTION_PTR(gl ## _Func)
# if defined(DXGL_USE_WGL)
# include <glad/wgl.h>
# define DXGL_WGL_EXTENSION_SUPPORTED(_Extension) (GLAD_WGL_ ## _Extension == 1)
# elif defined(DXGL_USE_EGL)
# include <glad/egl.h>
# elif defined(DXGL_USE_GLX)
# include <glad/glx.h>
# endif
#elif defined(DXGL_USE_LOADER_GLEW)
# define DXGL_EXTENSION_LOADER 1
# define DXGL_GL_EXTENSION_SUPPORTED(_Extension) (glewIsExtensionSupported("GL_" # _Extension) == GL_TRUE)
# define DXGL_GL_LOADER_FUNCTION_PTR(_Func) (_Func)
# define DXGL_GL_LOADER_FUNCTION_PTR_PREFIX(_Func) (__glew ## _Func)
# include <GL/glew.h>
# if defined(DXGL_USE_WGL)
# define DXGL_WGL_EXTENSION_SUPPORTED(_Extension) (wglewIsSupported("WGL_" # _Extension) == GL_TRUE)
# include <GL/wglew.h>
# elif defined(DXGL_USE_EGL)
# include <EGL/egl.h>
# elif defined(DXGL_USE_GLX)
# include <GL/glxew.h>
# endif
#else
# define DXGL_EXTENSION_LOADER 0
# define DXGL_GL_EXTENSION_SUPPORTED(_Extension) (false)
# define DXGL_GL_LOADER_FUNCTION_PTR(_Func) (_Func)
# if defined(MAC)
# define GL3_PROTOTYPES
# include <OpenGL/gl3.h>
# include <OpenGL/gl3ext.h>
# elif defined(IOS)
# include <OpenGLES/ES3/gl.h>
# include <OpenGLES/ES3/glext.h>
# endif
#endif
#if defined(AZ_PLATFORM_LINUX)
// The X11 library, which is included by GLAD, defines some macros that we use as function names in the Linux implementation.
static const int X11_Success = Success;
static const int X11_None = None;
#undef Success
#undef None
#endif
#include <Common/RenderCapabilities.h>
#define DXGL_SUPPORT_INDEXED_BOOL_STATE (DXGL_REQUIRED_VERSION >= DXGL_VERSION_32 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_INDEXED_ENABLE_STATE !DXGLES
#define DXGL_SUPPORT_INDEXED_FLOAT_STATE !DXGLES
#define DXGL_SUPPORT_VIEWPORT_ARRAY !DXGLES
#define DXGL_SUPPORT_SCISSOR_RECT_ARRAY !DXGLES
#define DXGL_SUPPORT_DRAW_WITH_BASE_VERTEX (DXGL_REQUIRED_VERSION >= DXGL_VERSION_42 && !DXGLES)
#define DXGL_SUPPORT_GETTEXIMAGE !DXGLES
#define DXGL_SUPPORT_DEPTH_CLAMP !DXGLES
#define DXGL_SUPPORT_TIMER_QUERIES !DXGLES
#define DXGL_SUPPORT_S3TC_TEXTURES (!DXGLES || DXGL_SUPPORT_TEGRA)
#define DXGL_SUPPORT_BGRA_TEXTURES !DXGLES
#define DXGL_SUPPORT_STENCIL_ONLY_FORMAT (DXGL_REQUIRED_VERSION >= DXGL_VERSION_32 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_MULTISAMPLED_TEXTURES (DXGL_REQUIRED_VERSION >= DXGL_VERSION_41 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_TESSELLATION (DXGL_REQUIRED_VERSION >= DXGL_VERSION_41)
#define DXGL_SUPPORT_GEOMETRY_SHADERS (DXGL_REQUIRED_VERSION >= DXGL_VERSION_41)
#define DXGL_SUPPORT_TEXTURE_BUFFERS (DXGL_REQUIRED_VERSION >= DXGL_VERSION_41)
#define DXGL_SUPPORT_CUBEMAP_ARRAYS (DXGL_REQUIRED_VERSION >= DXGL_VERSION_41)
#define DXGL_SUPPORT_DRAW_INDIRECT (DXGL_REQUIRED_VERSION >= DXGL_VERSION_41 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_BPTC (DXGL_REQUIRED_VERSION >= DXGL_VERSION_42)
#define DXGL_SUPPORT_STENCIL_TEXTURES ((DXGL_REQUIRED_VERSION >= DXGL_VERSION_42 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30) && !DXGL_SUPPORT_NSIGHT_SINCE(4_1))
#define DXGL_SUPPORT_ATOMIC_COUNTERS (DXGL_REQUIRED_VERSION >= DXGL_VERSION_42 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#ifdef MAC
#define DXGL_SUPPORT_COMPUTE 0
#define DXGL_SUPPORT_DEBUG_OUTPUT 0
#else
#define DXGL_SUPPORT_COMPUTE 1
#define DXGL_SUPPORT_DEBUG_OUTPUT !DXGL_SUPPORT_NSIGHT_SINCE(4_1)
#endif
#define DXGL_SUPPORT_DISPATCH_INDIRECT (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_SHADER_STORAGE_BLOCKS (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_SHADER_IMAGES (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_VERTEX_ATTRIB_BINDING (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_TEXTURE_VIEWS (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#define DXGL_SUPPORT_QUERY_INTERNAL_FORMAT_SUPPORT (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 && !DXGL_SUPPORT_NSIGHT_SINCE(3_0) && !DXGL_SUPPORT_VOGL)
#define DXGL_SUPPORT_BUFFER_STORAGE (DXGL_REQUIRED_VERSION >= DXGL_VERSION_44 && !DXGL_SUPPORT_NSIGHT_SINCE(4_5))
#define DXGL_SUPPORT_ETC2_EAC_COMPRESSION (DXGL_REQUIRED_VERSION >= DXGL_VERSION_43 || DXGLES_REQUIRED_VERSION >= DXGLES_VERSION_30)
#if DXGL_SUPPORT_GEOMETRY_SHADERS
# define DXGL_ENABLE_GEOMETRY_SHADERS 1
#else
# define DXGL_ENABLE_GEOMETRY_SHADERS 0
#endif
#if DXGL_SUPPORT_TESSELLATION
# define DXGL_ENABLE_TESSELLATION_SHADERS 1
#else
# define DXGL_ENABLE_TESSELLATION_SHADERS 0
#endif
#if DXGL_SUPPORT_COMPUTE
# define DXGL_ENABLE_COMPUTE_SHADERS 1
#else
# define DXGL_ENABLE_COMPUTE_SHADERS 0
#endif
#if defined(ANDROID)
#define USE_FAST_NAMED_APPROXIMATION
#endif
enum
{
#if DXGL_SUPPORT_VIEWPORT_ARRAY
DXGL_NUM_SUPPORTED_VIEWPORTS = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
#else
DXGL_NUM_SUPPORTED_VIEWPORTS = 1,
#endif
#if DXGL_SUPPORT_SCISSOR_RECT_ARRAY
DXGL_NUM_SUPPORTED_SCISSOR_RECTS = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
#else
DXGL_NUM_SUPPORTED_SCISSOR_RECTS = 1,
#endif
DXGL_NUM_SUPPORTED_BLEND_STATES = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT,
};
////////////////////////////////////////////////////////////////////////////
// Conform extension definitions
////////////////////////////////////////////////////////////////////////////
#if DXGL_SUPPORT_S3TC_TEXTURES
#if !defined(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT) || \
!defined(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT) || \
!defined(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT)
#undef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
#undef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
#undef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV
#endif
#endif
#if DXGL_SUPPORT_BGRA_TEXTURES
#if !defined(GL_BGRA)
#if defined(GL_BGRA_EXT)
#define GL_BGRA GL_BGRA_EXT
#else
#define GL_BGRA GL_BGRA_IMG
#endif
#endif
#endif
#if DXGL_REQUIRED_VERSION > 0 || defined(DXGL_ES_SUBSET)
#define GL_CLAMP_TO_BORDER_EXT GL_CLAMP_TO_BORDER
#define GL_TEXTURE_BORDER_COLOR_EXT GL_TEXTURE_BORDER_COLOR
#define glTextureViewEXT glTextureView
#endif
#if !defined(GL_COPY_READ_BUFFER_BINDING) || \
!defined(GL_COPY_WRITE_BUFFER_BINDING)
#undef GL_COPY_READ_BUFFER_BINDING
#undef GL_COPY_WRITE_BUFFER_BINDING
#define GL_COPY_READ_BUFFER_BINDING GL_COPY_READ_BUFFER
#define GL_COPY_WRITE_BUFFER_BINDING GL_COPY_WRITE_BUFFER
#endif
#if DXGLES
#undef GL_TEXTURE_1D
#undef GL_TEXTURE_1D_ARRAY
// Emulate 1D textures as 2D textures on OpenGL ES
#define GL_TEXTURE_1D GL_TEXTURE_2D
#define GL_TEXTURE_1D_ARRAY GL_TEXTURE_2D_ARRAY
#endif //DXGLES
#if DXGL_SUPPORT_NSIGHT_SINCE(3_0) || DXGL_SUPPORT_VOGL || defined(MAC)
#undef glClearBufferData
#undef glClearBufferSubData
#undef glClearNamedBufferDataEXT
#undef glClearNamedBufferSubDataEXT
#undef glDispatchCompute
#undef glDispatchComputeIndirect
#undef glFramebufferParameteri
#undef glGetFramebufferParameteriv
#undef glGetNamedFramebufferParameterivEXT
#undef glNamedFramebufferParameteriEXT
#undef glInvalidateBufferData
#undef glInvalidateBufferSubData
#undef glInvalidateFramebuffer
#undef glInvalidateSubFramebuffer
#undef glInvalidateTexImage
#undef glInvalidateTexSubImage
#undef glMultiDrawArraysIndirect
#undef glMultiDrawElementsIndirect
#undef glTexStorage2DMultisample
#undef glTexStorage3DMultisample
#undef glBindVertexBuffer
#undef glVertexAttribBinding
#undef glVertexAttribFormat
#undef glVertexAttribIFormat
#undef glVertexAttribLFormat
#undef glVertexBindingDivisor
#undef glTextureImage2DEXT
#undef glCompressedTextureImage2DEXT
#undef glCompressedTextureSubImage2DEXT
#undef glNamedFramebufferTextureEXT
#undef glNamedFramebufferTextureLayerEXT
#undef glCheckNamedFramebufferStatusEXT
#undef glGetNamedFramebufferAttachmentParameterivEXT
#undef glGetTextureLevelParameterivEXT
#endif //DXGL_SUPPORT_NSIGHT_SINCE(3_0) || DXGL_SUPPORT_VOGL || defined(MAC)
#if DXGL_SUPPORT_NSIGHT_SINCE(3_0) || defined(MAC)
#undef glGetProgramInterfaceiv
#undef glGetProgramResourceIndex
#undef glGetProgramResourceLocation
#undef glGetProgramResourceLocationIndex
#undef glGetProgramResourceName
#undef glGetProgramResourceiv
#undef glShaderStorageBlockBinding
#endif //DXGL_SUPPORT_NSIGHT_SINCE(3_0) || defined(MAC)
#if DXGL_SUPPORT_NSIGHT_SINCE(4_1) || defined(MAC)
#undef glDebugMessageCallback
#undef glDebugMessageInsert
#undef glGetDebugMessageLog
#undef glGetObjectLabel
#undef glGetObjectPtrLabel
#undef glTextureSubImage2DEXT
#endif // DXGL_SUPPORT_NSIGHT_SINCE(4_1)
#if DXGL_SUPPORT_NSIGHT_SINCE(4_1) || DXGL_SUPPORT_VOGL || defined(MAC)
#undef glDebugMessageControl
#undef glPushDebugGroup
#undef glNamedBufferDataEXT
#undef glNamedBufferSubDataEXT
#undef glMapNamedBufferEXT
#undef glMapNamedBufferRangeEXT
#undef glUnmapNamedBufferEXT
#undef glTexBufferRange
#undef glTextureBufferRangeEXT
#endif // DXGL_SUPPORT_NSIGHT_SINCE(4_1) || DXGL_SUPPORT_VOGL || defined(MAC)
#if DXGL_SUPPORT_NSIGHT_SINCE(4_5)
#undef glNamedBufferStorageEXT
#endif
#if DXGL_SUPPORT_VOGL
#undef glReleaseShaderCompiler
#endif //DXGL_SUPPORT_VOGL
////////////////////////////////////////////////////////////////////////////
// Direct state access framebuffer attachment emulation when not available
////////////////////////////////////////////////////////////////////////////
#if !defined(glNamedFramebufferTextureEXT) || \
!defined(glNamedFramebufferTextureLayerEXT) || \
!defined(glCheckNamedFramebufferStatusEXT) || \
!defined(glFramebufferDrawBuffersEXT) || \
!defined(glGetNamedFramebufferAttachmentParameterivEXT)
#undef glNamedFramebufferTextureEXT
#undef glNamedFramebufferTextureLayerEXT
#undef glCheckNamedFramebufferStatusEXT
#undef glFramebufferDrawBuffersEXT
#undef glGetNamedFramebufferAttachmentParameterivEXT
struct SAutoBindFrameBuffer
{
SAutoBindFrameBuffer(GLenum eTarget, GLuint uFrameBuffer)
: m_eTarget(eTarget)
{
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &m_iPrevFrameBuffer);
glBindFramebuffer(m_eTarget, uFrameBuffer);
}
~SAutoBindFrameBuffer()
{
glBindFramebuffer(m_eTarget, m_iPrevFrameBuffer);
}
GLint m_eTarget;
GLint m_iPrevFrameBuffer;
};
inline void glNamedFramebufferTextureEXT(GLuint uFramebuffer, GLenum eAttachment, GLuint uTexture, GLint iLevel)
{
SAutoBindFrameBuffer kAutoBind(GL_DRAW_FRAMEBUFFER, uFramebuffer);
#if DXGL_REQUIRED_VERSION >= DXGL_VERSION_41
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, eAttachment, uTexture, iLevel);
#else
// Note ES can only bind a cubemap face or a 2D texture
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, eAttachment, GL_TEXTURE_2D, uTexture, iLevel);
#endif
}
inline void glNamedFramebufferTextureLayerEXT(GLuint uFramebuffer, GLenum eAttachment, GLuint uTexture, GLint iLevel, GLint iLayer)
{
SAutoBindFrameBuffer kAutoBind(GL_DRAW_FRAMEBUFFER, uFramebuffer);
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, eAttachment, uTexture, iLevel, iLayer);
}
inline GLenum glCheckNamedFramebufferStatusEXT(GLuint uFramebuffer, GLenum eTarget)
{
SAutoBindFrameBuffer kAutoBind(eTarget, uFramebuffer);
return glCheckFramebufferStatus(eTarget);
}
inline void glFramebufferDrawBuffersEXT(GLuint uFramebuffer, GLsizei uNumber, const GLenum* aeBuffers)
{
SAutoBindFrameBuffer kAutoBind(GL_DRAW_FRAMEBUFFER, uFramebuffer);
glDrawBuffers(uNumber, aeBuffers);
}
inline void glGetNamedFramebufferAttachmentParameterivEXT(GLuint uFramebuffer, GLenum eAttachment, GLenum ePName, GLint* aiParams)
{
SAutoBindFrameBuffer kAutoBind(GL_DRAW_FRAMEBUFFER, uFramebuffer);
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, eAttachment, ePName, aiParams);
}
#endif
////////////////////////////////////////////////////////////////////////////
// Direct state access texture functions emulation when not available
////////////////////////////////////////////////////////////////////////////
#if !defined(glTextureStorage1DEXT) || \
!defined(glTextureStorage2DEXT) || \
!defined(glTextureStorage3DEXT) || \
!defined(glTextureImage1DEXT) || \
!defined(glTextureImage2DEXT) || \
!defined(glTextureImage3DEXT) || \
!defined(glCompressedTextureImage1DEXT) || \
!defined(glCompressedTextureImage2DEXT) || \
!defined(glCompressedTextureImage3DEXT) || \
!defined(glTextureSubImage1DEXT) || \
!defined(glTextureSubImage2DEXT) || \
!defined(glTextureSubImage3DEXT) || \
!defined(glCompressedTextureSubImage1DEXT) || \
!defined(glCompressedTextureSubImage2DEXT) || \
!defined(glCompressedTextureSubImage3DEXT) || \
!defined(glGetTextureImageEXT) || \
!defined(glGetCompressedTextureImageEXT) || \
!defined(glGenerateTextureMipmapEXT) || \
!defined(glTextureBufferEXT) || \
!defined(glTextureBufferRangeEXT) || \
!defined(glTextureParameterfEXT) || \
!defined(glTextureParameteriEXT) || \
!defined(glTextureParameterfvEXT) || \
!defined(glTextureParameterivEXT) || \
!defined(glGetTextureLevelParameterivEXT)
#undef glTextureStorage1DEXT
#undef glTextureStorage2DEXT
#undef glTextureStorage3DEXT
#undef glTextureImage1DEXT
#undef glTextureImage2DEXT
#undef glTextureImage3DEXT
#undef glCompressedTextureImage1DEXT
#undef glCompressedTextureImage2DEXT
#undef glCompressedTextureImage3DEXT
#undef glTextureSubImage1DEXT
#undef glTextureSubImage2DEXT
#undef glTextureSubImage3DEXT
#undef glCompressedTextureSubImage1DEXT
#undef glCompressedTextureSubImage2DEXT
#undef glCompressedTextureSubImage3DEXT
#undef glGetTextureImageEXT
#undef glGetCompressedTextureImageEXT
#undef glGenerateTextureMipmapEXT
#undef glTextureBufferEXT
#undef glTextureBufferRangeEXT
#undef glTextureParameterfEXT
#undef glTextureParameteriEXT
#undef glTextureParameterfvEXT
#undef glTextureParameterivEXT
#undef glGetTextureLevelParameterivEXT
struct SAutoTexBind
{
SAutoTexBind(GLenum eSubTarget, GLuint uTexture)
{
switch (eSubTarget)
{
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
m_eTarget = GL_TEXTURE_CUBE_MAP;
break;
default:
m_eTarget = eSubTarget;
break;
}
GLenum eBindingName;
switch (m_eTarget)
{
case GL_TEXTURE_CUBE_MAP:
eBindingName = GL_TEXTURE_BINDING_CUBE_MAP;
break;
case GL_TEXTURE_2D:
eBindingName = GL_TEXTURE_BINDING_2D;
break;
case GL_TEXTURE_2D_ARRAY:
eBindingName = GL_TEXTURE_BINDING_2D_ARRAY;
break;
case GL_TEXTURE_3D:
eBindingName = GL_TEXTURE_BINDING_3D;
break;
#if !DXGLES
case GL_TEXTURE_1D:
eBindingName = GL_TEXTURE_BINDING_1D;
break;
case GL_TEXTURE_1D_ARRAY:
eBindingName = GL_TEXTURE_BINDING_1D_ARRAY;
break;
case GL_TEXTURE_RECTANGLE:
eBindingName = GL_TEXTURE_BINDING_RECTANGLE;
break;
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
eBindingName = GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY;
break;
#endif //!DXGLES
#if DXGL_SUPPORT_CUBEMAP_ARRAYS
case GL_TEXTURE_CUBE_MAP_ARRAY:
eBindingName = GL_TEXTURE_BINDING_CUBE_MAP_ARRAY;
break;
#endif //DXGL_SUPPORT_CUBEMAP_ARRAYS
#if DXGL_SUPPORT_MULTISAMPLED_TEXTURES
case GL_TEXTURE_2D_MULTISAMPLE:
eBindingName = GL_TEXTURE_BINDING_2D_MULTISAMPLE;
break;
#endif //DXGL_SUPPORT_MULTISAMPLED_TEXTURES
#if DXGL_SUPPORT_TEXTURE_BUFFERS
case GL_TEXTURE_BUFFER:
eBindingName = GL_TEXTURE_BINDING_BUFFER;
break;
#endif //DXGL_SUPPORT_TEXTURE_BUFFERS
default:
assert(false);
eBindingName = 0;
break;
}
GLint iBinding;
glGetIntegerv(eBindingName, &iBinding);
m_uPreviousBinding = (GLuint)iBinding;
glBindTexture(m_eTarget, uTexture);
}
~SAutoTexBind()
{
glBindTexture(m_eTarget, m_uPreviousBinding);
}
GLuint m_uPreviousBinding;
GLenum m_eTarget;
};
inline void glTextureStorage1DEXT(GLuint uTexture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
{
SAutoTexBind kAutoBind(target, uTexture);
#if DXGLES
glTexStorage2D(target, levels, internalformat, width, 1);
#else
glTexStorage1D(target, levels, internalformat, width);
#endif
}
inline void glTextureStorage2DEXT (GLuint uTexture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
{
SAutoTexBind kAutoBind(target, uTexture);
glTexStorage2D(target, levels, internalformat, width, height);
}
inline void glTextureStorage3DEXT (GLuint uTexture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
{
SAutoTexBind kAutoBind(target, uTexture);
glTexStorage3D(target, levels, internalformat, width, height, depth);
}
inline void glTextureImage1DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eInternalFormat, GLsizei iSizeX, GLint iBorder, GLenum eBaseFormat, GLenum eDataType, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
#if DXGLES
glTexImage2D(eTarget, iLevel, eInternalFormat, iSizeX, 1, iBorder, eBaseFormat, eDataType, pData);
#else
glTexImage1D(eTarget, iLevel, eInternalFormat, iSizeX, iBorder, eBaseFormat, eDataType, pData);
#endif
}
inline void glTextureImage2DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eInternalFormat, GLsizei iSizeX, GLsizei iSizeY, GLint iBorder, GLenum eBaseFormat, GLenum eDataType, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexImage2D(eTarget, iLevel, eInternalFormat, iSizeX, iSizeY, iBorder, eBaseFormat, eDataType, pData);
}
inline void glTextureImage3DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eInternalFormat, GLsizei iSizeX, GLsizei iSizeY, GLsizei iSizeZ, GLint iBorder, GLenum eBaseFormat, GLenum eDataType, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexImage3D(eTarget, iLevel, eInternalFormat, iSizeX, iSizeY, iSizeZ, iBorder, eBaseFormat, eDataType, pData);
}
inline void glCompressedTextureImage1DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eInternalFormat, GLsizei iSizeX, GLint iBorder, GLsizei iImageSize, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
#if DXGLES
glCompressedTexImage2D(eTarget, iLevel, eInternalFormat, iSizeX, 1, iBorder, iImageSize, pData);
#else
glCompressedTexImage1D(eTarget, iLevel, eInternalFormat, iSizeX, iBorder, iImageSize, pData);
#endif
}
inline void glCompressedTextureImage2DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eInternalFormat, GLsizei iSizeX, GLsizei iSizeY, GLint iBorder, GLsizei iImageSize, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glCompressedTexImage2D(eTarget, iLevel, eInternalFormat, iSizeX, iSizeY, iBorder, iImageSize, pData);
}
inline void glCompressedTextureImage3DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eInternalFormat, GLsizei iSizeX, GLsizei iSizeY, GLsizei iSizeZ, GLint iBorder, GLsizei iImageSize, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glCompressedTexImage3D(eTarget, iLevel, eInternalFormat, iSizeX, iSizeY, iSizeZ, iBorder, iImageSize, pData);
}
inline void glTextureSubImage1DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLint iOffsetX, GLsizei iSizeX, GLenum eFormat, GLenum eDataType, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
#if DXGLES
glTexSubImage2D(eTarget, iLevel, iOffsetX, 0, iSizeX, 1, eFormat, eDataType, pData);
#else
glTexSubImage1D(eTarget, iLevel, iOffsetX, iSizeX, eFormat, eDataType, pData);
#endif
}
inline void glTextureSubImage2DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLint iOffsetX, GLint iOffsetY, GLsizei iSizeX, GLsizei iSizeY, GLenum eFormat, GLenum eDataType, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexSubImage2D(eTarget, iLevel, iOffsetX, iOffsetY, iSizeX, iSizeY, eFormat, eDataType, pData);
}
inline void glTextureSubImage3DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLint iOffsetX, GLint iOffsetY, GLint iOffsetZ, GLsizei iSizeX, GLsizei iSizeY, GLsizei iSizeZ, GLenum eFormat, GLenum eDataType, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexSubImage3D(eTarget, iLevel, iOffsetX, iOffsetY, iOffsetZ, iSizeX, iSizeY, iSizeZ, eFormat, eDataType, pData);
}
inline void glCompressedTextureSubImage1DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLint iOffsetX, GLsizei iSizeX, GLenum eFormat, GLsizei iImageSize, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
#if DXGLES
glCompressedTexSubImage2D(eTarget, iLevel, iOffsetX, 0, iSizeX, 1, eFormat, iImageSize, pData);
#else
glCompressedTexSubImage1D(eTarget, iLevel, iOffsetX, iSizeX, eFormat, iImageSize, pData);
#endif
}
inline void glCompressedTextureSubImage2DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLint iOffsetX, GLint iOffsetY, GLsizei iSizeX, GLsizei iSizeY, GLenum eFormat, GLsizei iImageSize, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glCompressedTexSubImage2D(eTarget, iLevel, iOffsetX, iOffsetY, iSizeX, iSizeY, eFormat, iImageSize, pData);
}
inline void glCompressedTextureSubImage3DEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLint iOffsetX, GLint iOffsetY, GLint iOffsetZ, GLsizei iSizeX, GLsizei iSizeY, GLsizei iSizeZ, GLenum eFormat, GLsizei iImageSize, const GLvoid* pData)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glCompressedTexSubImage3D(eTarget, iLevel, iOffsetX, iOffsetY, iOffsetZ, iSizeX, iSizeY, iSizeZ, eFormat, iImageSize, pData);
}
#if !DXGLES
inline void glGetTextureImageEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eFormat, GLenum eType, void* pPixels)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glGetTexImage(eTarget, iLevel, eFormat, eType, pPixels);
}
inline void glGetCompressedTextureImageEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, void* pImg)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glGetCompressedTexImage(eTarget, iLevel, pImg);
}
inline void glTextureBufferEXT(GLuint uTexture, GLenum eTarget, GLenum eInternalFormat, GLuint uBuffer)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexBuffer(eTarget, eInternalFormat, uBuffer);
}
#endif //!DXGLES
inline void glGenerateTextureMipmapEXT(GLuint uTexture, GLenum eTarget)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glGenerateMipmap(eTarget);
}
#if defined(glTexBufferRange)
inline void glTextureBufferRangeEXT(GLuint uTexture, GLenum eTarget, GLenum eInternalformat, GLuint uBuffer, GLintptr iOffset, GLsizeiptr iSize)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexBufferRange(eTarget, eInternalformat, uBuffer, iOffset, iSize);
}
#endif //defined(glTexBufferRange)
inline void glTextureParameterfEXT(GLuint uTexture, GLenum eTarget, GLenum eName, GLfloat fParam)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexParameterf(eTarget, eName, fParam);
}
inline void glTextureParameteriEXT(GLuint uTexture, GLenum eTarget, GLenum eName, GLint iParam)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexParameteri(eTarget, eName, iParam);
}
inline void glTextureParameterfvEXT(GLuint uTexture, GLenum eTarget, GLenum eName, const GLfloat* pfParam)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexParameterfv(eTarget, eName, pfParam);
}
inline void glTextureParameterivEXT(GLuint uTexture, GLenum eTarget, GLenum eName, const GLint* piParam)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
glTexParameteriv(eTarget, eName, piParam);
}
inline void glGetTextureLevelParameterivEXT(GLuint uTexture, GLenum eTarget, GLint iLevel, GLenum eName, GLint* piParam)
{
SAutoTexBind kAutoBind(eTarget, uTexture);
#if DXGLES
uint32 glVersion = RenderCapabilities::GetDeviceGLVersion();
if (glVersion < DXGLES_VERSION_31)
{
DXGL_NOT_IMPLEMENTED;
}
else
#endif
{
glGetTexLevelParameteriv(eTarget, iLevel, eName, piParam);
}
}
#endif
////////////////////////////////////////////////////////////////////////////
// Direct state access buffer functions emulation when not available
////////////////////////////////////////////////////////////////////////////
template <GLenum eTarget = GL_COPY_WRITE_BUFFER, GLenum eBinding = GL_COPY_WRITE_BUFFER_BINDING>
struct SAutoBufferBind
{
enum
{
TARGET = eTarget, BINDING = eBinding
};
SAutoBufferBind(GLuint uBuffer)
{
GLint iBinding;
glGetIntegerv(BINDING, &iBinding);
m_uPreviousBinding = (GLuint)iBinding;
glBindBuffer(TARGET, uBuffer);
}
~SAutoBufferBind()
{
glBindBuffer(TARGET, m_uPreviousBinding);
}
GLuint m_uPreviousBinding;
};
#if !defined(glNamedBufferDataEXT)
inline void glNamedBufferDataEXT(GLuint uBuffer, GLsizeiptr iSize, const void* pData, GLenum eUsage)
{
SAutoBufferBind<> kAutoBind(uBuffer);
glBufferData(kAutoBind.TARGET, iSize, pData, eUsage);
}
#endif
#if !defined(glNamedBufferSubDataEXT)
inline void glNamedBufferSubDataEXT(GLuint uBuffer, GLintptr iOffset, GLsizeiptr iSize, const void* pData)
{
SAutoBufferBind<> kAutoBind(uBuffer);
glBufferSubData(kAutoBind.TARGET, iOffset, iSize, pData);
}
#endif
#if !defined(glMapNamedBufferEXT)
inline GLvoid* glMapNamedBufferEXT(GLuint uBuffer, GLenum eAccess)
{
SAutoBufferBind<> kAutoBind(uBuffer);
#if DXGLES
// Workaround, bind full buffer with range
DXGL_NOT_IMPLEMENTED;
return NULL;
#else
return glMapBuffer(kAutoBind.TARGET, eAccess);
#endif
}
#endif
#if !defined(glMapNamedBufferRangeEXT)
inline GLvoid* glMapNamedBufferRangeEXT(GLuint uBuffer, GLintptr iOffset, GLsizeiptr iLength, GLbitfield uAccess)
{
SAutoBufferBind<> kAutoBind(uBuffer);
return glMapBufferRange(kAutoBind.TARGET, iOffset, iLength, uAccess);
}
#endif
#if !defined(glUnmapNamedBufferEXT)
inline GLboolean glUnmapNamedBufferEXT(GLuint uBuffer)
{
SAutoBufferBind<> kAutoBind(uBuffer);
return glUnmapBuffer(kAutoBind.TARGET);
}
#endif
#if !defined(glGetNamedBufferSubDataEXT) && !DXGLES
inline void glGetNamedBufferSubDataEXT(GLuint uBuffer, GLintptr iOffset, GLsizeiptr iSize, void* pData)
{
SAutoBufferBind<> kAutoBind(uBuffer);
glGetBufferSubData(kAutoBind.TARGET, iOffset, iSize, pData);
}
#endif
#if !defined(glNamedCopyBufferSubDataEXT)
inline void glNamedCopyBufferSubDataEXT(GLuint uReadBuffer, GLuint uWriteBuffer, GLintptr iReadOffset, GLintptr iWriteOffset, GLsizeiptr iSize)
{
SAutoBufferBind<GL_COPY_READ_BUFFER, GL_COPY_READ_BUFFER_BINDING> kAutoBindRead(uReadBuffer);
SAutoBufferBind<GL_COPY_WRITE_BUFFER, GL_COPY_WRITE_BUFFER_BINDING> kAutoBindWrite(uWriteBuffer);
glCopyBufferSubData(kAutoBindRead.TARGET, kAutoBindWrite.TARGET, iReadOffset, iWriteOffset, iSize);
}
#endif
#if !defined(glNamedBufferStorageEXT) && DXGL_SUPPORT_BUFFER_STORAGE
inline void glNamedBufferStorageEXT(GLuint uBuffer, GLsizeiptr iSize, const GLvoid* pData, GLbitfield uFlags)
{
SAutoBufferBind<> kAutoBind(uBuffer);
glBufferStorage(kAutoBind.TARGET, iSize, pData, uFlags);
}
#endif
#if defined(ANDROID) && !defined(EGL_OPENGL_API)
#define EGL_OPENGL_API 0x30A2
#endif
#endif //__GLFEATURES__
@@ -0,0 +1,608 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Defines the required information about image formats used
// by DXGL as well as utility functions.
#include "RenderDll_precompiled.h"
#include <AzDXGIFormat.h>
#include "GLFormat.hpp"
namespace NCryOpenGL
{
#define NA UINT_MAX
#define DXGL_DXGI_FORMAT(_FormatID) DXGI_FORMAT_ ## _FormatID
#define DXGL_UNCOMPRESSED_LAYOUT(_FormatID) g_kUncompressedLayout_ ## _FormatID
#define DXGL_TEXTURE_FORMAT(_FormatID) g_kTextureFormat_ ## _FormatID
#define DXGL_GL_INTERNAL_FORMAT(_InternalID) GL ## _InternalID
#define DXGL_GI_CHANNEL_TYPE(_Type) eGICT_ ## _Type
#define _PTR_MAP(_Type) _Type ## PtrMap
#define _PTR_MAP_DEFAULT(_Type, _Enum, _Ptr) \
template <_Enum eValue> \
struct _PTR_MAP(_Type){static const _Type* ms_pPtr; }; \
template <_Enum eValue> \
const _Type * _PTR_MAP(_Type) < eValue > ::ms_pPtr = _Ptr;
#define _PTR_MAP_VALUE(_Type, _Value, _Ptr) \
template <> \
struct _PTR_MAP(_Type) < _Value > {static const _Type* ms_pPtr; }; \
const _Type* _PTR_MAP(_Type) < _Value > ::ms_pPtr = _Ptr;
#define _UINT_MAP(_Name) S ## _Name ## UintMap
#define _UINT_MAP_DEFAULT(_Name, _Enum, _UIntVal) \
template <_Enum eValue> \
struct _UINT_MAP(_Name){enum {VALUE = _UIntVal}; };
#define _UINT_MAP_VALUE(_Name, _Value, _UIntVal) \
template <> \
struct _UINT_MAP(_Name) < _Value > {enum {VALUE = _UIntVal}; };
////////////////////////////////////////////////////////////////////////////////
// Uncompressed layouts for renderable formats
////////////////////////////////////////////////////////////////////////////////
_PTR_MAP_DEFAULT(SUncompressedLayout, EGIFormat, NULL)
#define _UNCOMPR_LAY(_FormatID, _NumR, _NumG, _NumB, _NumA, _ShiftR, _ShiftG, _ShiftB, _ShiftA, _TypeRGBA, _Depth, _TypeD, _Stencil, _TypeS, _Spare) \
static const SUncompressedLayout DXGL_UNCOMPRESSED_LAYOUT(_FormatID) = \
{ \
_NumR, _NumG, _NumB, _NumA, \
_ShiftR, _ShiftG, _ShiftB, _ShiftA, \
DXGL_GI_CHANNEL_TYPE(_TypeRGBA), \
_Depth, DXGL_GI_CHANNEL_TYPE(_TypeD), \
_Stencil, DXGL_GI_CHANNEL_TYPE(_TypeS), \
_Spare \
}; \
_PTR_MAP_VALUE(SUncompressedLayout, DXGL_GI_FORMAT(_FormatID), &DXGL_UNCOMPRESSED_LAYOUT(_FormatID))
// | FORMAT_ID | RGBA_SIZES | RGBA_SHIFTS | RGBA | DEPTH | STENCIL | - |
// | | NR NG NB NA | SR SG SB SA | TYPE | N TYPE | N TYPE | X |
_UNCOMPR_LAY(R32G32B32A32_FLOAT, 32, 32, 32, 32, 0, 32, 64, 96, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32B32A32_UINT, 32, 32, 32, 32, 0, 32, 64, 96, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32B32A32_SINT, 32, 32, 32, 32, 0, 32, 64, 96, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32B32_FLOAT, 32, 32, 32, 0, 0, 32, 64, 96, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32B32_UINT, 32, 32, 32, 0, 0, 32, 64, 96, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32B32_SINT, 32, 32, 32, 0, 0, 32, 64, 96, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16B16A16_FLOAT, 16, 16, 16, 16, 0, 16, 32, 48, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16B16A16_UNORM, 16, 16, 16, 16, 0, 16, 32, 48, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16B16A16_UINT, 16, 16, 16, 16, 0, 16, 32, 48, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16B16A16_SNORM, 16, 16, 16, 16, 0, 16, 32, 48, SNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16B16A16_SINT, 16, 16, 16, 16, 0, 16, 32, 48, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32_FLOAT, 32, 32, 0, 0, 0, 32, NA, NA, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32_UINT, 32, 32, 0, 0, 0, 32, NA, NA, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32G32_SINT, 32, 32, 0, 0, 0, 32, NA, NA, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(D32_FLOAT_S8X24_UINT, 0, 0, 0, 0, NA, NA, NA, NA, UNUSED, 32, FLOAT, 8, UINT, 24)
_UNCOMPR_LAY(R10G10B10A2_UNORM, 10, 10, 10, 2, 0, 10, 20, 30, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R10G10B10A2_UINT, 10, 10, 10, 2, 0, 10, 20, 30, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R11G11B10_FLOAT, 11, 11, 10, 0, 0, 11, 22, NA, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8B8A8_UNORM, 8, 8, 8, 8, 0, 8, 16, 24, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8B8A8_UNORM_SRGB, 8, 8, 8, 8, 0, 8, 16, 24, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8B8A8_UINT, 8, 8, 8, 8, 0, 8, 16, 24, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8B8A8_SNORM, 8, 8, 8, 8, 0, 8, 16, 24, SNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8B8A8_SINT, 8, 8, 8, 8, 0, 8, 16, 24, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16_FLOAT, 16, 16, 0, 0, 0, 16, NA, NA, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16_UNORM, 16, 16, 0, 0, 0, 16, NA, NA, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16_UINT, 16, 16, 0, 0, 0, 16, NA, NA, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16_SNORM, 16, 16, 0, 0, 0, 16, NA, NA, SNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16G16_SINT, 16, 16, 0, 0, 0, 16, NA, NA, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(D32_FLOAT, 0, 0, 0, 0, NA, NA, NA, NA, UNUSED, 32, FLOAT, 0, UNUSED, 0)
_UNCOMPR_LAY(R32_FLOAT, 32, 0, 0, 0, 0, NA, NA, NA, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32_UINT, 32, 0, 0, 0, 0, NA, NA, NA, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R32_SINT, 32, 0, 0, 0, 0, NA, NA, NA, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(D24_UNORM_S8_UINT, 0, 0, 0, 0, NA, NA, NA, NA, UNUSED, 24, UNORM, 8, UINT, 0)
_UNCOMPR_LAY(R24_UNORM_X8_TYPELESS, 24, 0, 0, 0, NA, NA, NA, NA, UNORM, 0, UNUSED, 0, UNUSED, 8)
_UNCOMPR_LAY(R8G8_UNORM, 8, 8, 0, 0, 0, 8, NA, NA, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8_UINT, 8, 8, 0, 0, 0, 8, NA, NA, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8_SNORM, 8, 8, 0, 0, 0, 8, NA, NA, SNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8G8_SINT, 8, 8, 0, 0, 0, 8, NA, NA, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16_FLOAT, 16, 0, 0, 0, 0, NA, NA, NA, FLOAT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(D16_UNORM, 0, 0, 0, 0, NA, NA, NA, NA, UNUSED, 16, UNORM, 0, UNUSED, 0)
_UNCOMPR_LAY(R16_UNORM, 16, 0, 0, 0, 0, NA, NA, NA, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16_UINT, 16, 0, 0, 0, 0, NA, NA, NA, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16_SNORM, 16, 0, 0, 0, 0, NA, NA, NA, SNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R16_SINT, 16, 0, 0, 0, 0, NA, NA, NA, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8_UNORM, 8, 0, 0, 0, 0, NA, NA, NA, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8_UINT, 8, 0, 0, 0, 0, NA, NA, NA, UINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8_SNORM, 8, 0, 0, 0, 0, NA, NA, NA, SNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(R8_SINT, 8, 0, 0, 0, 0, NA, NA, NA, SINT, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(A8_UNORM, 0, 0, 0, 8, NA, NA, NA, 0, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(B5G6R5_UNORM, 5, 6, 5, 0, 11, 5, 0, NA, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(B5G5R5A1_UNORM, 5, 5, 5, 1, 10, 5, 0, 15, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(B8G8R8A8_UNORM, 8, 8, 8, 8, 16, 8, 0, 24, UNORM, 0, UNUSED, 0, UNUSED, 0)
_UNCOMPR_LAY(B8G8R8X8_UNORM, 8, 8, 8, 0, 16, 8, 0, NA, UNORM, 0, UNUSED, 0, UNUSED, 8)
#undef _UNCOMPR_LAY
////////////////////////////////////////////////////////////////////////////////
// Swizzle required to map each texture format to the corresponding DXGI format
////////////////////////////////////////////////////////////////////////////////
#define DXGL_SWIZZLE_RED 0
#define DXGL_SWIZZLE_GREEN 1
#define DXGL_SWIZZLE_BLUE 2
#define DXGL_SWIZZLE_ALPHA 3
#define DXGL_SWIZZLE_ZERO 4
#define DXGL_SWIZZLE_ONE 5
#define _SWIZZLE_MASK(_Red, _Green, _Blue, _Alpha) \
DXGL_SWIZZLE_ ## _Red << 9 | \
DXGL_SWIZZLE_ ## _Green << 6 | \
DXGL_SWIZZLE_ ## _Blue << 3 | \
DXGL_SWIZZLE_ ## _Alpha
_UINT_MAP_DEFAULT(DXGITextureSwizzle, TSwizzleMask, _SWIZZLE_MASK(RED, GREEN, BLUE, ALPHA))
#define _DXGI_TEX_SWIZZLE(_FormatID, _Red, _Green, _Blue, _Alpha) _UINT_MAP_VALUE(DXGITextureSwizzle, DXGL_GI_FORMAT(_FormatID), _SWIZZLE_MASK(_Red, _Green, _Blue, _Alpha))
_DXGI_TEX_SWIZZLE(A8_UNORM, ZERO, ZERO, ZERO, RED)
#if DXGLES
_DXGI_TEX_SWIZZLE(B8G8R8A8_UNORM, BLUE, GREEN, RED, ALPHA)
_DXGI_TEX_SWIZZLE(B8G8R8X8_UNORM, BLUE, GREEN, RED, ALPHA)
_DXGI_TEX_SWIZZLE(B8G8R8A8_UNORM_SRGB, BLUE, GREEN, RED, ALPHA)
_DXGI_TEX_SWIZZLE(B8G8R8X8_UNORM_SRGB, BLUE, GREEN, RED, ALPHA)
#endif
#undef _DXGI_TEX_SWIZZLE
#undef _SWIZZLE_MASK
////////////////////////////////////////////////////////////////////////////////
// Texturable formats (split between uncompressed and compressed)
////////////////////////////////////////////////////////////////////////////////
_PTR_MAP_DEFAULT(STextureFormat, EGIFormat, NULL)
#define _TEX(_FormatID, _GLInternalFormat, _GLBaseFormat, _Compressed, _GLType, _BlockWidth, _BlockHeight, _BlockDepth, _NumBlockBytes, _SRGB) \
static const STextureFormat DXGL_TEXTURE_FORMAT(_FormatID) = \
{ \
_GLInternalFormat, \
_GLBaseFormat, \
_Compressed, \
_SRGB, \
_GLType, \
_BlockWidth, \
_BlockHeight, \
_BlockDepth, \
_NumBlockBytes \
}; \
_PTR_MAP_VALUE(STextureFormat, DXGL_GI_FORMAT(_FormatID), &DXGL_TEXTURE_FORMAT(_FormatID))
#define _UNCOMPR_TEX(_FormatID, _GLInternalFormat, _GLBaseFormat, _GLType, _SRGB, _Bytes) _TEX(_FormatID, _GLInternalFormat, _GLBaseFormat, false, _GLType, 1, 1, 1, _Bytes, _SRGB)
#define _COMPR_TEX(_FormatID, _GLInternalFormat, _GLBaseFormat, _BlockWidth, _BlockHeight, _BlockDepth, _NumBlockBytes, _SRGB) _TEX(_FormatID, _GLInternalFormat, _GLBaseFormat, true, 0, _BlockWidth, _BlockHeight, _BlockDepth, _NumBlockBytes, _SRGB)
// | FORMAT_ID | GL_INTERNAL_FORMAT | GL_FORMAT | GL_TYPE | SRGB | BYTES |
_UNCOMPR_TEX(R32G32B32A32_FLOAT, GL_RGBA32F, GL_RGBA, GL_FLOAT, false, 16)
_UNCOMPR_TEX(R32G32B32A32_UINT, GL_RGBA32UI, GL_RGBA, GL_UNSIGNED_INT, false, 16)
_UNCOMPR_TEX(R32G32B32A32_SINT, GL_RGBA32I, GL_RGBA, GL_INT, false, 16)
_UNCOMPR_TEX(R32G32B32_FLOAT, GL_RGB32F, GL_RGB, GL_FLOAT, false, 12)
_UNCOMPR_TEX(R32G32B32_UINT, GL_RGB32UI, GL_RGB, GL_UNSIGNED_INT, false, 12)
_UNCOMPR_TEX(R32G32B32_SINT, GL_RGB32I, GL_RGB, GL_INT, false, 12)
_UNCOMPR_TEX(R16G16B16A16_FLOAT, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, false, 8)
#if DXGLES
_UNCOMPR_TEX(R16G16B16A16_UNORM, GL_RGBA16UI, GL_RGBA, GL_UNSIGNED_SHORT, false, 8)
#else
_UNCOMPR_TEX(R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT, false, 8)
#endif
_UNCOMPR_TEX(R16G16B16A16_UINT, GL_RGBA16UI, GL_RGBA, GL_UNSIGNED_SHORT, false, 8)
#if !DXGLES
_UNCOMPR_TEX(R16G16B16A16_SNORM, GL_RGBA16_SNORM, GL_RGBA, GL_SHORT, false, 8)
#else
_UNCOMPR_TEX(R16G16B16A16_SNORM, GL_NONE, GL_RGBA, GL_SHORT, false, 8)
#endif
_UNCOMPR_TEX(R16G16B16A16_SINT, GL_RGBA16I, GL_RGBA, GL_SHORT, false, 8)
_UNCOMPR_TEX(R32G32_FLOAT, GL_RG32F, GL_RG, GL_FLOAT, false, 8)
_UNCOMPR_TEX(R32G32_UINT, GL_RG32UI, GL_RG, GL_UNSIGNED_INT, false, 8)
_UNCOMPR_TEX(R32G32_SINT, GL_RG32I, GL_RG, GL_INT, false, 8)
_UNCOMPR_TEX(D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, false, 8)
#if DXGLES
_UNCOMPR_TEX(R10G10B10A2_UNORM, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false, 4)
_UNCOMPR_TEX(R10G10B10A2_UINT, GL_RGB10_A2UI, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false, 4)
#else
_UNCOMPR_TEX(R10G10B10A2_UNORM, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_10_10_10_2, false, 4)
_UNCOMPR_TEX(R10G10B10A2_UINT, GL_RGB10_A2UI, GL_RGBA, GL_UNSIGNED_INT_10_10_10_2, false, 4)
#endif
_UNCOMPR_TEX(R11G11B10_FLOAT, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false, 4)
_UNCOMPR_TEX(R8G8B8A8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, false, 4)
_UNCOMPR_TEX(R8G8B8A8_UNORM_SRGB, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, true, 4)
_UNCOMPR_TEX(R8G8B8A8_UINT, GL_RGBA8UI, GL_RGBA, GL_UNSIGNED_BYTE, false, 4)
_UNCOMPR_TEX(R8G8B8A8_SNORM, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE, false, 4)
_UNCOMPR_TEX(R8G8B8A8_SINT, GL_RGBA8I, GL_RGBA, GL_BYTE, false, 4)
_UNCOMPR_TEX(R16G16_FLOAT, GL_RG16F, GL_RG, GL_HALF_FLOAT, false, 4)
#if DXGLES
// https://www.khronos.org/opengles/sdk/docs/man3/html/glRenderbufferStorage.xhtml
// GL ES Can't convert to a render target with a different internal format... Framebuffer will error to "incomplete" if so
_UNCOMPR_TEX(R16G16_UNORM, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT, false, 4)
#else
_UNCOMPR_TEX(R16G16_UNORM, GL_RG16, GL_RG, GL_UNSIGNED_SHORT, false, 4)
#endif
_UNCOMPR_TEX(R16G16_UINT, GL_RG16UI, GL_RG, GL_UNSIGNED_SHORT, false, 4)
_UNCOMPR_TEX(R16G16_SINT, GL_RG16I, GL_RG, GL_SHORT, false, 4)
_UNCOMPR_TEX(D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false, 4)
_UNCOMPR_TEX(R32_FLOAT, GL_R32F, GL_RED, GL_FLOAT, false, 4)
_UNCOMPR_TEX(R32_UINT, GL_R32UI, GL_RED, GL_UNSIGNED_INT, false, 4)
_UNCOMPR_TEX(R32_SINT, GL_R32I, GL_RED, GL_INT, false, 4)
_UNCOMPR_TEX(D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false, 4)
_UNCOMPR_TEX(R8G8_UNORM, GL_RG8, GL_RG, GL_UNSIGNED_BYTE, false, 2)
_UNCOMPR_TEX(R8G8_UINT, GL_RG8UI, GL_RG, GL_UNSIGNED_BYTE, false, 2)
_UNCOMPR_TEX(R8G8_SNORM, GL_RG8_SNORM, GL_RG, GL_BYTE, false, 2)
_UNCOMPR_TEX(R8G8_SINT, GL_RG8I, GL_RG, GL_BYTE, false, 2)
_UNCOMPR_TEX(R16_FLOAT, GL_R16F, GL_RED, GL_HALF_FLOAT, false, 2)
_UNCOMPR_TEX(D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false, 2)
#if DXGLES
_UNCOMPR_TEX(R16_UNORM, GL_R16UI, GL_RED, GL_UNSIGNED_SHORT, false, 2)
#else
_UNCOMPR_TEX(R16_UNORM, GL_R16, GL_RED, GL_UNSIGNED_SHORT, false, 2)
#endif
_UNCOMPR_TEX(R16_UINT, GL_R16UI, GL_RED, GL_UNSIGNED_SHORT, false, 2)
_UNCOMPR_TEX(R16_SINT, GL_R16I, GL_RED, GL_SHORT, false, 2)
_UNCOMPR_TEX(R8_UNORM, GL_R8, GL_RED, GL_UNSIGNED_BYTE, false, 1)
_UNCOMPR_TEX(R8_UINT, GL_R8UI, GL_RED, GL_UNSIGNED_BYTE, false, 1)
_UNCOMPR_TEX(R8_SNORM, GL_R8_SNORM, GL_RED, GL_BYTE, false, 1)
_UNCOMPR_TEX(R8_SINT, GL_R8I, GL_RED, GL_BYTE, false, 1)
_UNCOMPR_TEX(A8_UNORM, GL_R8, GL_RED, GL_UNSIGNED_BYTE, false, 1)
_UNCOMPR_TEX(R9G9B9E5_SHAREDEXP, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, false, 4)
#if DXGLES
_UNCOMPR_TEX(B8G8R8A8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, false, 4)
_UNCOMPR_TEX(B8G8R8A8_UNORM_SRGB, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, true, 4)
_UNCOMPR_TEX(B8G8R8X8_UNORM, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, false, 4)
_UNCOMPR_TEX(B8G8R8X8_UNORM_SRGB, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, true, 4)
#else
_UNCOMPR_TEX(B8G8R8A8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, false, 4)
_UNCOMPR_TEX(B8G8R8A8_UNORM_SRGB, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, true, 4)
_UNCOMPR_TEX(B8G8R8X8_UNORM, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, false, 4)
_UNCOMPR_TEX(B8G8R8X8_UNORM_SRGB, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, true, 4)
#endif
#if !DXGLES
_UNCOMPR_TEX(B5G6R5_UNORM, GL_RGB565, GL_BGR, GL_UNSIGNED_SHORT_5_6_5_REV, false, 2)
_UNCOMPR_TEX(B5G5R5A1_UNORM, GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_5_5_5_1, false, 2)
_UNCOMPR_TEX(R16_SNORM, GL_R16_SNORM, GL_RED, GL_SHORT, false, 2)
_UNCOMPR_TEX(R16G16_SNORM, GL_RG16_SNORM, GL_RG, GL_SHORT, false, 4)
#endif
// | FORMAT_ID | GL_INTERNAL_FORMAT | GL_FORMAT | BLOCK | SRGB |
// | | | | X | Y | Z | BYTES | |
#if DXGL_SUPPORT_ETC2_EAC_COMPRESSION
_COMPR_TEX(EAC_R11_UNORM, GL_COMPRESSED_R11_EAC, GL_RED, 4, 4, 1, 8, false)
_COMPR_TEX(EAC_R11_SNORM, GL_COMPRESSED_SIGNED_R11_EAC, GL_RED, 4, 4, 1, 8, false)
_COMPR_TEX(EAC_RG11_UNORM, GL_COMPRESSED_RG11_EAC, GL_RG, 4, 4, 1, 16, false)
_COMPR_TEX(EAC_RG11_SNORM, GL_COMPRESSED_SIGNED_RG11_EAC, GL_RG, 4, 4, 1, 16, false)
_COMPR_TEX(ETC2_UNORM, GL_COMPRESSED_RGB8_ETC2, GL_RGB, 4, 4, 1, 8, false)
_COMPR_TEX(ETC2_UNORM_SRGB, GL_COMPRESSED_SRGB8_ETC2, GL_RGB, 4, 4, 1, 8, true)
_COMPR_TEX(ETC2A_UNORM, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_RGBA, 4, 4, 1, 16, false)
_COMPR_TEX(ETC2A_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_RGBA, 4, 4, 1, 16, true)
#endif //DXGL_SUPPORT_ETC2_EAC_COMPRESSION
#if DXGL_SUPPORT_S3TC_TEXTURES
_COMPR_TEX(BC1_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, 4, 4, 1, 8, false)
_COMPR_TEX(BC1_UNORM_SRGB, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, 4, 4, 1, 8, true)
_COMPR_TEX(BC2_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, 4, 4, 1, 16, false)
_COMPR_TEX(BC2_UNORM_SRGB, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, 4, 4, 1, 16, true)
_COMPR_TEX(BC3_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, 4, 4, 1, 16, false)
_COMPR_TEX(BC3_UNORM_SRGB, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, 4, 4, 1, 16, true)
#endif //DXGL_SUPPORT_S3TC_TEXTURES
#if !DXGLES
_COMPR_TEX(BC4_UNORM, GL_COMPRESSED_RED_RGTC1, GL_RED, 4, 4, 1, 8, false)
_COMPR_TEX(BC4_SNORM, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_RED, 4, 4, 1, 8, false)
_COMPR_TEX(BC5_UNORM, GL_COMPRESSED_RG_RGTC2, GL_RG, 4, 4, 1, 16, false)
_COMPR_TEX(BC5_SNORM, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_RG, 4, 4, 1, 16, false)
#if DXGL_SUPPORT_BPTC
_COMPR_TEX(BC6H_UF16, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_RGB, 4, 4, 1, 16, false)
_COMPR_TEX(BC6H_SF16, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_RGB, 4, 4, 1, 16, false)
_COMPR_TEX(BC7_UNORM, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_RGBA, 4, 4, 1, 16, false)
_COMPR_TEX(BC7_UNORM_SRGB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, GL_RGBA, 4, 4, 1, 16, true)
#endif //DXGL_SUPPORT_BPTC
#endif //!DXGLES
// | FORMAT_ID | GL_INTERNAL_FORMAT | GL_FORMAT | BLOCK | SRGB |
// | | | | X | Y | Z | BYTES | |
#if defined(ANDROID) && DXGLES
_COMPR_TEX(ASTC_4x4_UNORM, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_RGBA, 4, 4, 1, 16, false)
_COMPR_TEX(ASTC_4x4_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, GL_RGBA, 4, 4, 1, 16, true)
_COMPR_TEX(ASTC_5x4_UNORM, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_RGBA, 5, 4, 1, 16, false)
_COMPR_TEX(ASTC_5x4_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, GL_RGBA, 5, 4, 1, 16, true)
_COMPR_TEX(ASTC_5x5_UNORM, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_RGBA, 5, 5, 1, 16, false)
_COMPR_TEX(ASTC_5x5_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, GL_RGBA, 5, 5, 1, 16, true)
_COMPR_TEX(ASTC_6x5_UNORM, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_RGBA, 6, 5, 1, 16, false)
_COMPR_TEX(ASTC_6x5_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, GL_RGBA, 6, 5, 1, 16, true)
_COMPR_TEX(ASTC_6x6_UNORM, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_RGBA, 6, 6, 1, 16, false)
_COMPR_TEX(ASTC_6x6_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, GL_RGBA, 6, 6, 1, 16, true)
_COMPR_TEX(ASTC_8x5_UNORM, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_RGBA, 8, 5, 1, 16, false)
_COMPR_TEX(ASTC_8x5_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, GL_RGBA, 8, 5, 1, 16, true)
_COMPR_TEX(ASTC_8x6_UNORM, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_RGBA, 8, 6, 1, 16, false)
_COMPR_TEX(ASTC_8x6_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, GL_RGBA, 8, 6, 1, 16, true)
_COMPR_TEX(ASTC_8x8_UNORM, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_RGBA, 8, 8, 1, 16, false)
_COMPR_TEX(ASTC_8x8_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, GL_RGBA, 8, 8, 1, 16, true)
_COMPR_TEX(ASTC_10x5_UNORM, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_RGBA, 10, 5, 1, 16, false)
_COMPR_TEX(ASTC_10x5_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, GL_RGBA, 10, 5, 1, 16, true)
_COMPR_TEX(ASTC_10x6_UNORM, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_RGBA, 10, 6, 1, 16, false)
_COMPR_TEX(ASTC_10x6_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, GL_RGBA, 10, 6, 1, 16, true)
_COMPR_TEX(ASTC_10x8_UNORM, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_RGBA, 10, 8, 1, 16, false)
_COMPR_TEX(ASTC_10x8_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_RGBA, 10, 8, 1, 16, true)
_COMPR_TEX(ASTC_10x10_UNORM, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_RGBA, 10, 10, 1, 16, false)
_COMPR_TEX(ASTC_10x10_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, GL_RGBA, 10, 10, 1, 16, true)
_COMPR_TEX(ASTC_12x10_UNORM, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_RGBA, 12, 10, 1, 16, false)
_COMPR_TEX(ASTC_12x10_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_RGBA, 12, 10, 1, 16, true)
_COMPR_TEX(ASTC_12x12_UNORM, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_RGBA, 12, 12, 1, 16, false)
_COMPR_TEX(ASTC_12x12_UNORM_SRGB, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, GL_RGBA, 12, 12, 1, 16, true)
#endif
#undef _TEX
#undef _UNCOMPR_TEX
#undef _COMPR_TEX
////////////////////////////////////////////////////////////////////////////////
// Default support for each format
////////////////////////////////////////////////////////////////////////////////
_UINT_MAP_DEFAULT(DefaultSupport, EGIFormat, 0)
#define _SUPPORT(_FormatID, _Mask) _UINT_MAP_VALUE(DefaultSupport, DXGL_GI_FORMAT(_FormatID), _Mask)
DXGL_TODO("Add here hardcoded default support masks (see _SUPPORT) for each format to use when format queries are not supported and for particular features")
#undef _SUPPORT
////////////////////////////////////////////////////////////////////////////////
// Typeless format mappings
////////////////////////////////////////////////////////////////////////////////
_UINT_MAP_DEFAULT(TypelessFormat, EGIFormat, eGIF_NUM)
_UINT_MAP_DEFAULT(TypelessConversion, EGIFormat, eGIFC_UNSUPPORTED)
#define _TYPED_CONVERT(_FormatID, _TypelessID, _Conversion) \
_UINT_MAP_VALUE(TypelessFormat, DXGL_GI_FORMAT(_FormatID), DXGL_GI_FORMAT(_TypelessID)) \
_UINT_MAP_VALUE(TypelessConversion, DXGL_GI_FORMAT(_FormatID), eGIFC_ ## _Conversion)
#define _TYPED_DEFAULT(_FormatID, _TypelessID) \
_PTR_MAP_VALUE(STextureFormat, DXGL_GI_FORMAT(_TypelessID), &DXGL_TEXTURE_FORMAT(_FormatID)) \
_PTR_MAP_VALUE(SUncompressedLayout, DXGL_GI_FORMAT(_TypelessID), _PTR_MAP(SUncompressedLayout) < DXGL_GI_FORMAT(_FormatID) > ::ms_pPtr) \
_TYPED_CONVERT(_FormatID, _TypelessID, NONE)
_TYPED_DEFAULT(R32G32B32A32_FLOAT, R32G32B32A32_TYPELESS)
_TYPED_CONVERT(R32G32B32A32_UINT, R32G32B32A32_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R32G32B32A32_SINT, R32G32B32A32_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(R32G32B32_FLOAT, R32G32B32_TYPELESS)
_TYPED_CONVERT(R32G32B32_UINT, R32G32B32_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R32G32B32_SINT, R32G32B32_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(R16G16B16A16_FLOAT, R16G16B16A16_TYPELESS)
_TYPED_CONVERT(R16G16B16A16_UNORM, R16G16B16A16_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R16G16B16A16_UINT, R16G16B16A16_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R16G16B16A16_SNORM, R16G16B16A16_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R16G16B16A16_SINT, R16G16B16A16_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(R32G32_FLOAT, R32G32_TYPELESS)
_TYPED_CONVERT(R32G32_UINT, R32G32_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R32G32_SINT, R32G32_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(D32_FLOAT_S8X24_UINT, R32G8X24_TYPELESS)
_TYPED_CONVERT(R32_FLOAT_X8X24_TYPELESS, R32G8X24_TYPELESS, DEPTH_TO_RED)
_TYPED_CONVERT(X32_TYPELESS_G8X24_UINT, R32G8X24_TYPELESS, STENCIL_TO_RED)
_TYPED_DEFAULT(R10G10B10A2_UNORM, R10G10B10A2_TYPELESS)
_TYPED_CONVERT(R10G10B10A2_UINT, R10G10B10A2_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(R8G8B8A8_UNORM, R8G8B8A8_TYPELESS)
_TYPED_CONVERT(R8G8B8A8_UNORM_SRGB, R8G8B8A8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8G8B8A8_UINT, R8G8B8A8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8G8B8A8_SNORM, R8G8B8A8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8G8B8A8_SINT, R8G8B8A8_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(R16G16_FLOAT, R16G16_TYPELESS)
_TYPED_CONVERT(R16G16_UNORM, R16G16_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R16G16_UINT, R16G16_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R16G16_SNORM, R16G16_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R16G16_SINT, R16G16_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(D32_FLOAT, R32_TYPELESS)
_TYPED_CONVERT(R32_FLOAT, R32_TYPELESS, DEPTH_TO_RED)
_TYPED_DEFAULT(D24_UNORM_S8_UINT, R24G8_TYPELESS)
_TYPED_CONVERT(R24_UNORM_X8_TYPELESS, R24G8_TYPELESS, DEPTH_TO_RED)
_TYPED_CONVERT(X24_TYPELESS_G8_UINT, R24G8_TYPELESS, STENCIL_TO_RED)
_TYPED_DEFAULT(R8G8_UNORM, R8G8_TYPELESS)
_TYPED_CONVERT(R8G8_UINT, R8G8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8G8_SNORM, R8G8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8G8_SINT, R8G8_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(D16_UNORM, R16_TYPELESS)
_TYPED_CONVERT(R16_UNORM, R16_TYPELESS, DEPTH_TO_RED)
_TYPED_DEFAULT(R8_UNORM, R8_TYPELESS)
_TYPED_CONVERT(R8_UINT, R8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8_SNORM, R8_TYPELESS, TEXTURE_VIEW)
_TYPED_CONVERT(R8_SINT, R8_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(B8G8R8A8_UNORM, B8G8R8A8_TYPELESS)
_TYPED_CONVERT(B8G8R8A8_UNORM_SRGB, B8G8R8A8_TYPELESS, TEXTURE_VIEW)
#if DXGL_SUPPORT_ETC2_EAC_COMPRESSION
_TYPED_DEFAULT(EAC_R11_UNORM, EAC_R11_TYPELESS)
_TYPED_CONVERT(EAC_R11_SNORM, EAC_R11_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(EAC_RG11_UNORM, EAC_RG11_TYPELESS)
_TYPED_CONVERT(EAC_RG11_SNORM, EAC_RG11_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(ETC2_UNORM, ETC2_TYPELESS)
_TYPED_CONVERT(ETC2_UNORM_SRGB, ETC2_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(ETC2A_UNORM, ETC2A_TYPELESS)
_TYPED_CONVERT(ETC2A_UNORM_SRGB, ETC2A_TYPELESS, TEXTURE_VIEW)
#endif
_TYPED_DEFAULT(B8G8R8X8_UNORM, B8G8R8X8_TYPELESS)
_TYPED_CONVERT(B8G8R8X8_UNORM_SRGB, B8G8R8X8_TYPELESS, TEXTURE_VIEW)
#if DXGL_SUPPORT_S3TC_TEXTURES
_TYPED_DEFAULT(BC1_UNORM, BC1_TYPELESS)
_TYPED_CONVERT(BC1_UNORM_SRGB, BC1_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(BC2_UNORM, BC2_TYPELESS)
_TYPED_CONVERT(BC2_UNORM_SRGB, BC2_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(BC3_UNORM, BC3_TYPELESS)
_TYPED_CONVERT(BC3_UNORM_SRGB, BC3_TYPELESS, TEXTURE_VIEW)
#endif //DXGL_SUPPORT_S3TC_TEXTURES
#if !DXGLES
_TYPED_DEFAULT(BC4_UNORM, BC4_TYPELESS)
_TYPED_CONVERT(BC4_SNORM, BC4_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(BC5_UNORM, BC5_TYPELESS)
_TYPED_CONVERT(BC5_SNORM, BC5_TYPELESS, TEXTURE_VIEW)
#if DXGL_SUPPORT_BPTC
_TYPED_DEFAULT(BC6H_UF16, BC6H_TYPELESS)
_TYPED_CONVERT(BC6H_SF16, BC6H_TYPELESS, TEXTURE_VIEW)
_TYPED_DEFAULT(BC7_UNORM, BC7_TYPELESS)
_TYPED_CONVERT(BC7_UNORM_SRGB, BC7_TYPELESS, TEXTURE_VIEW)
#endif //DXGL_SUPPORT_BPTC
#endif //!DXGLES
#undef _TYPED_DEFAULT
#undef _TYPED_CONVERT
////////////////////////////////////////////////////////////////////////////////
// Format information accessors
////////////////////////////////////////////////////////////////////////////////
static SGIFormatInfo g_akFormatInfo[] =
{
#define _FORMAT_INFO(_FormatID) \
{ \
DXGL_DXGI_FORMAT(_FormatID), \
_UINT_MAP(DefaultSupport) < DXGL_GI_FORMAT(_FormatID) > ::VALUE, \
_PTR_MAP(STextureFormat) < DXGL_GI_FORMAT(_FormatID) > ::ms_pPtr, \
_PTR_MAP(SUncompressedLayout) < DXGL_GI_FORMAT(_FormatID) > ::ms_pPtr, \
static_cast<EGIFormat>(_UINT_MAP(TypelessFormat) < DXGL_GI_FORMAT(_FormatID) > ::VALUE), \
static_cast<EGIFormatConversion>(_UINT_MAP(TypelessConversion) < DXGL_GI_FORMAT(_FormatID) > ::VALUE), \
_UINT_MAP(DXGITextureSwizzle) < DXGL_GI_FORMAT(_FormatID) > ::VALUE, \
},
DXGL_GI_FORMATS(_FORMAT_INFO)
#undef _FORMAT_INFO
};
const SGIFormatInfo* GetGIFormatInfo(EGIFormat eGIFormat)
{
assert(eGIFormat < eGIF_NUM);
return &g_akFormatInfo[eGIFormat];
}
DXGI_FORMAT GetDXGIFormat(EGIFormat eGIFormat)
{
const SGIFormatInfo* pFormatInfo(GetGIFormatInfo(eGIFormat));
return (pFormatInfo == NULL) ? DXGI_FORMAT_INVALID : pFormatInfo->m_eDXGIFormat;
}
EGIFormat GetGIFormat(DXGI_FORMAT eDXGIFormat)
{
switch (eDXGIFormat)
{
#define _FORMAT_CASE(_FormatID, ...) \
case DXGL_DXGI_FORMAT(_FormatID): \
return DXGL_GI_FORMAT(_FormatID);
DXGL_GI_FORMATS(_FORMAT_CASE)
#undef _FORMAT_CASE
default:
return eGIF_NUM;
}
}
#undef _PTR_MAP_VALUE
#undef _PTR_MAP_DEFAULT
#undef _PTR_MAP
#undef _UINT_MAP_VALUE
#undef _UINT_MAP_DEFAULT
#undef _UINT_MAP
#undef DXGL_DXGI_FORMAT
#undef DXGL_UNCOMPRESSED_LAYOUT
#undef DXGL_TEXTURE_FORMAT
#undef DXGL_GL_INTERNAL_FORMAT
#undef DXGL_GI_CHANNEL_TYPE
////////////////////////////////////////////////////////////////////////////////
// Texture swizzle encoding
////////////////////////////////////////////////////////////////////////////////
void SwizzleMaskToRGBA(TSwizzleMask uMask, GLint aiRGBA[4])
{
uint32 uChannel(4);
while (uChannel--)
{
switch (uMask & 7)
{
case DXGL_SWIZZLE_RED:
aiRGBA[uChannel] = GL_RED;
break;
case DXGL_SWIZZLE_GREEN:
aiRGBA[uChannel] = GL_GREEN;
break;
case DXGL_SWIZZLE_BLUE:
aiRGBA[uChannel] = GL_BLUE;
break;
case DXGL_SWIZZLE_ALPHA:
aiRGBA[uChannel] = GL_ALPHA;
break;
case DXGL_SWIZZLE_ZERO:
aiRGBA[uChannel] = GL_ZERO;
break;
case DXGL_SWIZZLE_ONE:
aiRGBA[uChannel] = GL_ONE;
break;
default:
assert(false);
}
uMask >>= 3;
}
}
bool RGBAToSwizzleMask(const GLint aiRGBA[4], TSwizzleMask& uMask)
{
uMask = 0;
uint32 uChannel;
for (uChannel = 0; uChannel < 4; ++uChannel, uMask <<= 3)
{
switch (aiRGBA[uChannel])
{
case GL_RED:
uMask |= DXGL_SWIZZLE_RED;
break;
case GL_GREEN:
uMask |= DXGL_SWIZZLE_GREEN;
break;
case GL_BLUE:
uMask |= DXGL_SWIZZLE_BLUE;
break;
case GL_ALPHA:
uMask |= DXGL_SWIZZLE_ALPHA;
break;
case GL_ZERO:
uMask |= DXGL_SWIZZLE_ZERO;
break;
case GL_ONE:
uMask |= DXGL_SWIZZLE_ONE;
break;
default:
return false;
}
}
return true;
}
#undef DXGL_SWIZZLE_RED
#undef DXGL_SWIZZLE_GREEN
#undef DXGL_SWIZZLE_BLUE
#undef DXGL_SWIZZLE_ALPHA
#undef DXGL_SWIZZLE_ZERO
#undef DXGL_SWIZZLE_ONE
bool GetImageFormat(EGIFormat eGIFormat, GLenum* peImageFormat)
{
const SGIFormatInfo* pFormatInfo;
DXGL_TODO("If possible add a specific list of valid image formats rather than re-using texture formats and checking that it's not compressed")
if (eGIFormat == eGIF_NUM ||
(pFormatInfo = GetGIFormatInfo(eGIFormat)) == NULL ||
pFormatInfo->m_pTexture == NULL ||
pFormatInfo->m_pTexture->m_bCompressed)
{
return false;
}
*peImageFormat = (GLenum)pFormatInfo->m_pTexture->m_iInternalFormat;
return true;
}
}
@@ -0,0 +1,355 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declares the image formats used by DXGL and the utility
// methods for converting to and from DXGI formats.
#ifndef __GLFORMAT__
#define __GLFORMAT__
#include "GLCommon.hpp"
// Enumeration of the IDs of all the supported GI format (each ID must match one
// DXGI_FORMAT enumeration value - excluding the DXGI_FORMAT prefix).
#define DXGL_UNCOMPRESSED_GI_FORMATS(_Func) \
_Func(R32G32B32A32_TYPELESS) \
_Func(R32G32B32A32_FLOAT) \
_Func(R32G32B32A32_UINT) \
_Func(R32G32B32A32_SINT) \
_Func(R32G32B32_TYPELESS) \
_Func(R32G32B32_FLOAT) \
_Func(R32G32B32_UINT) \
_Func(R32G32B32_SINT) \
_Func(R16G16B16A16_TYPELESS) \
_Func(R16G16B16A16_FLOAT) \
_Func(R16G16B16A16_UNORM) \
_Func(R16G16B16A16_UINT) \
_Func(R16G16B16A16_SNORM) \
_Func(R16G16B16A16_SINT) \
_Func(R32G32_TYPELESS) \
_Func(R32G32_FLOAT) \
_Func(R32G32_UINT) \
_Func(R32G32_SINT) \
_Func(R32G8X24_TYPELESS) \
_Func(D32_FLOAT_S8X24_UINT) \
_Func(R32_FLOAT_X8X24_TYPELESS) \
_Func(X32_TYPELESS_G8X24_UINT) \
_Func(R10G10B10A2_TYPELESS) \
_Func(R10G10B10A2_UNORM) \
_Func(R10G10B10A2_UINT) \
_Func(R11G11B10_FLOAT) \
_Func(R8G8B8A8_TYPELESS) \
_Func(R8G8B8A8_UNORM) \
_Func(R8G8B8A8_UNORM_SRGB) \
_Func(R8G8B8A8_UINT) \
_Func(R8G8B8A8_SNORM) \
_Func(R8G8B8A8_SINT) \
_Func(R16G16_TYPELESS) \
_Func(R16G16_FLOAT) \
_Func(R16G16_UNORM) \
_Func(R16G16_UINT) \
_Func(R16G16_SNORM) \
_Func(R16G16_SINT) \
_Func(R32_TYPELESS) \
_Func(D32_FLOAT) \
_Func(R32_FLOAT) \
_Func(R32_UINT) \
_Func(R32_SINT) \
_Func(R24G8_TYPELESS) \
_Func(D24_UNORM_S8_UINT) \
_Func(R24_UNORM_X8_TYPELESS) \
_Func(X24_TYPELESS_G8_UINT) \
_Func(R8G8_TYPELESS) \
_Func(R8G8_UNORM) \
_Func(R8G8_UINT) \
_Func(R8G8_SNORM) \
_Func(R8G8_SINT) \
_Func(R16_TYPELESS) \
_Func(R16_FLOAT) \
_Func(D16_UNORM) \
_Func(R16_UNORM) \
_Func(R16_UINT) \
_Func(R16_SNORM) \
_Func(R16_SINT) \
_Func(R8_TYPELESS) \
_Func(R8_UNORM) \
_Func(R8_UINT) \
_Func(R8_SNORM) \
_Func(R8_SINT) \
_Func(A8_UNORM) \
_Func(R9G9B9E5_SHAREDEXP) \
_Func(B5G6R5_UNORM) \
_Func(B5G5R5A1_UNORM) \
_Func(B8G8R8A8_TYPELESS) \
_Func(B8G8R8A8_UNORM) \
_Func(B8G8R8A8_UNORM_SRGB) \
_Func(B8G8R8X8_TYPELESS) \
_Func(B8G8R8X8_UNORM) \
_Func(B8G8R8X8_UNORM_SRGB)
#define DXGL_COMPRESSED_GI_FORMATS(_Func) \
_Func(BC1_TYPELESS) \
_Func(BC1_UNORM) \
_Func(BC1_UNORM_SRGB) \
_Func(BC2_TYPELESS) \
_Func(BC2_UNORM) \
_Func(BC2_UNORM_SRGB) \
_Func(BC3_TYPELESS) \
_Func(BC3_UNORM) \
_Func(BC3_UNORM_SRGB) \
_Func(BC4_TYPELESS) \
_Func(BC4_UNORM) \
_Func(BC4_SNORM) \
_Func(BC5_TYPELESS) \
_Func(BC5_UNORM) \
_Func(BC5_SNORM) \
_Func(BC6H_TYPELESS) \
_Func(BC6H_UF16) \
_Func(BC6H_SF16) \
_Func(BC7_TYPELESS) \
_Func(BC7_UNORM) \
_Func(BC7_UNORM_SRGB) \
_Func(EAC_R11_TYPELESS) \
_Func(EAC_R11_UNORM) \
_Func(EAC_R11_SNORM) \
_Func(EAC_RG11_TYPELESS) \
_Func(EAC_RG11_UNORM) \
_Func(EAC_RG11_SNORM) \
_Func(ETC2_TYPELESS) \
_Func(ETC2_UNORM) \
_Func(ETC2_UNORM_SRGB) \
_Func(ETC2A_TYPELESS) \
_Func(ETC2A_UNORM) \
_Func(ETC2A_UNORM_SRGB) \
_Func(ASTC_4x4_TYPELESS) \
_Func(ASTC_4x4_UNORM) \
_Func(ASTC_4x4_UNORM_SRGB) \
_Func(ASTC_5x4_TYPELESS) \
_Func(ASTC_5x4_UNORM) \
_Func(ASTC_5x4_UNORM_SRGB) \
_Func(ASTC_5x5_TYPELESS) \
_Func(ASTC_5x5_UNORM) \
_Func(ASTC_5x5_UNORM_SRGB) \
_Func(ASTC_6x5_TYPELESS) \
_Func(ASTC_6x5_UNORM) \
_Func(ASTC_6x5_UNORM_SRGB) \
_Func(ASTC_6x6_TYPELESS) \
_Func(ASTC_6x6_UNORM) \
_Func(ASTC_6x6_UNORM_SRGB) \
_Func(ASTC_8x5_TYPELESS) \
_Func(ASTC_8x5_UNORM) \
_Func(ASTC_8x5_UNORM_SRGB) \
_Func(ASTC_8x6_TYPELESS) \
_Func(ASTC_8x6_UNORM) \
_Func(ASTC_8x6_UNORM_SRGB) \
_Func(ASTC_8x8_TYPELESS) \
_Func(ASTC_8x8_UNORM) \
_Func(ASTC_8x8_UNORM_SRGB) \
_Func(ASTC_10x5_TYPELESS) \
_Func(ASTC_10x5_UNORM) \
_Func(ASTC_10x5_UNORM_SRGB) \
_Func(ASTC_10x6_TYPELESS) \
_Func(ASTC_10x6_UNORM) \
_Func(ASTC_10x6_UNORM_SRGB) \
_Func(ASTC_10x8_TYPELESS) \
_Func(ASTC_10x8_UNORM) \
_Func(ASTC_10x8_UNORM_SRGB) \
_Func(ASTC_10x10_TYPELESS) \
_Func(ASTC_10x10_UNORM) \
_Func(ASTC_10x10_UNORM_SRGB) \
_Func(ASTC_12x10_TYPELESS) \
_Func(ASTC_12x10_UNORM) \
_Func(ASTC_12x10_UNORM_SRGB) \
_Func(ASTC_12x12_TYPELESS) \
_Func(ASTC_12x12_UNORM) \
_Func(ASTC_12x12_UNORM_SRGB)
#define DXGL_GI_FORMATS(_Func) \
DXGL_UNCOMPRESSED_GI_FORMATS(_Func) \
DXGL_COMPRESSED_GI_FORMATS(_Func)
namespace NCryOpenGL
{
// Supported DXGI format identifiers
enum EGIFormat
{
#define DXGL_GI_FORMAT(_FormatID) eGIF_ ## _FormatID
#define _GI_FORMAT_ENUM_FUNC(_FormatID, ...) DXGL_GI_FORMAT(_FormatID),
DXGL_GI_FORMATS(_GI_FORMAT_ENUM_FUNC)
#undef _GI_FORMAT_ENUM_FUNC
DXGL_GI_FORMAT(NUM)
};
// Data types supported for DXGI format channels
enum EGIChannelType
{
eGICT_UNUSED, // Not used by the format
eGICT_UNORM, // Unsigned normalized integer (range linearly mapped to [0, 1])
eGICT_UINT, // Unsigned integer
eGICT_FLOAT, // Floating point value
eGICT_SNORM, // Signed normalized integer (range linearly mapped to [-1, 1])
eGICT_SINT, // Signed integer
};
// Utility information about an uncompressed pixel format
struct SUncompressedLayout
{
// Number of bits per pixel for the red, green, blue and alpha channels
uint32 m_uRedBits;
uint32 m_uGreenBits;
uint32 m_uBlueBits;
uint32 m_uAlphaBits;
// Position for the red, green, blue and alpha channels within each pixel
uint32 m_uRedShift;
uint32 m_uGreenShift;
uint32 m_uBlueShift;
uint32 m_uAlphaShift;
// The data type for the red, green, blue and alpha channels
EGIChannelType m_eColorType;
// Number of bits of the depth channel
uint32 m_uDepthBits;
// The data type for the depth channel
EGIChannelType m_eDepthType;
// Number of bits of the stencil channel
uint32 m_uStencilBits;
// The data type for the stencil channel
EGIChannelType m_eStencilType;
// Number of spare bits not used by the format layout
uint32 m_uSpareBits;
inline uint32 GetColorBits() const
{
return m_uRedBits + m_uGreenBits + m_uBlueBits + m_uAlphaBits;
}
inline uint32 GetDepthStencilBits() const
{
return m_uDepthBits + m_uStencilBits;
}
inline uint32 GetPixelBits() const
{
return GetColorBits() + GetDepthStencilBits() + m_uSpareBits;
}
inline uint32 GetPixelBytes() const
{
uint32 uPixelBits(GetPixelBits());
assert(uPixelBits % 8 == 0);
return uPixelBits >> 3;
}
};
// Identifies a set of swizzle modes for each color channel
typedef uint16 TSwizzleMask;
struct STextureFormat
{
// The OpenGL image format used to store textures internally
GLint m_iInternalFormat;
// The OpenGL image format used at application level for pixel data
GLenum m_eBaseFormat;
// Tells if the image data is compressed
bool m_bCompressed;
// Tells if the the format assumes data in sRGB space
bool m_bSRGB;
// Native OpenGL pixel data type (not meaningful if m_bCompressed is true)
GLenum m_eDataType;
// The size in pixels of a texture block (compression block if m_bCompressed is true, otherwise one pixel).
uint32 m_uBlockWidth;
uint32 m_uBlockHeight;
uint32 m_uBlockDepth;
// The size in bytes of a texture block (compression block if m_bCompressed is true, otherwise one pixel).
uint32 m_uNumBlockBytes;
};
// Identifies the possible format conversion procedures available
enum EGIFormatConversion
{
// A texture view is required to reinterpret the source format as the destination format
eGIFC_TEXTURE_VIEW,
// The depth channel of the source is mapped to the red channel of the destination
eGIFC_DEPTH_TO_RED,
// The stencil channel of the source is mapped to the red channel of the destination
eGIFC_STENCIL_TO_RED,
// The source format cannot be converted to the destination format
eGIFC_UNSUPPORTED,
// The source format can be used in place of the destination format without conversion
eGIFC_NONE
};
struct SGIFormatInfo
{
// Equivalent DXGI format
DXGI_FORMAT m_eDXGIFormat;
// Default supported usage mask for features/GL versions where support detection is not possible (union of D3D11_FORMAT_SUPPORT flags)
uint32 m_uDefaultSupport;
// Pointer to the texture information, or NULL if not a valid texture format
const STextureFormat* m_pTexture;
// Pointer to the uncompressed layout information, or NULL if compressed
const SUncompressedLayout* m_pUncompressed;
// Identifies the the compatible typeless format, or eGIF_NUM if no such format exists
EGIFormat m_eTypelessFormat;
// Describes how to convert to the compatible typeless format
EGIFormatConversion m_eTypelessConversion;
// The color channel swizzle modes required to map this format to the associated DXGI format
TSwizzleMask m_uDXGISwizzleMask;
};
extern const DXGI_FORMAT DXGI_FORMAT_INVALID;
// Finds the DXGI format corresponding to the given EGIFormat value.
// Returns DXGI_FORMAT_INVALID if the format was not found.
DXGI_FORMAT GetDXGIFormat(EGIFormat eGIFormat);
// Finds the DXGL EGIFormat value corresponding to the given DXGI_FORMAT.
// Returns eGIF_NUM if the given format is not supported.
EGIFormat GetGIFormat(DXGI_FORMAT eDXGIFormat);
// Gets the global format information for the given EGIFormat
const SGIFormatInfo* GetGIFormatInfo(EGIFormat eGIFormat);
// Converts a TSwizzleMask to red, green, blue and alpha texture swizzle modes
void SwizzleMaskToRGBA(TSwizzleMask uMask, GLint aiRGBA[4]);
// Converts a combination of red, green, blue and alpha texture swizzle modes to a TSwizzleMask
bool RGBAToSwizzleMask(const GLint aRGBA[4], TSwizzleMask& uMask);
// Tries to match a valid image format for a given EGIFormat value and returns true on success
bool GetImageFormat(EGIFormat eGIFormat, GLenum* peImageFormat);
};
#endif //__GLFORMAT__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,523 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Platform specific DXGL requirements implementation
#ifndef __GLPLATFORM__
#define __GLPLATFORM__
namespace NCryOpenGL
{
enum ELogSeverity
{
eLS_Info,
eLS_Warning,
eLS_Error
};
}
#define CUSTOM_SCOPED_PROFILE(_Name)
#if defined(OPENGL)
#include "GLCryPlatform.hpp"
#elif defined(WIN32)
#include "../Standalone/GLWinPlatform.hpp"
#elif defined(LINUX)
#include "../Standalone/GLLinuxPlatform.hpp"
#else
#error "Platform is not supported"
#endif
#define DXGL_PROFILING 0
#if defined(AZ_COMPILER_MSVC)
#define _DXGL_LOG_STRINGIFY_(x) #x
#define _DXGL_LOG_STRINGIFY(x) _DXGL_LOG_STRINGIFY_(x)
#define _DXGL_LOG_MSG(_TEXT, _FILE, _LINE, _FUNC) "DXGL: " _TEXT " : [@" _FUNC "] " _FILE "(" _LINE ")"
#define DXGL_LOG_MSG(_TEXT) _DXGL_LOG_MSG(_TEXT, __FILE__, _DXGL_LOG_STRINGIFY(__LINE__), __FUNCSIG__)
#else
#define _DXGL_LOG_MSG(_TEXT, _FILE, _FUNC) "DXGL: " _TEXT " : [@" _FUNC "] " _FILE "(%d)"
#define DXGL_LOG_MSG(_TEXT) _DXGL_LOG_MSG(_TEXT, __FILE__, "?") // GCC can't resolve __FUNCTION__ in the preprocessor
#endif
#if defined(_MSC_VER)
#define DXGL_WARNING(_Format, ...) NCryOpenGL::LogMessage(NCryOpenGL::eLS_Warning, DXGL_LOG_MSG(_Format), __VA_ARGS__)
#define DXGL_ERROR(_Format, ...) NCryOpenGL::LogMessage(NCryOpenGL::eLS_Error, DXGL_LOG_MSG(_Format), __VA_ARGS__)
#define DXGL_INFO(_Format, ...) NCryOpenGL::LogMessage(NCryOpenGL::eLS_Info, DXGL_LOG_MSG(_Format), __VA_ARGS__)
#else
#define DXGL_WARNING(_Format, ...) NCryOpenGL::LogMessage(NCryOpenGL::eLS_Warning, DXGL_LOG_MSG(_Format), ##__VA_ARGS__, __LINE__)
#define DXGL_ERROR(_Format, ...) NCryOpenGL::LogMessage(NCryOpenGL::eLS_Error, DXGL_LOG_MSG(_Format), ##__VA_ARGS__, __LINE__)
#define DXGL_INFO(_Format, ...) NCryOpenGL::LogMessage(NCryOpenGL::eLS_Info, DXGL_LOG_MSG(_Format), ##__VA_ARGS__, __LINE__)
#endif
#define DXGL_NOT_IMPLEMENTED NCryOpenGL::BreakUnique(__FILE__, __LINE__, __func__);
#define DXGL_TODO(_DESC)
#define DXGL_ARRAY_SIZE(_Array) (sizeof(_Array) / sizeof(_Array[0]))
#define _DXGL_QUOTE(X) #X
#define DXGL_QUOTE(X) _DXGL_QUOTE(X)
#define DXGL_CAT(_Left, _Right) _Left ## _Right
#define _DXGL_IF_0(...)
#define _DXGL_IF_1(...) __VA_ARGS__
#define DXGL_IF(_Condition) DXGL_CAT(_DXGL_IF_, _Condition)
#define DXGL_DECLARE_PTR(_Qualifier, _TypeName) \
_Qualifier _TypeName; \
typedef _smart_ptr<_TypeName> _TypeName ## Ptr;
#define DXGL_DECLARE_REF_COUNTED(_Qualifier, _TypeName) \
DXGL_DECLARE_PTR(_Qualifier, _TypeName) \
_Qualifier _TypeName: public NCryOpenGL::SRefCounted < _TypeName >
namespace NCryOpenGL
{
template <typename T>
struct SRefCounted
{
uint32 m_uRefCnt;
SRefCounted()
: m_uRefCnt(0)
{
}
void AddRef()
{
++m_uRefCnt;
}
void Release()
{
if (--m_uRefCnt == 0)
{
delete static_cast<T*>(this);
}
}
};
struct SSpinlockBitMaskWord
{
typedef LONG Word;
enum
{
BIT_SIZE = sizeof(Word) * 8
};
volatile Word m_aMask;
void Set(Word kNewValue)
{
Exchange(&m_aMask, kNewValue);
}
Word Get() const
{
return CompareExchange(const_cast<Word*>(&m_aMask), 0, 0);
}
bool Set(uint32 uIndex, bool bFlag)
{
while (true)
{
Word kOld(m_aMask);
Word uFlagMask(1 << uIndex);
Word kNew(bFlag ? (kOld | uFlagMask) : (kOld & ~uFlagMask));
if (CompareExchange(&m_aMask, kNew, kOld) == kOld)
{
return (kOld & uFlagMask) != 0;
}
}
}
bool Get(uint32 uIndex) const
{
assert(uIndex <= BIT_SIZE);
return ((m_aMask >> uIndex) & 1) != 0;
}
};
struct SUnsafeBitMaskWord
{
typedef uint32 Word;
enum
{
BIT_SIZE = sizeof(Word) * 8
};
Word m_aMask;
void Set(Word kNewValue)
{
m_aMask = kNewValue;
}
Word Get() const
{
return m_aMask;
}
bool Set(uint32 uIndex, bool bFlag)
{
assert(uIndex <= BIT_SIZE);
Word uFlagMask(1 << uIndex);
Word kOld(m_aMask);
m_aMask = bFlag ? (kOld | uFlagMask) : (kOld & ~uFlagMask);
return (kOld & uFlagMask) != 0;
}
bool Get(uint32 uIndex) const
{
assert(uIndex <= BIT_SIZE);
return ((m_aMask >> uIndex) & 1) != 0;
}
};
template <uint32 uNumWords, typename BitMaskWord>
struct SBitMaskMultiWord
{
typedef BitMaskWord Word;
Word m_akWords[uNumWords];
bool Set(uint32 uIndex, bool bFlag)
{
return m_akWords[uIndex / Word::BIT_SIZE].Set(uIndex % Word::BIT_SIZE, bFlag);
}
bool Get(uint32 uIndex) const
{
return m_akWords[uIndex / Word::BIT_SIZE].Get(uIndex % Word::BIT_SIZE);
}
};
template <uint32 uNumWords, typename BitMaskWord>
struct SBitMaskImpl
{
typedef SBitMaskMultiWord<uNumWords, BitMaskWord> Type;
typedef typename BitMaskWord::Word Word;
static void Init(Type* pMask, bool bValue, Word kUsedMask)
{
memset(pMask->m_akWords, bValue ? (Word) ~0 : (Word)0, sizeof(Word) * (uNumWords - 1));
pMask->m_akWords[uNumWords - 1].m_aMask = bValue ? kUsedMask : (Word)0;
}
static void SetZero(Type* pMask)
{
for (uint32 uPosition = 0; uPosition < uNumWords; ++uPosition)
{
pMask->m_akWords[uPosition].Set((Word)0);
}
}
static void SetOne(Type* pMask, Word kUsedMask)
{
for (uint32 uPosition = 0; uPosition < uNumWords - 1; ++uPosition)
{
pMask->m_akWords[uPosition].Set(~(Word)0);
}
pMask->m_akWords[uNumWords - 1].Set(kUsedMask);
}
static bool IsZero(Type* pMask, Word kUsedMask)
{
for (uint32 uPosition = 0; uPosition < uNumWords - 1; ++uPosition)
{
if (pMask->m_akWords[uPosition].Get() != (Word)0)
{
return false;
}
}
return (pMask->m_akWords[uNumWords - 1].Get() & kUsedMask) == (Word)0;
}
static bool IsOne(Type* pMask, Word kUsedMask)
{
for (uint32 uPosition = 0; uPosition < uNumWords - 1; ++uPosition)
{
if (pMask->m_akWords[uPosition].Get() != ~(Word)0)
{
return false;
}
}
return (pMask->m_akWords[uNumWords - 1].Get() & kUsedMask) == kUsedMask;
}
static void BitwiseOr(BitMaskWord* pResult, const BitMaskWord& kLeft, const BitMaskWord& kRight)
{
for (uint32 uIndex = 0; uIndex < uNumWords; ++uIndex)
{
pResult->m_akWords[uIndex].Set(kLeft.m_akWords[uIndex].Get() | kRight.m_akWords[uIndex].Get());
}
}
static void BitwiseAnd(BitMaskWord* pResult, const BitMaskWord& kLeft, const BitMaskWord& kRight)
{
for (uint32 uIndex = 0; uIndex < uNumWords; ++uIndex)
{
pResult->m_akWords[uIndex].Set(kLeft.m_akWords[uIndex].Get() & kRight.m_akWords[uIndex].Get());
}
}
static bool Equals(const BitMaskWord& kLeft, const BitMaskWord& kRight)
{
for (uint32 uIndex = 0; uIndex < uNumWords; ++uIndex)
{
if (kLeft.m_akWords[uIndex].Get() != kRight.m_akWords[uIndex].Get())
{
return false;
}
}
return true;
}
static void Copy(BitMaskWord* pDestination, const BitMaskWord& kSource)
{
for (uint32 uIndex = 0; uIndex < uNumWords; ++uIndex)
{
pDestination->m_akWords[uIndex].Set(kSource.m_akWords[uIndex].Get());
}
}
};
template <typename BitMaskWord>
struct SBitMaskImpl<1, BitMaskWord>
{
typedef BitMaskWord Type;
typedef typename BitMaskWord::Word Word;
static void Init(Type* pMask, bool bValue, Word kUsedMask)
{
pMask->m_aMask = bValue ? kUsedMask : (Word)0;
}
static void SetZero(Type* pMask)
{
pMask->Set((Word)0);
}
static void SetOne(Type* pMask, Word kUsedMask)
{
pMask->Set(kUsedMask);
}
static bool IsZero(const Type* pMask, Word kUsedMask)
{
return (pMask->Get() & kUsedMask) == (Word)0;
}
static bool IsOne(const Type* pMask, Word kUsedMask)
{
return (pMask->Get() & kUsedMask) == kUsedMask;
}
static void BitwiseOr(Type* pResult, const Type& kLeft, const Type& kRight)
{
pResult->Set(kLeft.Get() | kRight.Get());
}
static void BitwiseAnd(Type* pResult, const Type& kLeft, const Type& kRight)
{
pResult->Set(kLeft.Get() & kRight.Get());
}
static bool Equals(const Type& kLeft, const Type& kRight)
{
return kLeft.Get() == kRight.Get();
}
static void Copy(Type* pDestination, const Type& kSource)
{
pDestination->Set(kSource.Get());
}
};
template <uint32 uSize, typename BitMaskWord>
struct SBitMask
: SBitMaskImpl<(uSize + BitMaskWord::BIT_SIZE - 1) / BitMaskWord::BIT_SIZE, BitMaskWord>::Type
{
typedef SBitMaskImpl<(uSize + BitMaskWord::BIT_SIZE - 1) / BitMaskWord::BIT_SIZE, BitMaskWord> Impl;
typedef typename BitMaskWord::Word Word;
enum
{
USED_MASK = ~(~(Word)0 << uSize % BitMaskWord::BIT_SIZE)
};
// The following methods are not thread safe regardless of the BitMaskWord type
SBitMask(bool bInitValue = false)
{
Impl::Init(this, bInitValue, (Word)USED_MASK);
}
SBitMask(const SBitMask& kOther)
{
Impl::Copy(this, kOther);
}
void SetZero()
{
return Impl::SetZero(this);
}
void SetOne()
{
return Impl::SetOne(this, (Word)USED_MASK);
}
bool IsZero() const
{
return Impl::IsZero(this, (Word)USED_MASK);
}
bool IsOne() const
{
return Impl::IsOne(this, (Word)USED_MASK);
}
SBitMask& operator|=(const SBitMask& kOther)
{
Impl::BitwiseOr(this, *this, kOther);
return *this;
}
SBitMask& operator&=(const SBitMask& kOther)
{
Impl::BitwiseAnd(this, *this, kOther);
return *this;
}
SBitMask operator|(const SBitMask& kOther) const
{
SBitMask kResult;
Impl::BitwiseOr(&kResult, *this, kOther);
return kResult;
}
SBitMask operator&(const SBitMask& kOther) const
{
SBitMask kResult;
Impl::BitwiseAnd(&kResult, *this, kOther);
return kResult;
}
bool operator==(const SBitMask& kOther) const
{
return Impl::Equals(*this, kOther);
}
bool operator!=(const SBitMask& kOther) const
{
return !Impl::Equals(*this, kOther);
}
SBitMask& operator=(const SBitMask& kOther)
{
Impl::Copy(this, kOther);
return *this;
}
};
inline void* CreateTLS()
{
#if defined(WIN32)
return alias_cast<void*>(TlsAlloc());
#elif AZ_LEGACY_CRYCOMMON_TRAIT_USE_PTHREADS
pthread_key_t* pKey(new pthread_key_t());
pthread_key_create(pKey, NULL);
return alias_cast<void*>(pKey);
#else
#error "Not implemented on this platform"
#endif
}
inline void DestroyTLS(void* pTLSHandle)
{
#if defined(WIN32)
TlsFree(alias_cast<DWORD>(pTLSHandle));
#elif AZ_LEGACY_CRYCOMMON_TRAIT_USE_PTHREADS
pthread_key_t* pKey(alias_cast<pthread_key_t*>(pTLSHandle));
pthread_key_delete(*pKey);
#else
#error "Not implemented on this platform"
#endif
}
inline void* GetTLSValue(void* pTLSHandle)
{
#if defined(WIN32)
return TlsGetValue(alias_cast<DWORD>(pTLSHandle));
#elif AZ_LEGACY_CRYCOMMON_TRAIT_USE_PTHREADS
return pthread_getspecific(*alias_cast<pthread_key_t*>(pTLSHandle));
#else
#error "Not implemented on this platform"
#endif
}
inline void SetTLSValue(void* pTLSHandle, void* pValue)
{
#if defined(WIN32)
TlsSetValue(alias_cast<DWORD>(pTLSHandle), pValue);
#elif AZ_LEGACY_CRYCOMMON_TRAIT_USE_PTHREADS
pthread_setspecific(*alias_cast<pthread_key_t*>(pTLSHandle), pValue);
#else
#error "Not implemented on this platform"
#endif
}
struct SList
{
typedef SLockFreeSingleLinkedListHeader TListHeader;
typedef SLockFreeSingleLinkedListEntry TListEntry;
SList()
{
CryInitializeSListHead(m_kHeader);
}
void Push(TListEntry& kEntry)
{
CryInterlockedPushEntrySList(m_kHeader, kEntry);
}
TListEntry* Pop()
{
return alias_cast<TListEntry*>(CryInterlockedPopEntrySList(m_kHeader));
}
TListHeader m_kHeader;
};
struct SScopedProfileLabel
{
const char* m_szName;
SScopedProfileLabel(const char* szName)
: m_szName(szName)
{
PushProfileLabel(m_szName);
}
~SScopedProfileLabel()
{
PopProfileLabel(m_szName);
}
};
}
#if DXGL_PROFILING
#define DXGL_SCOPED_PROFILE(_Name) NCryOpenGL::SScopedProfileLabel kDXGLScopedProfileLabel(_Name);
#else
#define DXGL_SCOPED_PROFILE(_Name)
#endif
#endif //__GLPLATFORM__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,689 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declares the resource types and related functions
#ifndef __GLRESOURCE__
#define __GLRESOURCE__
#include "GLCommon.hpp"
#include "GLFormat.hpp"
#define DXGL_USE_PBO_FOR_STAGING_TEXTURES !DXGL_FULL_EMULATION
#define DXGL_SHARED_OBJECT_SYNCHRONIZATION 1
#define DXGL_STREAMING_CONSTANT_BUFFERS 1
namespace NCryOpenGL
{
class CDevice;
class CContext;
struct STextureUnitContext;
struct SSamplerState;
struct SShaderTextureViewConfiguration;
struct SShaderTextureBufferViewConfiguration;
struct SShaderImageViewConfiguration;
struct SOutputMergerTextureViewConfiguration;
DXGL_DECLARE_PTR(struct, SFrameBuffer);
DXGL_DECLARE_PTR(struct, SOutputMergerView);
DXGL_DECLARE_PTR(struct, SOutputMergerTextureView);
DXGL_DECLARE_PTR(struct, STexture);
DXGL_DECLARE_PTR(struct, SShaderView);
DXGL_DECLARE_PTR(struct, SShaderTextureBasedView);
DXGL_DECLARE_PTR(struct, SShaderTextureView);
DXGL_DECLARE_PTR(struct, SShaderTextureBufferView);
DXGL_DECLARE_PTR(struct, SShaderImageView);
DXGL_DECLARE_PTR(struct, SShaderBufferView);
DXGL_DECLARE_PTR(struct, SDefaultFrameBufferTexture);
DXGL_DECLARE_PTR(struct, SBuffer);
DXGL_DECLARE_PTR(struct, SQuery);
#if DXGL_STREAMING_CONSTANT_BUFFERS
DXGL_DECLARE_PTR(struct, SContextFrame)
#endif //DXGL_STREAMING_CONSTANT_BUFFERS
enum
{
MAX_NUM_CONTEXT_PER_DEVICE = 32
};
struct SFrameBufferConfiguration
{
enum
{
DEPTH_ATTACHMENT_INDEX = 0,
STENCIL_ATTACHMENT_INDEX = 1,
FIRST_COLOR_ATTACHMENT_INDEX = STENCIL_ATTACHMENT_INDEX + 1,
MAX_COLOR_ATTACHMENTS = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT,
MAX_ATTACHMENTS = FIRST_COLOR_ATTACHMENT_INDEX + MAX_COLOR_ATTACHMENTS
};
SOutputMergerView* m_akAttachments[MAX_ATTACHMENTS];
SFrameBufferConfiguration();
static GLenum AttachmentIndexToID(uint32 uIndex);
static uint32 AttachmentIDToIndex(GLenum eID);
};
struct SSharingFence
{
#if DXGL_SHARED_OBJECT_SYNCHRONIZATION
GLsync m_pFence;
SBitMask<MAX_NUM_CONTEXT_PER_DEVICE, SSpinlockBitMaskWord> m_akWaitIssued;
#endif //DXGL_SHARED_OBJECT_SYNCHRONIZATION
SSharingFence();
~SSharingFence();
void IssueFence(CDevice* pDevice, bool bAvoidFlushing = false);
void IssueWait(CContext* pContext);
};
struct SResourceNamePool;
struct UResourceNameSlot
{
SList::TListEntry m_kNextFree;
struct SUsed
{
GLuint m_uName;
UResourceNameSlot* m_pBlock;
volatile LONG m_uRefCount;
} m_kUsed;
};
struct SResourceNameBlockHeader
{
UResourceNameSlot* m_pNext;
SResourceNamePool* m_pPool;
volatile LONG m_uRefCount;
SList m_kFreeList;
uint32 m_uSize;
};
class CResourceName
{
public:
CResourceName();
CResourceName(UResourceNameSlot* pSlot);
CResourceName(const CResourceName& kOther);
~CResourceName();
CResourceName& operator=(const CResourceName& kOther);
bool operator==(const CResourceName& kOther) const;
bool operator!=(const CResourceName& kOther) const;
GLuint GetName() const;
bool IsValid() const;
protected:
void Acquire();
void Release();
UResourceNameSlot* m_pSlot;
};
struct SResourceNamePool
{
typedef UResourceNameSlot TSlot;
typedef SResourceNameBlockHeader TBlockHeader;
enum
{
MIN_BLOCK_SIZE = 256, GROWTH_FACTOR = 2, NUM_HEADER_SLOTS = (sizeof(TBlockHeader) + sizeof(TSlot) - 1) / sizeof(TSlot)
};
TSlot* m_pBlocksHead;
TCriticalSection m_kBlockSection;
SResourceNamePool();
~SResourceNamePool();
CResourceName Create(GLuint uName);
};
inline CResourceName::CResourceName()
: m_pSlot(NULL)
{
}
inline CResourceName::CResourceName(UResourceNameSlot* pSlot)
: m_pSlot(pSlot)
{
if (AtomicIncrement(&m_pSlot->m_kUsed.m_uRefCount) == 1)
{
AtomicIncrement(&alias_cast<SResourceNameBlockHeader*>(m_pSlot->m_kUsed.m_pBlock)->m_uRefCount);
}
}
inline CResourceName::CResourceName(const CResourceName& kOther)
: m_pSlot(kOther.m_pSlot)
{
Acquire();
}
inline CResourceName::~CResourceName()
{
Release();
}
inline CResourceName& CResourceName::operator=(const CResourceName& kOther)
{
Release();
m_pSlot = kOther.m_pSlot;
Acquire();
return *this;
}
inline bool CResourceName::operator==(const CResourceName& kOther) const
{
return m_pSlot == kOther.m_pSlot;
}
inline bool CResourceName::operator!=(const CResourceName& kOther) const
{
return !operator==(kOther);
}
inline void CResourceName::Acquire()
{
if (m_pSlot != NULL && AtomicIncrement(&m_pSlot->m_kUsed.m_uRefCount) == 1)
{
AtomicIncrement(&alias_cast<SResourceNameBlockHeader*>(m_pSlot->m_kUsed.m_pBlock)->m_uRefCount);
}
}
inline void CResourceName::Release()
{
if (m_pSlot != NULL && AtomicDecrement(&m_pSlot->m_kUsed.m_uRefCount) == 0)
{
SResourceNameBlockHeader* pBlockHeader(alias_cast<SResourceNameBlockHeader*>(m_pSlot->m_kUsed.m_pBlock));
if (AtomicDecrement(&pBlockHeader->m_uRefCount) == 0)
{
delete [] m_pSlot->m_kUsed.m_pBlock;
}
else
{
pBlockHeader->m_kFreeList.Push(m_pSlot->m_kNextFree);
}
}
}
inline GLuint CResourceName::GetName() const
{
return m_pSlot == NULL ? 0 : m_pSlot->m_kUsed.m_uName;
}
inline bool CResourceName::IsValid() const
{
return m_pSlot != NULL;
}
DXGL_DECLARE_REF_COUNTED(struct, SResource)
{
typedef void (* UpdateSubresourceFunc) (SResource* pResource, uint32 uSubresource, const D3D11_BOX* pDstBox, const void* pSrcData, uint32 uSrcRowPitch, uint32 uSrcDepthPitch, CContext* pContext);
typedef bool (* MapSubresourceFunc) (SResource* pResource, uint32 uSubresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource, CContext* pContext);
typedef void (* UnmapSubresourceFunc) (SResource* pResource, uint32 uSubresource, CContext* pContext);
CResourceName m_kName;
UpdateSubresourceFunc m_pfUpdateSubresource;
MapSubresourceFunc m_pfMapSubresource;
UnmapSubresourceFunc m_pfUnmapSubresource;
SSharingFence m_kCreationFence;
SResource();
SResource(const SResource&kOther);
virtual ~SResource();
};
struct SFrameBufferObject
{
typedef SBitMask<SFrameBufferConfiguration::MAX_COLOR_ATTACHMENTS, SUnsafeBitMaskWord> TColorAttachmentMask;
CResourceName m_kName;
bool m_bUsesSRGB;
TColorAttachmentMask m_kDrawMaskCache;
SFrameBufferObject();
~SFrameBufferObject();
};
void InitializeCryGlFramebufferFunctions();
DXGL_DECLARE_REF_COUNTED(struct, SFrameBuffer)
{
SFrameBufferConfiguration m_kConfiguration;
SFrameBufferObject m_kObject;
CContext* m_pContext;
// Specification of the list of color attachments that are enabled for writing
GLenum m_aeDrawBuffers[SFrameBufferConfiguration::MAX_COLOR_ATTACHMENTS];
GLuint m_uNumDrawBuffers;
SFrameBufferObject::TColorAttachmentMask m_kDrawMask;
SFrameBuffer(const SFrameBufferConfiguration&kConfiguration);
~SFrameBuffer();
bool Validate();
};
struct SMappedSubTexture
{
uint8* m_pBuffer;
uint32 m_uDataOffset;
bool m_bUpload;
uint32 m_uRowPitch;
uint32 m_uImagePitch;
SMappedSubTexture()
: m_pBuffer(NULL)
{
}
};
struct STextureUnitCache;
struct STextureState
{
GLint m_iBaseMipLevel;
GLint m_iMaxMipLevel;
#if DXGL_SUPPORT_STENCIL_TEXTURES
GLint m_iDepthStencilTextureMode; // 0 if not used
#endif //DXGL_SUPPORT_STENCIL_TEXTURES
TSwizzleMask m_uSwizzleMask;
void ApplyFormatMode(GLuint uTexture, GLenum eTarget);
void ApplyFormatMode(GLenum eTarget);
void Apply(GLuint uTexture, GLenum eTarget, const STextureUnitCache& kCurrentUnitCache);
bool operator==(const STextureState& kOther) const
{
return
m_iBaseMipLevel == kOther.m_iBaseMipLevel &&
m_iMaxMipLevel == kOther.m_iMaxMipLevel &&
#if DXGL_SUPPORT_STENCIL_TEXTURES
m_iDepthStencilTextureMode == kOther.m_iDepthStencilTextureMode &&
#endif //DXGL_SUPPORT_STENCIL_TEXTURES
m_uSwizzleMask == kOther.m_uSwizzleMask;
}
bool operator!=(const STextureState& kOther) const
{
return !operator==(kOther);
}
};
template <typename T>
struct STexVec
{
T x, y, z;
STexVec() {}
STexVec(T kX, T kY, T kZ)
: x(kX)
, y(kY)
, z(kZ) {}
};
typedef STexVec<GLsizei> STexSize;
typedef STexVec<GLint> STexPos;
struct STexSubresourceID
{
GLint m_iMipLevel;
uint32 m_uElement;
};
enum EBufferBinding
{
eBB_Array,
eBB_CopyRead,
eBB_CopyWrite,
#if DXGL_SUPPORT_DRAW_INDIRECT
eBB_DrawIndirect,
#endif //DXGL_SUPPORT_DRAW_INDIRECT
eBB_ElementArray,
eBB_PixelPack,
eBB_PixelUnpack,
eBB_TransformFeedback,
eBB_UniformBuffer,
#if DXGL_SUPPORT_ATOMIC_COUNTERS
eBB_AtomicCounter,
#endif //DXGL_SUPPORT_ATOMIC_COUNTERS
#if DXGL_SUPPORT_DISPATCH_INDIRECT
eBB_DispachIndirect,
#endif //DXGL_SUPPORT_DISPATCH_INDIRECT
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
eBB_ShaderStorage,
#endif //DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
eBB_NUM
};
struct SBufferRange
{
uint32 m_uOffset;
uint32 m_uSize;
SBufferRange(uint32 uOffset = 0, uint32 uSize = 0)
: m_uOffset(uOffset)
, m_uSize(uSize)
{
}
bool operator==(const SBufferRange& kOther) const
{
return
m_uOffset == kOther.m_uOffset &&
m_uSize == kOther.m_uSize;
}
bool operator!=(const SBufferRange& kOther) const
{
return !operator==(kOther);
}
};
//#define DXGL_USE_LAZY_CLEAR
struct STexture
: SResource
{
STexture(GLsizei iWidth, GLsizei iHeight, GLsizei iDepth, GLenum eTarget, EGIFormat eFormat, uint32 uNumMipLevels, uint32 uNumElements);
virtual ~STexture();
virtual SShaderTextureViewPtr CreateShaderResourceView(const SShaderTextureViewConfiguration& kConfiguration, CContext* pContext);
virtual SShaderImageViewPtr CreateUnorderedAccessView(const SShaderImageViewConfiguration& kConfiguration, CContext* pContext);
virtual SOutputMergerTextureViewPtr CreateOutputMergerView(const SOutputMergerTextureViewConfiguration& kConfiguration, CContext* pContext);
SOutputMergerTextureViewPtr GetCompatibleOutputMergerView(const SOutputMergerTextureViewConfiguration& kConfiguration, CContext* pContext);
virtual void OnCopyRead(CContext* pContext) {};
virtual void OnCopyWrite(CContext* pContext) {};
void SetMinLod(float minLod);
float GetMinLod() const { return m_fMinLod; }
#if defined(ANDROID)
void ResetDontCareActionFlags();
void UpdateDontCareActionFlagsOnBound();
void UpdateDontCareActionFlagsOnUnbound();
#endif
typedef std::vector<SMappedSubTexture> TMappedSubTextures;
typedef std::vector<SOutputMergerTextureViewPtr> TCopySubTextureViews;
GLsizei m_iWidth, m_iHeight, m_iDepth;
GLenum m_eTarget;
EGIFormat m_eFormat;
uint32 m_uNumMipLevels;
uint32 m_uNumElements; // array_size * number_of_faces
// Texture view used for glCopyImageSubData if the driver requires a custom view for that, texture name otherwise
CResourceName m_kCopyImageView;
GLenum m_eCopyImageTarget;
typedef void(*TransferDataFunc) (STexture* pTexture, STexSubresourceID kSubID, STexPos kOffset, STexSize kSize, const SMappedSubTexture& kDataLocation, CContext* pContext);
typedef uint32(*LocatePackedDataFunc) (STexture* pTexture, STexSubresourceID kSubID, STexPos kOffset, SMappedSubTexture& kDataLocation);
TransferDataFunc m_pfUnpackData;
TransferDataFunc m_pfPackData;
LocatePackedDataFunc m_pfLocatePackedDataFunc;
#if DXGL_USE_PBO_FOR_STAGING_TEXTURES
CResourceName* m_akPixelBuffers; // Only used for staging textures
#else
uint8* m_pSystemMemoryCopy; // Only used for staging textures
#endif
TMappedSubTextures m_kMappedSubTextures;
TCopySubTextureViews m_kCopySubTextureViews;
STextureState m_kCache;
SShaderTextureView* m_pShaderViewsHead;
SOutputMergerTextureView* m_pOutputMergerViewsHead;
SShaderTextureView* m_pBoundModifier; // NULL if no SRV for this texture has bound custom texture parameters
#if defined(DXGL_USE_LAZY_CLEAR)
float m_ClearColor[4];
_smart_ptr<SOutputMergerView> m_spViewToClear;
float m_fClearDepthValue;
bool m_bClearDepth;
bool m_bClearStencil;
uint8 m_uClearStencilValue;
#endif
#if defined(ANDROID)
bool m_bColorLoadDontCare;
bool m_bDepthLoadDontCare;
bool m_bStencilLoadDontCare;
bool m_bColorStoreDontCare;
bool m_bDepthStoreDontCare;
bool m_bStencilStoreDontCare;
bool m_bColorStoreDontCareWhenUnbound;
bool m_bDepthStoreDontCareWhenUnbound;
bool m_bStencilStoreDontCareWhenUnbound;
bool m_bColorWasInvalidatedWhenUnbound;
bool m_bDepthWasInvalidatedWhenUnbound;
bool m_bStencilWasInvalidatedWhenUnbound;
#endif
private:
// Making this private so that users have to use the Set/Get since there
// is a corresponding gl call that needs to be called when this variable
// is set.
GLfloat m_fMinLod;
};
#if DXGL_SUPPORT_APITRACE
struct SDynamicBufferCopy
{
uint8* m_pData;
uint32 m_uSize;
#if defined(WIN32)
void** m_apDirtyPages;
uint32 m_uNumPages;
static uint32 ms_uPageSize;
#endif //defined(WIN32)
SDynamicBufferCopy();
~SDynamicBufferCopy();
uint8* Allocate(uint32 uSize);
void Free();
void ResetDirtyRegion();
bool GetDirtyRegion(uint32& uOffset, uint32& uSize);
};
#endif //DXGL_SUPPORT_APITRACE
struct SBuffer
: SResource
{
SBuffer();
virtual ~SBuffer();
SShaderViewPtr CreateShaderResourceView(EGIFormat eFormat, uint32 uFirstElement, uint32 uNumElements, uint32 uFlags, CContext* pContext);
SShaderViewPtr CreateUnorderedAccessView(EGIFormat eFormat, uint32 uFirstElement, uint32 uNumElements, uint32 uFlags, CContext* pContext);
SShaderTextureBufferViewPtr GetTextureBuffer(SShaderTextureBufferViewConfiguration& kConfiguration, CContext* pContext);
SShaderBufferViewPtr CreateBufferView(uint32 uFirstElement, uint32 uNumElements, CContext* pContext);
typedef bool (* MapBufferRangeFunc) (SBuffer* pBuffer, size_t uOffset, size_t uSize, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource, CContext* pContext);
MapBufferRangeFunc m_pfMapBufferRange;
SBitMask<eBB_NUM, SUnsafeBitMaskWord> m_kBindings;
GLenum m_eUsage;
uint32 m_uSize;
uint32 m_uElementSize; // 0 if not structured
uint8* m_pSystemMemoryCopy;
bool m_bMapped;
size_t m_uMapOffset;
size_t m_uMapSize;
SShaderTextureBufferView* m_pTextureBuffersHead;
#if DXGL_SUPPORT_APITRACE
SDynamicBufferCopy m_kDynamicCopy;
bool m_bSystemMemoryCopyOwner;
#endif //DXGL_SUPPORT_APITRACE
#if DXGL_STREAMING_CONSTANT_BUFFERS
struct SContextCache
{
SContextFramePtr m_spFrame;
SBufferRange m_kRange;
uint32 m_uUnit;
uint32 m_uStreamOffset;
} m_akContextCaches[MAX_NUM_CONTEXT_PER_DEVICE];
DXGL_TODO("Evaluate if it is worth to have multiple possible bindings cached - eventually add another dimension and keep items sorted by slot for binary search");
SBitMask<MAX_NUM_CONTEXT_PER_DEVICE, SSpinlockBitMaskWord> m_kContextCachesValid;
bool m_bStreaming;
#endif //DXGL_STREAMING_CONSTANT_BUFFERS
};
DXGL_DECLARE_REF_COUNTED(struct, SQuery)
{
virtual ~SQuery();
virtual void Begin();
virtual void End();
virtual bool GetData(void* pData, uint32 uDataSize, bool bFlush) = 0;
virtual uint32 GetDataSize();
};
struct SPlainQuery
: SQuery
{
SPlainQuery(GLenum eTarget);
virtual ~SPlainQuery();
virtual void Begin();
virtual void End();
GLuint m_uName;
GLenum m_eTarget;
bool m_bBegun;
};
struct SOcclusionQuery
: SPlainQuery
{
SOcclusionQuery();
virtual bool GetData(void* pData, uint32 uDataSize, bool bFlush);
virtual uint32 GetDataSize();
};
struct SFenceSync
: SQuery
{
SFenceSync();
virtual ~SFenceSync();
virtual void End();
virtual bool GetData(void* pData, uint32 uDataSize, bool bFlush);
virtual uint32 GetDataSize();
GLsync m_pFence;
};
#if DXGL_SUPPORT_TIMER_QUERIES
struct STimestampDisjointQuery
: SQuery
{
virtual bool GetData(void* pData, uint32 uDataSize, bool bFlush);
virtual uint32 GetDataSize();
};
struct STimestampQuery
: SQuery
{
STimestampQuery();
virtual ~STimestampQuery();
virtual void End();
virtual bool GetData(void* pData, uint32 uDataSize, bool bFlush);
virtual uint32 GetDataSize();
GLuint m_uName;
};
#endif //DXGL_SUPPORT_TIMER_QUERIES
struct SDefaultFrameBufferTexture
: STexture
{
SDefaultFrameBufferTexture(GLsizei iWidth, GLsizei iHeight, EGIFormat eFormat, GLbitfield eBufferMask);
virtual ~SDefaultFrameBufferTexture();
virtual SShaderTextureViewPtr CreateShaderResourceView(const SShaderTextureViewConfiguration& kConfiguration, CContext* pContext);
virtual SShaderImageViewPtr CreateUnorderedAccessView(const SShaderImageViewConfiguration& kConfiguration, CContext* pContext);
virtual SOutputMergerTextureViewPtr CreateOutputMergerView(const SOutputMergerTextureViewConfiguration& kConfiguration, CContext* pContext);
virtual void OnCopyRead(CContext* pContext);
virtual void OnCopyWrite(CContext* pContext);
void IncTextureRefCount(CContext* pContext);
void DecTextureRefCount();
void EnsureTextureExists(CContext* pContext);
void ReleaseTexture();
void OnWrite(CContext* pContext, bool bDefaultFrameBuffer);
void OnRead(CContext* pContext);
void Flush(CContext* pContext);
#if DXGL_FULL_EMULATION
void SetCustomWindowContext(const TWindowContext& kCustomWindowContext);
#endif //DXGL_FULL_EMULATION
static void UpdateSubresource(SResource* pResource, uint32 uSubresource, const D3D11_BOX* pDstBox, const void* pSrcData, uint32 uSrcRowPitch, uint32 uSrcDepthPitch, CContext* pContext);
static bool MapSubresource(SResource* pResource, uint32 uSubresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource, CContext* pContext);
static void UnmapSubresource(SResource* pResource, uint32 uSubresource, CContext* pContext);
static void UnpackData(STexture* pTexture, STexSubresourceID kSubID, STexPos kOffset, STexSize kSize, const SMappedSubTexture& kDataLocation, CContext* pContext);
static void PackData(STexture* pTexture, STexSubresourceID kSubID, STexPos kOffset, STexSize kSize, const SMappedSubTexture& kDataLocation, CContext* pContext);
static uint32 LocatePackedData(STexture* pTexture, STexSubresourceID kSubID, STexPos kOffset, SMappedSubTexture& kDataLocation);
uint32 m_uTextureRefCount;
SFrameBufferObject m_kInputFBO;
SFrameBufferObject m_kDefaultFBO;
GLbitfield m_uBufferMask;
GLenum m_eInputColorBuffer, m_eOutputColorBuffer;
GLsizei m_iDefaultFBOWidth, m_iDefaultFBOHeight;
bool m_bInputDirty, m_bOutputDirty;
SShaderTextureViewPtr m_kInputFBOColorTextureView;
#if DXGL_FULL_EMULATION
TWindowContext m_kCustomWindowContext;
#endif //DXGL_FULL_EMULATION
};
STexturePtr CreateTexture1D(const D3D11_TEXTURE1D_DESC& kDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, CContext* pContext);
STexturePtr CreateTexture2D(const D3D11_TEXTURE2D_DESC& kDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, CContext* pContext);
STexturePtr CreateTexture3D(const D3D11_TEXTURE3D_DESC& kDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, CContext* pContext);
SBufferPtr CreateBuffer(const D3D11_BUFFER_DESC& kDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, CContext* pContext);
SQueryPtr CreateQuery(const D3D11_QUERY_DESC& kDesc, CContext* pContext);
SDefaultFrameBufferTexturePtr CreateBackBufferTexture(const D3D11_TEXTURE2D_DESC& kDesc);
CResourceName CreateTextureView(STexture* pTexture, const SGIFormatInfo* pFormatInfo, GLenum eTarget, GLuint uMinMipLevel, GLuint uNumMipLevels, GLuint uMinLayer, GLuint uNumLayers, CContext* pContext);
GLenum GetBufferBindingTarget(EBufferBinding eBinding);
GLenum GetBufferBindingPoint(EBufferBinding eBinding);
void CopyTexture(STexture* pDstTexture, STexture* pSrcTexture, CContext* pContext);
void CopyBuffer(SBuffer* pDstBuffer, SBuffer* pSrcBuffer, CContext* pContext);
void CopySubTexture(STexture* pDstTexture, uint32 uDstSubresource, uint32 uDstX, uint32 uDstY, uint32 uDstZ, STexture* pSrcTexture, uint32 uSrcSubresource, const D3D11_BOX* pSrcBox, CContext* pContext);
void CopySubBuffer(SBuffer* pDstBuffer, uint32 uDstSubresource, uint32 uDstX, uint32 uDstY, uint32 uDstZ, SBuffer* pSrcBuffer, uint32 uSrcSubresource, const D3D11_BOX* pSrcBox, CContext* pContext);
}
#endif //__GLRESOURCE__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,453 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declares the shader types and related functions
#ifndef __GLSHADER__
#define __GLSHADER__
#include "GLCommon.hpp"
#if !DXGL_INPUT_GLSL && DXGL_GLSL_FROM_HLSLCROSSCOMPILER
#include "hlslcc.hpp"
#endif //!DXGL_INPUT_GLSL && DXGL_GLSL_FROM_HLSLCROSSCOMPILER
#if DXGL_GLSL_FROM_HLSLCROSSCOMPILER && !DXGL_INPUT_GLSL && DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
#define DXGL_ENABLE_SHADER_TRACING 1
#else
#define DXGL_ENABLE_SHADER_TRACING 0
#endif
#if DXGL_GLSL_FROM_HLSLCROSSCOMPILER && !DXGL_INPUT_GLSL
#define DXGL_HLSL_TO_GLSL_DEBUG 1
#else
#define DXGL_HLSL_TO_GLSL_DEBUG 0
#endif
#define DXGL_DUMP_GLSL_SOURCES 0
#define DXGL_SHADER_TYPE_MAP(_Predicate, _Vertex, _Fragment, _Geometry, _TessControl, _TessEvaluation, _Compute) \
_Predicate(_Vertex) _Predicate(_Fragment) \
DXGL_IF(DXGL_ENABLE_GEOMETRY_SHADERS)(_Predicate(_Geometry)) \
DXGL_IF(DXGL_ENABLE_TESSELLATION_SHADERS)(_Predicate(_TessControl) _Predicate(_TessEvaluation)) \
DXGL_IF(DXGL_ENABLE_COMPUTE_SHADERS)(_Predicate(_Compute)) \
namespace NCryOpenGL
{
class CDevice;
enum EShaderType
{
#define _ENUM(_Name) _Name,
DXGL_SHADER_TYPE_MAP(_ENUM, eST_Vertex, eST_Fragment, eST_Geometry, eST_TessControl, eST_TessEvaluation, eST_Compute)
#undef _ENUM
eST_NUM
};
enum EPipelineMode
{
ePM_Graphics,
ePM_Compute
};
enum EShaderVersion
{
eSV_Normal = 0,
#if DXGL_ENABLE_SHADER_TRACING
eSV_Tracing,
#endif //DXGL_ENABLE_SHADER_TRACING
eSV_NUM
};
enum EResourceUnitType
{
eRUT_Texture,
eRUT_UniformBuffer,
#if DXGL_SUPPORT_SHADER_STORAGE_BLOCKS
eRUT_StorageBuffer,
#endif
#if DXGL_SUPPORT_SHADER_IMAGES
eRUT_Image,
#endif
eRUT_NUM
};
struct SPipeline;
class CContext;
struct SSource
{
const char* m_pData;
uint32 m_uDataSize;
SSource(const char* pData = NULL, uint32 uDataSize = 0);
~SSource();
};
#if DXGL_ENABLE_SHADER_TRACING
struct SShaderTraceIndex
{
std::vector<uint32> m_kTraceStepSizes;
std::vector<uint32> m_kTraceStepOffsets;
std::vector<VariableTraceInfo> m_kTraceVariables;
};
#endif //DXGL_ENABLE_SHADER_TRACING
struct SShaderSource
: SSource
{
SShaderSource();
~SShaderSource();
void SetData(const char* pData = NULL, uint32 uDataSize = 0);
};
enum
{
DXGL_MAX_REFLECT_STRING_LENGTH = 128
};
struct SShaderReflectionVariable
{
D3D11_SHADER_VARIABLE_DESC m_kDesc;
D3D11_SHADER_TYPE_DESC m_kType;
char m_acName[DXGL_MAX_REFLECT_STRING_LENGTH];
std::vector<uint8> m_kDefaultValue;
};
struct SShaderReflectionConstBuffer
{
typedef std::vector<SShaderReflectionVariable> TVariables;
TVariables m_kVariables;
D3D11_SHADER_BUFFER_DESC m_kDesc;
char m_acName[DXGL_MAX_REFLECT_STRING_LENGTH];
};
struct SShaderReflectionResource
{
D3D11_SHADER_INPUT_BIND_DESC m_kDesc;
char m_acName[DXGL_MAX_REFLECT_STRING_LENGTH];
};
struct SShaderReflectionParameter
{
D3D11_SIGNATURE_PARAMETER_DESC m_kDesc;
char m_acSemanticName[DXGL_MAX_REFLECT_STRING_LENGTH];
};
struct SShaderReflection
{
typedef std::vector<SShaderReflectionConstBuffer> TConstantBuffers;
typedef std::vector<SShaderReflectionResource> TResources;
typedef std::vector<SShaderReflectionParameter> TParameters;
SShaderReflection()
: m_uGLSLSourceOffset(0)
, m_uSamplersOffset(0)
, m_uNumSamplers(0)
, m_uImagesOffset(0)
, m_uNumImages(0)
, m_uStorageBuffersOffset(0)
, m_uNumStorageBuffers(0)
, m_uUniformBuffersOffset(0)
, m_uNumUniformBuffers(0)
, m_uImportsOffset(0)
, m_uImportsSize(0)
, m_uExportsOffset(0)
, m_uExportsSize(0)
, m_uInputHash(0)
, m_uSymbolsOffset(0)
{}
uint32 m_uGLSLSourceOffset;
uint32 m_uSamplersOffset;
uint32 m_uNumSamplers;
uint32 m_uImagesOffset;
uint32 m_uNumImages;
uint32 m_uStorageBuffersOffset;
uint32 m_uNumStorageBuffers;
uint32 m_uUniformBuffersOffset;
uint32 m_uNumUniformBuffers;
uint32 m_uImportsOffset;
uint32 m_uImportsSize;
uint32 m_uExportsOffset;
uint32 m_uExportsSize;
uint32 m_uInputHash;
uint32 m_uSymbolsOffset;
TConstantBuffers m_kConstantBuffers;
TResources m_kResources;
TParameters m_kInputs, m_kOutputs, m_kPatchConstants;
D3D11_SHADER_DESC m_kDesc;
};
struct SGLShader
{
GLuint m_uName; // Name of the shader program if eF_SeparablePrograms is supported, name of the shader otherwise
bool m_separableProgramsSupported; // True if the device supports separable programs and we need to call glDeleteProgram instead of glDeleteShader
SGLShader();
~SGLShader();
};
DXGL_DECLARE_REF_COUNTED(struct, SShader)
{
EShaderType m_eType;
struct SVersion
{
SShaderSource m_kSource;
SShaderReflection m_kReflection;
} m_akVersions[eSV_NUM];
#if DXGL_ENABLE_SHADER_TRACING
SShaderTraceIndex m_kTraceIndex;
#endif //DXGL_ENABLE_SHADER_TRACING
typedef std::vector<SPipeline*> TPipelines;
TPipelines m_kBoundPipelines;
void AttachPipeline(SPipeline * pPipeline);
void DetachPipeline(SPipeline * pPipeline);
SShader();
~SShader();
};
struct SPipelineConfiguration
{
SShader* m_apShaders[eST_NUM];
#if DXGL_ENABLE_SHADER_TRACING
EShaderVersion m_aeShaderVersions[eST_NUM];
#endif //DXGL_ENABLE_SHADER_TRACING
EPipelineMode m_eMode;
#if !DXGL_SUPPORT_DEPTH_CLAMP
bool m_bEmulateDepthClamp;
#endif //!DXGL_SUPPORT_DEPTH_CLAMP
SPipelineConfiguration();
};
struct SPipelineCompilationBuffer
{
enum
{
VERSION_STRING_CAPACITY = 32
};
GLchar* m_acImportsHeader;
uint32 m_uImportsBeginOffset;
uint32 m_uImportsEndOffset;
uint32 m_uImportsHeaderCapacity;
GLchar m_acVersionString[VERSION_STRING_CAPACITY];
GLint m_iVersionStringLength;
SPipelineCompilationBuffer();
~SPipelineCompilationBuffer();
};
struct SIndexPartitionRange
{
enum
{
INVALID_INDEX = 0xFFFFFFFFu
};
uint32 m_uFirstIn;
uint32 m_uFirstOut;
uint32 m_uCount;
uint32 operator()(uint32 uSlot) const { return uSlot < m_uFirstIn || uSlot >= m_uFirstIn + m_uCount ? INVALID_INDEX : m_uFirstOut + uSlot - m_uFirstIn; }
};
struct SIndexPartition
{
SIndexPartitionRange m_akStages[eST_NUM];
SIndexPartitionRange& operator[](EShaderType eType){ return m_akStages[eType]; };
SIndexPartitionRange operator[](EShaderType eType) const { return m_akStages[eType]; };
};
DXGL_DECLARE_REF_COUNTED(struct, SUnitMap)
{
enum
{
MAX_TEXTURE_SLOT_IN_MAP = 0x400,
MAX_SAMPLER_SLOT_IN_MAP = 0x400,
MAX_TEXTURE_UNIT_IN_MAP = 0x400,
};
struct SElement
{
uint32 m_uMask;
// For non-texture unit maps
uint32 GetResourceSlot() const { return m_uMask >> 16; }
uint32 GetResourceUnit() const { return m_uMask & 0xFFFF; }
static SElement Resource(uint32 uSlot, uint32 uUnit)
{
SElement kElement = { uSlot << 16 | uUnit };
return kElement;
}
// For texture unit maps
uint32 GetTextureSlot() const { return m_uMask >> 22; }
uint32 GetSamplerSlot() const { return (m_uMask >> 12) & 0x3FF; }
uint32 GetTextureUnit() const { return (m_uMask >> 2) & 0x3FF; }
bool HasSampler() const { return ((m_uMask >> 1) & 0x1) == 1; }
static SElement TextureWithoutSampler(uint32 uTextureSlot, uint32 uTextureUnit)
{
SElement kElement = { uTextureSlot << 22 | uTextureUnit << 2 };
return kElement;
}
static SElement TextureWithSampler(uint32 uTextureSlot, uint32 uSamplerSlot, uint32 uTextureUnit)
{
SElement kElement = { uTextureSlot << 22 | uSamplerSlot << 12 | uTextureUnit << 2 | 1 << 1 };
return kElement;
}
};
SElement* m_akUnits;
uint16 m_uNumUnits;
SUnitMap(uint16 uNumUnits = 0);
SUnitMap(const SUnitMap&kOther);
~SUnitMap();
};
DXGL_DECLARE_REF_COUNTED(struct, SPipeline)
{
GLuint m_uName; // Name of the pipeline if eF_SeparablePrograms is supported, name of the program otherwise
SGLShader m_akGLShaders[eST_NUM];
CContext* m_pContext;
SPipelineConfiguration m_kConfiguration;
SUnitMapPtr m_aspResourceUnitMaps[eRUT_NUM];
#if DXGL_ENABLE_SHADER_TRACING
uint32 m_uTraceBufferUnit;
#endif //DXGL_ENABLE_SHADER_TRACING
SPipeline(const SPipelineConfiguration&kConfiguration, CContext * pContext);
~SPipeline();
};
DXGL_DECLARE_REF_COUNTED(struct, SInputLayout)
{
// Parameters taken by glVertexAttribPointer (excluding stride and pointer base that are part of the vertex buffer data)
struct SAttributeParameters
{
GLuint m_uAttributeIndex;
GLint m_iDimension;
GLenum m_eType;
GLboolean m_bNormalized;
GLuint m_uPointerOffset;
GLuint m_uVertexAttribDivisor;
bool m_bInteger;
};
// Interleaved vertex attributes for a specific input assembler slot
typedef std::vector<SAttributeParameters> TAttributes;
// Vertex attributes for each input assembler slot
TAttributes m_akSlotAttributes[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
#if DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
// for vertex_attrib_binding we need the binding slot in addition to the other data
struct SAttributeFormats
: SAttributeParameters
{
GLuint m_uBindingIndex;
};
typedef std::vector<SAttributeFormats> TAttributeFormats;
TAttributeFormats m_akVertexAttribFormats;
#endif //DXGL_SUPPORT_VERTEX_ATTRIB_BINDING
};
namespace DXBC
{
const uint32 TextureIndexEncodeShift = 22;
const uint32 SamplerIndexEncodeShift = 12;
const uint32 TextureUnitEncodeShift = 2;
const uint32 NormalSampleEncodeShift = 1;
const uint32 EmbeddedNameEncodeShift = 12;
const uint32 EncodeMask = 0x3FF;
const uint32 EncodeSampleModeMask = 0x1;
template <size_t uSize>
bool GetEmbeddedName(char(&acBuffer)[uSize], const char* szGLSL, uint32 uNameMask)
{
uint32 uNameOffset = uNameMask >> EmbeddedNameEncodeShift;
uint32 uNameSize = uNameMask & EncodeMask;
if (uNameSize + 1 >= uSize)
{
DXGL_ERROR("Embedded name is too big");
return false;
}
memcpy(acBuffer, szGLSL + uNameOffset, uNameSize);
acBuffer[uNameSize] = '\0';
return true;
}
inline uint32 DecodeTextureIndex(uint32 uSamplerField) { return uSamplerField >> TextureIndexEncodeShift; }
inline uint32 DecodeSamplerIndex(uint32 uSamplerField) { return (uSamplerField >> SamplerIndexEncodeShift) & EncodeMask; }
inline uint32 DecodeTextureUnitIndex(uint32 uSamplerField) { return (uSamplerField >> TextureUnitEncodeShift) & EncodeMask; }
inline bool DecodeNormalSample(uint32 uSamplerField) { return ((uSamplerField >> NormalSampleEncodeShift) & EncodeSampleModeMask) == 1; }
inline bool DecodeCompareSample(uint32 uSamplerField) { return (uSamplerField & 0x1) == 1; }
inline uint32 DecodeResourceIndex(uint32 uResourceField) { return uResourceField; }
inline uint32 EncodeEmbeddedName(uint32 uNameOffset, uint32 uNameSize) { return uNameOffset << EmbeddedNameEncodeShift | uNameSize & EncodeMask; }
inline uint32 EncodeTextureData(uint32 uTextureIndex, uint32 uSamplerIndex, uint32 uTextureUnitIndex, bool bNormalSample, bool bCompareSample)
{
return uTextureIndex << TextureIndexEncodeShift |
(uSamplerIndex & EncodeSampleModeMask) << SamplerIndexEncodeShift |
(uTextureUnitIndex & EncodeSampleModeMask) << TextureUnitEncodeShift |
((static_cast<uint32>(bNormalSample) & EncodeSampleModeMask) << NormalSampleEncodeShift) |
static_cast<uint32>(bCompareSample);
}
inline uint32 EncodeResourceIndex(uint32 uResourceField) { return uResourceField; }
}
typedef SShaderReflection TShaderReflection;
bool InitializeShaderReflectionFromInput(SShaderReflection* pReflection, const void* pvData);
bool CompileShader(SShader* pShader, SSource* aSourceVersions, SGLShader* pGLShader);
bool CompilePipeline(SPipeline* pPipeline, SPipelineCompilationBuffer* pBuffer, CDevice* pDevice);
bool InitializeShader(SShader* pShader, const void* pvSourceData, size_t uSourceSize, const GLchar* szSourceOverride = NULL);
bool InitializePipelineResources(SPipeline* pPipeline, CContext* pContext);
SInputLayoutPtr CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC* pInputElementDescs, uint32 uNumElements, const TShaderReflection& kReflection, const CDevice* pDevice);
bool IsPipelineStageUsed(EPipelineMode eMode, EShaderType eType);
bool GetGLShaderType(GLenum& eGLShaderType, EShaderType eType);
bool GetGLProgramStageBit(GLbitfield& uProgramStageBit, EShaderType eType);
bool VerifyShaderStatus(GLuint uShader, GLenum eStatus);
bool VerifyProgramStatus(GLuint uProgram, GLenum eStatus);
bool VerifyProgramPipelineStatus(GLuint uPipeline, GLenum eStatus);
bool BindUniformToUnit(GLuint uProgramName, uint32 uUnit, const char* szName, CContext* pContext);
bool BindUniformBufferToUnit(GLuint uProgramName, uint32 uUnit, const char* szName, CContext* pContext);
}
#endif //__GLSHADER__
@@ -0,0 +1,531 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Implementation of the functions used to create states
// and apply them to an OpenGL device
#include "RenderDll_precompiled.h"
#include "GLState.hpp"
#include "GLDevice.hpp"
namespace NCryOpenGL
{
bool GetComparisonFunc(GLenum& eGLCompareFunc, D3D11_COMPARISON_FUNC eD3DCompareFunc)
{
switch (eD3DCompareFunc)
{
case D3D11_COMPARISON_NEVER:
eGLCompareFunc = GL_NEVER;
break;
case D3D11_COMPARISON_LESS:
eGLCompareFunc = GL_LESS;
break;
case D3D11_COMPARISON_EQUAL:
eGLCompareFunc = GL_EQUAL;
break;
case D3D11_COMPARISON_LESS_EQUAL:
eGLCompareFunc = GL_LEQUAL;
break;
case D3D11_COMPARISON_GREATER:
eGLCompareFunc = GL_GREATER;
break;
case D3D11_COMPARISON_NOT_EQUAL:
eGLCompareFunc = GL_NOTEQUAL;
break;
case D3D11_COMPARISON_GREATER_EQUAL:
eGLCompareFunc = GL_GEQUAL;
break;
case D3D11_COMPARISON_ALWAYS:
eGLCompareFunc = GL_ALWAYS;
break;
default:
return false;
}
return true;
}
bool GetStencilOperation(GLenum& eGLStencilOp, D3D11_STENCIL_OP eD3DStencilOp)
{
switch (eD3DStencilOp)
{
case D3D11_STENCIL_OP_KEEP:
eGLStencilOp = GL_KEEP;
break;
case D3D11_STENCIL_OP_ZERO:
eGLStencilOp = GL_ZERO;
break;
case D3D11_STENCIL_OP_REPLACE:
eGLStencilOp = GL_REPLACE;
break;
case D3D11_STENCIL_OP_INCR_SAT:
eGLStencilOp = GL_INCR;
break;
case D3D11_STENCIL_OP_DECR_SAT:
eGLStencilOp = GL_DECR;
break;
case D3D11_STENCIL_OP_INVERT:
eGLStencilOp = GL_INVERT;
break;
case D3D11_STENCIL_OP_INCR:
eGLStencilOp = GL_INCR_WRAP;
break;
case D3D11_STENCIL_OP_DECR:
eGLStencilOp = GL_DECR_WRAP;
break;
default:
return false;
}
return true;
}
bool GetBlendEquation(GLenum& eGLBlendEquation, D3D11_BLEND_OP eD3DBlendOp)
{
switch (eD3DBlendOp)
{
case D3D11_BLEND_OP_ADD:
eGLBlendEquation = GL_FUNC_ADD;
break;
case D3D11_BLEND_OP_SUBTRACT:
eGLBlendEquation = GL_FUNC_SUBTRACT;
break;
case D3D11_BLEND_OP_REV_SUBTRACT:
eGLBlendEquation = GL_FUNC_REVERSE_SUBTRACT;
break;
case D3D11_BLEND_OP_MIN:
eGLBlendEquation = GL_MIN;
break;
case D3D11_BLEND_OP_MAX:
eGLBlendEquation = GL_MAX;
break;
default:
return false;
}
return true;
}
bool GetBlendFunction(GLenum& eGLBlendFunction, D3D11_BLEND eD3DBlend)
{
switch (eD3DBlend)
{
case D3D11_BLEND_ZERO:
eGLBlendFunction = GL_ZERO;
break;
case D3D11_BLEND_ONE:
eGLBlendFunction = GL_ONE;
break;
case D3D11_BLEND_SRC_COLOR:
eGLBlendFunction = GL_SRC_COLOR;
break;
case D3D11_BLEND_INV_SRC_COLOR:
eGLBlendFunction = GL_ONE_MINUS_SRC_COLOR;
break;
case D3D11_BLEND_SRC_ALPHA:
eGLBlendFunction = GL_SRC_ALPHA;
break;
case D3D11_BLEND_INV_SRC_ALPHA:
eGLBlendFunction = GL_ONE_MINUS_SRC_ALPHA;
break;
case D3D11_BLEND_DEST_ALPHA:
eGLBlendFunction = GL_DST_ALPHA;
break;
case D3D11_BLEND_INV_DEST_ALPHA:
eGLBlendFunction = GL_ONE_MINUS_DST_ALPHA;
break;
case D3D11_BLEND_DEST_COLOR:
eGLBlendFunction = GL_DST_COLOR;
break;
case D3D11_BLEND_INV_DEST_COLOR:
eGLBlendFunction = GL_ONE_MINUS_DST_COLOR;
break;
case D3D11_BLEND_SRC_ALPHA_SAT:
eGLBlendFunction = GL_SRC_ALPHA_SATURATE;
break;
case D3D11_BLEND_BLEND_FACTOR:
eGLBlendFunction = GL_CONSTANT_COLOR;
break;
case D3D11_BLEND_INV_BLEND_FACTOR:
eGLBlendFunction = GL_ONE_MINUS_CONSTANT_COLOR;
break;
#if !DXGLES
case D3D11_BLEND_SRC1_COLOR:
eGLBlendFunction = GL_SRC1_COLOR;
break;
case D3D11_BLEND_INV_SRC1_COLOR:
eGLBlendFunction = GL_ONE_MINUS_SRC1_COLOR;
break;
case D3D11_BLEND_SRC1_ALPHA:
eGLBlendFunction = GL_SRC1_ALPHA;
break;
case D3D11_BLEND_INV_SRC1_ALPHA:
eGLBlendFunction = GL_ONE_MINUS_SRC1_ALPHA;
break;
#endif
default:
return false;
}
return true;
}
bool InitializeChannelBlendState(
D3D11_BLEND_OP eBlendOp, D3D11_BLEND eSrcBlend, D3D11_BLEND eDestBlend,
SChannelBlendState& kChannel)
{
if (!GetBlendEquation(kChannel.m_eEquation, eBlendOp))
{
DXGL_ERROR("Invalid blend operator");
return false;
}
if (!GetBlendFunction(kChannel.m_kFunction.m_eSrc, eSrcBlend) ||
!GetBlendFunction(kChannel.m_kFunction.m_eDst, eDestBlend))
{
DXGL_ERROR("Invalid blend factor");
return false;
}
return true;
}
bool InitializeBlendState(const D3D11_BLEND_DESC& kDesc, SBlendState& kState, CContext* context)
{
if (kDesc.IndependentBlendEnable && !context->GetDevice()->IsFeatureSupported(eF_IndependentBlending))
{
DXGL_ERROR("Independent blend state is not supported");
return false;
}
COMPILE_TIME_ASSERT(DXGL_ARRAY_SIZE(kDesc.RenderTarget) == DXGL_ARRAY_SIZE(kState.m_kTargets));
kState.m_bIndependentBlendEnable = kDesc.IndependentBlendEnable == TRUE;
kState.m_bAlphaToCoverageEnable = kDesc.AlphaToCoverageEnable == TRUE;
uint32 uTargetEnd(kState.m_bIndependentBlendEnable ? DXGL_ARRAY_SIZE(kDesc.RenderTarget) : 1);
for (uint32 uTarget = 0; uTarget < uTargetEnd; ++uTarget)
{
const D3D11_RENDER_TARGET_BLEND_DESC& kRTDesc(kDesc.RenderTarget[uTarget]);
STargetBlendState& kRTState(kState.m_kTargets[uTarget]);
kRTState.m_kWriteMask.m_abRGBA[0] = (kRTDesc.RenderTargetWriteMask & D3D11_COLOR_WRITE_ENABLE_RED) != 0 ? GL_TRUE : GL_FALSE;
kRTState.m_kWriteMask.m_abRGBA[1] = (kRTDesc.RenderTargetWriteMask & D3D11_COLOR_WRITE_ENABLE_GREEN) != 0 ? GL_TRUE : GL_FALSE;
kRTState.m_kWriteMask.m_abRGBA[2] = (kRTDesc.RenderTargetWriteMask & D3D11_COLOR_WRITE_ENABLE_BLUE) != 0 ? GL_TRUE : GL_FALSE;
kRTState.m_kWriteMask.m_abRGBA[3] = (kRTDesc.RenderTargetWriteMask & D3D11_COLOR_WRITE_ENABLE_ALPHA) != 0 ? GL_TRUE : GL_FALSE;
kRTState.m_bEnable = kRTDesc.BlendEnable == TRUE;
if (kRTState.m_bEnable)
{
kRTState.m_bSeparateAlpha =
(kRTDesc.BlendOp != kRTDesc.BlendOpAlpha) ||
(kRTDesc.SrcBlend != kRTDesc.SrcBlendAlpha) ||
(kRTDesc.DestBlend != kRTDesc.DestBlendAlpha);
if (!InitializeChannelBlendState(kRTDesc.BlendOp, kRTDesc.SrcBlend, kRTDesc.DestBlend, kRTState.m_kRGB))
{
return false;
}
if (kRTState.m_bSeparateAlpha &&
!InitializeChannelBlendState(kRTDesc.BlendOpAlpha, kRTDesc.SrcBlendAlpha, kRTDesc.DestBlendAlpha, kRTState.m_kAlpha))
{
return false;
}
}
}
return true;
}
bool InitializeStencilFace(SDepthStencilState::SFace& kStencilFace, const D3D11_DEPTH_STENCILOP_DESC& kDesc, UINT8 uWriteMask, UINT8 uReadMask)
{
kStencilFace.m_uStencilWriteMask = uWriteMask;
kStencilFace.m_uStencilReadMask = uReadMask;
if (!GetComparisonFunc(kStencilFace.m_eFunction, kDesc.StencilFunc))
{
DXGL_ERROR("Invalid stencil comparison function");
return false;
}
if (!GetStencilOperation(kStencilFace.m_eStencilFailOperation, kDesc.StencilFailOp) ||
!GetStencilOperation(kStencilFace.m_eDepthFailOperation, kDesc.StencilDepthFailOp) ||
!GetStencilOperation(kStencilFace.m_eDepthPassOperation, kDesc.StencilPassOp))
{
DXGL_ERROR("Invalid stencil operation");
return false;
}
return true;
}
bool InitializeDepthStencilState(const D3D11_DEPTH_STENCIL_DESC& kDesc, SDepthStencilState& kState, CContext*)
{
kState.m_bDepthTestingEnabled = kDesc.DepthEnable == TRUE;
switch (kDesc.DepthWriteMask)
{
case D3D11_DEPTH_WRITE_MASK_ALL:
kState.m_bDepthWriteMask = GL_TRUE;
break;
case D3D11_DEPTH_WRITE_MASK_ZERO:
kState.m_bDepthWriteMask = GL_FALSE;
break;
default:
DXGL_ERROR("Invalid depth write mask");
return false;
}
if (kState.m_bDepthTestingEnabled)
{
if (!GetComparisonFunc(kState.m_eDepthTestFunc, kDesc.DepthFunc))
{
DXGL_ERROR("Invalid depth comparison function");
return false;
}
}
kState.m_bStencilTestingEnabled = kDesc.StencilEnable == TRUE;
if (kState.m_bStencilTestingEnabled)
{
if (!InitializeStencilFace(kState.m_kStencilFrontFaces, kDesc.FrontFace, kDesc.StencilWriteMask, kDesc.StencilReadMask) ||
!InitializeStencilFace(kState.m_kStencilBackFaces, kDesc.BackFace, kDesc.StencilWriteMask, kDesc.StencilReadMask))
{
return false;
}
}
return true;
}
bool InitializeRasterizerState(const D3D11_RASTERIZER_DESC& kDesc, SRasterizerState& kState, CContext*)
{
#if !DXGLES
switch (kDesc.FillMode)
{
case D3D11_FILL_SOLID:
kState.m_ePolygonMode = GL_FILL;
break;
case D3D11_FILL_WIREFRAME:
kState.m_ePolygonMode = GL_LINE;
break;
}
#else
if (kDesc.FillMode != D3D11_FILL_SOLID)
{
DXGL_WARNING("Fill modes other than solid are not supported on OpenGL ES. The setting will be ignored");
}
#endif
switch (kDesc.CullMode)
{
case D3D11_CULL_NONE:
kState.m_bCullingEnabled = false;
break;
case D3D11_CULL_FRONT:
kState.m_eCullFaceMode = GL_FRONT;
kState.m_bCullingEnabled = true;
break;
case D3D11_CULL_BACK:
kState.m_eCullFaceMode = GL_BACK;
kState.m_bCullingEnabled = true;
break;
}
#if CRY_OPENGL_FLIP_Y
kState.m_eFrontFaceMode = kDesc.FrontCounterClockwise ? GL_CW : GL_CCW;
#else
kState.m_eFrontFaceMode = kDesc.FrontCounterClockwise ? GL_CCW : GL_CW;
#endif
kState.m_fPolygonOffsetUnits = static_cast<GLfloat>(kDesc.DepthBias); // Same behavior as D3D11 except it's input as float
kState.m_fPolygonOffsetFactor = kDesc.SlopeScaledDepthBias;
kState.m_bPolygonOffsetEnabled = kDesc.DepthBias != 0.0f || kDesc.SlopeScaledDepthBias != 0.0f;
if (kDesc.DepthBiasClamp > 0.0f)
{
DXGL_WARNING("Direct3D Depth bias clamping is not supported by OpenGL. This setting will be ignored.");
}
kState.m_bScissorEnabled = kDesc.ScissorEnable == TRUE;
kState.m_bDepthClipEnabled = kDesc.DepthClipEnable == TRUE;
#if !DXGLES
kState.m_bLineSmoothEnabled = kDesc.AntialiasedLineEnable == TRUE;
kState.m_bMultisampleEnabled = kDesc.MultisampleEnable == TRUE;
#else
if (kDesc.AntialiasedLineEnable == TRUE)
{
DXGL_WARNING("Smooth line rasterization is not supported on OpenGL ES. This setting will be ignored.");
}
if (kDesc.MultisampleEnable == TRUE)
{
DXGL_WARNING("Specifying the multisampling mode globally is not supported on OpenGL ES. This setting will be ignored.");
}
#endif
return true;
}
bool GetTexFilterParams(GLenum& eMinFilter, GLenum& eMagFilter, bool& bAnisotropic, bool& bComparison, D3D11_FILTER eD3DFilter, bool bMip)
{
switch (eD3DFilter)
{
#define _FILTER_CASE(_D3D11FilterID, _MinFilter, _MagFilter, _MipFilter, _Anisotropic, _Comparison) \
case _D3D11FilterID: \
eMinFilter = bMip ? GL_ ## _MinFilter ## _MIPMAP_ ## _MipFilter : GL_ ## _MinFilter; \
eMagFilter = GL_ ## _MagFilter; \
bAnisotropic = _Anisotropic; \
bComparison = _Comparison; \
break;
_FILTER_CASE(D3D11_FILTER_MIN_MAG_MIP_POINT, NEAREST, NEAREST, NEAREST, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, NEAREST, NEAREST, LINEAR, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, NEAREST, LINEAR, NEAREST, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, NEAREST, LINEAR, LINEAR, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, LINEAR, NEAREST, NEAREST, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, LINEAR, NEAREST, LINEAR, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, LINEAR, LINEAR, NEAREST, false, false);
_FILTER_CASE(D3D11_FILTER_MIN_MAG_MIP_LINEAR, LINEAR, LINEAR, LINEAR, false, false);
_FILTER_CASE(D3D11_FILTER_ANISOTROPIC, LINEAR, LINEAR, LINEAR, true, false);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, NEAREST, NEAREST, NEAREST, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, NEAREST, NEAREST, LINEAR, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT, NEAREST, LINEAR, NEAREST, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, NEAREST, LINEAR, LINEAR, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, LINEAR, NEAREST, NEAREST, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR, LINEAR, NEAREST, LINEAR, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, LINEAR, LINEAR, NEAREST, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, LINEAR, LINEAR, LINEAR, false, true);
_FILTER_CASE(D3D11_FILTER_COMPARISON_ANISOTROPIC, LINEAR, LINEAR, LINEAR, true, true);
#undef _FILTER_CASE
default:
return false;
}
return true;
}
bool GetTexWrapParams(GLint& iTexWrap, D3D11_TEXTURE_ADDRESS_MODE eD3DAddressMode, CContext* pContext)
{
switch (eD3DAddressMode)
{
case D3D11_TEXTURE_ADDRESS_WRAP:
iTexWrap = GL_REPEAT;
break;
case D3D11_TEXTURE_ADDRESS_MIRROR:
iTexWrap = GL_MIRRORED_REPEAT;
break;
case D3D11_TEXTURE_ADDRESS_CLAMP:
iTexWrap = GL_CLAMP_TO_EDGE;
break;
case D3D11_TEXTURE_ADDRESS_BORDER:
#if !defined(IOS) // iOS cannot compile the below gl code
if (!pContext->GetDevice()->IsFeatureSupported(eF_TextureBorderClamp))
{
DXGL_WARNING("Sampler with texture border clamping is not supported");
iTexWrap = GL_CLAMP_TO_EDGE;
return true;
}
iTexWrap = GL_CLAMP_TO_BORDER_EXT;
#else
DXGL_WARNING("Sampler with texture border clamping is not supported");
//LYTODO: Their is code that calls this function that is dependent on this succeeding, so lie for now
//set to clamp to edge and succeed.
iTexWrap = GL_CLAMP_TO_EDGE;
return true;
#endif
break;
default:
DXGL_WARNING("Unsupported sampler address mode");
return false;
}
return true;
}
bool CreateSamplerObject(const D3D11_SAMPLER_DESC& kDesc, GLuint* puSampler, bool bMip, CContext* pContext)
{
GLenum eComparisonFunc, eMinFilter, eMagFilter;
bool bAnisotropic, bComparison;
GLint iWrapS, iWrapT, iWrapR;
if (!GetTexFilterParams(eMinFilter, eMagFilter, bAnisotropic, bComparison, kDesc.Filter, bMip) ||
!GetTexWrapParams(iWrapS, kDesc.AddressU, pContext) ||
!GetTexWrapParams(iWrapT, kDesc.AddressV, pContext) ||
!GetTexWrapParams(iWrapR, kDesc.AddressW, pContext))
{
return false;
}
if (bComparison && !GetComparisonFunc(eComparisonFunc, kDesc.ComparisonFunc))
{
return false;
}
CDevice* pDevice = pContext->GetDevice();
glGenSamplers(1, puSampler);
if (bComparison)
{
glSamplerParameteri(*puSampler, GL_TEXTURE_COMPARE_FUNC, eComparisonFunc);
}
if (pDevice->IsFeatureSupported(eF_TextureAnisotropicFiltering))
{
glSamplerParameterf(*puSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, bAnisotropic ? (float)kDesc.MaxAnisotropy : 1.0f);
}
glSamplerParameteri(*puSampler, GL_TEXTURE_COMPARE_MODE, bComparison ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE);
glSamplerParameterf(*puSampler, GL_TEXTURE_MAX_LOD, kDesc.MaxLOD);
glSamplerParameteri(*puSampler, GL_TEXTURE_MAG_FILTER, eMagFilter);
glSamplerParameteri(*puSampler, GL_TEXTURE_MIN_FILTER, eMinFilter);
glSamplerParameterf(*puSampler, GL_TEXTURE_MIN_LOD, kDesc.MinLOD);
glSamplerParameteri(*puSampler, GL_TEXTURE_WRAP_S, iWrapS);
glSamplerParameteri(*puSampler, GL_TEXTURE_WRAP_T, iWrapT);
glSamplerParameteri(*puSampler, GL_TEXTURE_WRAP_R, iWrapR);
#if !defined(IOS) // iOS cannot compile the below gl code
if (pDevice->IsFeatureSupported(eF_TextureBorderClamp))
{
glSamplerParameterfv(*puSampler, GL_TEXTURE_BORDER_COLOR_EXT, kDesc.BorderColor);
}
#endif
if (kDesc.MipLODBias != 0.0f)
{
#if DXGLES
DXGL_WARNING("MipLODBias not supported on GL ES");
#else
glSamplerParameterf(*puSampler, GL_TEXTURE_LOD_BIAS, kDesc.MipLODBias);
#endif
}
return true;
}
bool InitializeSamplerState(const D3D11_SAMPLER_DESC& kDesc, SSamplerState& kSamplerState, CContext* pContext)
{
return
CreateSamplerObject(kDesc, &kSamplerState.m_uSamplerObjectMip, true, pContext) &&
CreateSamplerObject(kDesc, &kSamplerState.m_uSamplerObjectNoMip, false, pContext);
}
void ResetSamplerState(SSamplerState& kSamplerState)
{
AZStd::vector<GLuint> samplers;
if (kSamplerState.m_uSamplerObjectMip)
{
samplers.push_back(kSamplerState.m_uSamplerObjectMip);
}
if (kSamplerState.m_uSamplerObjectNoMip)
{
samplers.push_back(kSamplerState.m_uSamplerObjectNoMip);
}
if (!samplers.empty())
{
glDeleteSamplers(samplers.size(), samplers.data());
}
kSamplerState.m_uSamplerObjectMip = 0;
kSamplerState.m_uSamplerObjectNoMip = 0;
}
}
@@ -0,0 +1,162 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declares the state types and the functions to modify them
// and apply to a device
#ifndef __GLSTATE__
#define __GLSTATE__
#include "GLCommon.hpp"
namespace NCryOpenGL
{
class CDevice;
class CContext;
struct SBlendFunction
{
GLenum m_eSrc;
GLenum m_eDst;
};
struct SChannelBlendState
{
GLenum m_eEquation;
SBlendFunction m_kFunction;
};
struct SColorMask
{
GLboolean m_abRGBA[4];
};
struct STargetBlendState
{
bool m_bEnable;
bool m_bSeparateAlpha;
SChannelBlendState m_kRGB;
SChannelBlendState m_kAlpha;
SColorMask m_kWriteMask;
};
struct SBlendState
{
STargetBlendState m_kTargets[DXGL_NUM_SUPPORTED_BLEND_STATES];
bool m_bAlphaToCoverageEnable;
bool m_bIndependentBlendEnable;
};
struct SDepthStencilState
{
bool m_bDepthTestingEnabled;
GLenum m_eDepthTestFunc;
GLboolean m_bDepthWriteMask;
bool m_bStencilTestingEnabled;
struct SFace
{
GLenum m_eFunction;
GLenum m_eStencilFailOperation;
GLenum m_eDepthFailOperation;
GLenum m_eDepthPassOperation;
GLuint m_uStencilWriteMask;
GLuint m_uStencilReadMask;
} m_kStencilFrontFaces, m_kStencilBackFaces;
};
struct SRasterizerState
{
bool m_bCullingEnabled;
GLenum m_eCullFaceMode;
GLenum m_eFrontFaceMode;
bool m_bPolygonOffsetEnabled;
GLfloat m_fPolygonOffsetUnits;
GLfloat m_fPolygonOffsetFactor;
bool m_bScissorEnabled;
bool m_bDepthClipEnabled;
#if !DXGLES
GLenum m_ePolygonMode;
bool m_bLineSmoothEnabled;
bool m_bMultisampleEnabled;
#endif //!DXGLES
};
struct SSamplerState
{
// OpenGL doesn't allow a sampler object with mipmap filtering to be used with
// textures without mipmaps. For this reason two different sampler objects are needed.
GLuint m_uSamplerObjectMip;
GLuint m_uSamplerObjectNoMip;
};
bool InitializeBlendState(const D3D11_BLEND_DESC& kDesc, SBlendState& kState, CContext* pContext);
bool InitializeDepthStencilState(const D3D11_DEPTH_STENCIL_DESC& kDesc, SDepthStencilState& kState, CContext* pContext);
bool InitializeRasterizerState(const D3D11_RASTERIZER_DESC& kDesc, SRasterizerState& kState, CContext* pContext);
bool InitializeSamplerState(const D3D11_SAMPLER_DESC& kDesc, SSamplerState& kState, CContext* pContext);
void ResetSamplerState(SSamplerState& kSamplerState);
bool GetTexFilterParams(GLenum& eMinFilter, GLenum& eMagFilter, bool& bAnisotropic, bool& bComparison, D3D11_FILTER eD3DFilter, bool bMip);
inline bool operator==(SBlendFunction kLeft, SBlendFunction kRight)
{
return
kLeft.m_eSrc == kRight.m_eSrc &&
kLeft.m_eDst == kRight.m_eDst;
}
inline bool operator==(SChannelBlendState kLeft, SChannelBlendState kRight)
{
return
kLeft.m_eEquation == kRight.m_eEquation &&
kLeft.m_kFunction == kRight.m_kFunction;
}
inline bool operator==(SColorMask kLeft, SColorMask kRight)
{
return 0 == memcmp(kLeft.m_abRGBA, kRight.m_abRGBA, sizeof(kRight.m_abRGBA));
}
inline bool operator==(const STargetBlendState& kLeft, const STargetBlendState& kRight)
{
return
kLeft.m_bEnable == kRight.m_bEnable &&
kLeft.m_bSeparateAlpha == kRight.m_bSeparateAlpha &&
kLeft.m_kRGB == kRight.m_kRGB &&
kLeft.m_kAlpha == kRight.m_kAlpha &&
kLeft.m_kWriteMask == kRight.m_kWriteMask;
}
inline bool operator!=(SBlendFunction kLeft, SBlendFunction kRight)
{
return !(kLeft == kRight);
}
inline bool operator!=(SChannelBlendState kLeft, SChannelBlendState kRight)
{
return !(kLeft == kRight);
}
inline bool operator!=(SColorMask kLeft, SColorMask kRight)
{
return !(kLeft == kRight);
}
inline bool operator!=(const STargetBlendState& kLeft, const STargetBlendState& kRight)
{
return !(kLeft == kRight);
}
}
#endif //__GLSTATE__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,334 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Declares the resource view types and related functions
#ifndef __GLVIEW__
#define __GLVIEW__
#include "GLResource.hpp"
namespace NCryOpenGL
{
struct SShaderTextureViewConfiguration
{
EGIFormat m_eFormat;
GLenum m_eTarget;
uint32 m_uMinMipLevel;
uint32 m_uNumMipLevels;
uint32 m_uMinLayer;
uint32 m_uNumLayers;
SShaderTextureViewConfiguration(EGIFormat eFormat, GLenum eTarget, uint32 uMinMipLevel, uint32 uNumMipLevels, uint32 uMinLayer, uint32 uNumLayers)
: m_eFormat(eFormat)
, m_eTarget(eTarget)
, m_uMinMipLevel(uMinMipLevel)
, m_uNumMipLevels(uNumMipLevels)
, m_uMinLayer(uMinLayer)
, m_uNumLayers(uNumLayers)
{
}
bool operator==(const SShaderTextureViewConfiguration& kOther)
{
return
m_eFormat == kOther.m_eFormat &&
m_eTarget == kOther.m_eTarget &&
m_uMinMipLevel == kOther.m_uMinMipLevel &&
m_uNumMipLevels == kOther.m_uNumMipLevels &&
m_uMinLayer == kOther.m_uMinLayer &&
m_uNumLayers == kOther.m_uNumLayers;
}
};
struct SShaderTextureBufferViewConfiguration
{
EGIFormat m_eFormat;
uint32 m_uFirstElement;
uint32 m_uNumElements;
SShaderTextureBufferViewConfiguration(EGIFormat eFormat, uint32 uFirstElement, uint32 uNumElements)
: m_eFormat(eFormat)
, m_uFirstElement(uFirstElement)
, m_uNumElements(uNumElements)
{
}
bool operator==(const SShaderTextureBufferViewConfiguration& kOther)
{
return
m_eFormat == kOther.m_eFormat &&
m_uFirstElement == kOther.m_uFirstElement &&
m_uNumElements == kOther.m_uNumElements;
}
};
struct SShaderImageViewConfiguration
{
GLint m_iLevel;
GLint m_iLayer; // -1 for all layers
GLenum m_eAccess;
GLenum m_eFormat;
SShaderImageViewConfiguration()
: m_iLevel(0)
, m_iLayer(-1)
, m_eAccess(GL_NONE)
, m_eFormat(GL_NONE)
{
}
SShaderImageViewConfiguration(GLenum eFormat, GLint iLevel, GLint iLayer, GLenum eAccess)
: m_eFormat(eFormat)
, m_iLevel(iLevel)
, m_iLayer(iLayer)
, m_eAccess(eAccess)
{
}
bool operator==(const SShaderImageViewConfiguration& kOther)
{
return
m_iLevel == kOther.m_iLevel &&
m_iLayer == kOther.m_iLayer &&
m_eAccess == kOther.m_eAccess &&
m_eFormat == kOther.m_eFormat;
}
bool operator!=(const SShaderImageViewConfiguration& kOther)
{
return !operator==(kOther);
}
};
struct SOutputMergerTextureViewConfiguration
{
EGIFormat m_eFormat;
uint32 m_uMipLevel;
uint32 m_uMinLayer;
uint32 m_uNumLayers;
SOutputMergerTextureViewConfiguration(EGIFormat eFormat, uint32 uMipLevel, uint32 uMinLayer, uint32 uNumLayers)
: m_eFormat(eFormat)
, m_uMipLevel(uMipLevel)
, m_uMinLayer(uMinLayer)
, m_uNumLayers(uNumLayers)
{
}
bool operator==(const SOutputMergerTextureViewConfiguration& kOther)
{
return
m_eFormat == kOther.m_eFormat &&
m_uMipLevel == kOther.m_uMipLevel &&
m_uMinLayer == kOther.m_uMinLayer &&
m_uNumLayers == kOther.m_uNumLayers;
}
};
DXGL_DECLARE_REF_COUNTED(struct, SShaderView)
{
enum Type
{
eSVT_Buffer,
eSVT_Texture,
eSVT_Image
};
SShaderView(Type eType);
virtual ~SShaderView();
CResourceName m_kName;
SSharingFence m_kCreationFence;
Type m_eType;
};
struct SShaderBufferView
: SShaderView
{
SShaderBufferView(const SBufferRange& kRange);
virtual ~SShaderBufferView();
void Init(SBuffer* pBuffer, CContext* pContext);
SBufferRange m_kRange;
};
struct SShaderTextureBasedView
: SShaderView
{
SShaderTextureBasedView(Type eType);
virtual ~SShaderTextureBasedView();
virtual bool BindTextureUnit(SSamplerState* pSamplerState, STextureUnitContext& kContext, CContext* pContext, const STextureUnitCache& kCurrentUnitCache);
virtual bool GenerateMipmaps(CContext* pContext);
bool m_bTextureOwned;
bool m_bFormatRequiresUniqueView;
};
struct SShaderTextureBufferView
: SShaderTextureBasedView
{
SShaderTextureBufferView(const SShaderTextureBufferViewConfiguration& kConfiguration);
virtual ~SShaderTextureBufferView();
bool Init(SBuffer* pBuffer, CContext* pContext);
virtual bool BindTextureUnit(SSamplerState* pSamplerState, STextureUnitContext& kContext, CContext* pContext, const STextureUnitCache& kCurrentUnitCache);
SBuffer* m_pBuffer;
SShaderTextureBufferViewConfiguration m_kConfiguration;
SShaderTextureBufferView* m_pNextView;
};
struct SShaderTextureView
: SShaderTextureBasedView
{
SShaderTextureView(const SShaderTextureViewConfiguration& kConfiguration);
virtual ~SShaderTextureView();
bool Init(STexture* pTexture, CContext* pContext);
bool CreateUniqueView(CContext* pContext);
virtual bool BindTextureUnit(SSamplerState* pSamplerState, STextureUnitContext& kContext, CContext* pContext, const STextureUnitCache& kCurrentUnitCache);
virtual bool GenerateMipmaps(CContext* pContext);
STexture* m_pTexture;
SShaderTextureViewConfiguration m_kConfiguration;
STextureState m_kViewState;
SShaderTextureView* m_pNextView;
};
struct SShaderImageView
: SShaderTextureBasedView
{
SShaderImageView(const SShaderImageViewConfiguration& kConfiguration);
virtual ~SShaderImageView();
bool Init(STexture* pTexture, CContext* pContext);
bool Init(SShaderTextureBasedView* pTextureBufferView, CContext* pContext);
SShaderImageViewConfiguration m_kConfiguration;
SShaderViewPtr m_spAuxiliaryView;
};
struct SOutputMergerTextureView;
DXGL_DECLARE_REF_COUNTED(struct, SOutputMergerView)
{
SOutputMergerView(const CResourceName&kUniqueView, EGIFormat eFormat);
virtual ~SOutputMergerView();
virtual bool AttachFrameBuffer(SFrameBuffer * pFrameBuffer, GLenum eAttachmentID, CContext * pContext);
virtual void DetachFrameBuffer(SFrameBuffer * pFrameBuffer);
virtual bool FrameBufferTexture(GLuint uFrameBuffer, GLenum eAttachmentID);
virtual void Bind(const SFrameBuffer&kFrameBuffer, CContext * pContext);
struct SFrameBufferRef
{
SFrameBufferPtr m_spFrameBuffer;
uint32 m_uNumBindings;
SFrameBufferRef(SFrameBuffer* pFrameBuffer, uint32 uNumBindings)
: m_spFrameBuffer(pFrameBuffer)
, m_uNumBindings(uNumBindings)
{
}
bool operator==(const SFrameBuffer* pOther)
{
return m_spFrameBuffer == pOther;
}
};
typedef std::vector<SFrameBufferRef> TFrameBufferRefs;
struct SContextData
{
TFrameBufferRefs m_kBoundFrameBuffers;
};
typedef SContextData* TContextMap[MAX_NUM_CONTEXT_PER_DEVICE];
CResourceName m_kUniqueView;
EGIFormat m_eFormat;
TContextMap m_kContextMap;
SSharingFence m_kCreationFence;
#if defined(ANDROID) || defined(DXGL_USE_LAZY_CLEAR)
virtual SOutputMergerTextureView* AsSOutputMergerTextureView() { return NULL; }
#endif
};
struct SOutputMergerTextureView
: SOutputMergerView
{
SOutputMergerTextureView(STexture* pTexture, const SOutputMergerTextureViewConfiguration& kConfiguration);
virtual ~SOutputMergerTextureView();
bool Init(CContext* pContext);
virtual bool FrameBufferTexture(GLuint uFrameBuffer, GLenum eAttachmentID);
virtual bool CreateUniqueView(const SGIFormatInfo* pFormatInfo, CContext* pContext);
STexture* m_pTexture;
SOutputMergerTextureViewConfiguration m_kConfiguration;
SOutputMergerTextureView* m_pNextView;
GLint m_iMipLevel;
GLint m_iLayer; //INVALID_LAYER for all layers
static const GLint INVALID_LAYER;
#if defined(ANDROID) || defined(DXGL_USE_LAZY_CLEAR)
virtual SOutputMergerTextureView* AsSOutputMergerTextureView() { return this; }
#endif
};
struct SDefaultFrameBufferOutputMergerView
: SOutputMergerTextureView
{
SDefaultFrameBufferOutputMergerView(SDefaultFrameBufferTexture* pTexture, const SOutputMergerTextureViewConfiguration& kConfiguration);
virtual ~SDefaultFrameBufferOutputMergerView();
virtual bool AttachFrameBuffer(SFrameBuffer* pFrameBuffer, GLenum eAttachmentID, CContext* pContext);
virtual void Bind(const SFrameBuffer& kFrameBuffer, CContext* pContext);
virtual bool CreateUniqueView(const SGIFormatInfo* pFormatInfo, CContext* pContext);
bool m_bUsesTexture;
};
struct SDefaultFrameBufferShaderTextureView
: SShaderTextureView
{
SDefaultFrameBufferShaderTextureView(const SShaderTextureViewConfiguration& kConfiguration);
virtual ~SDefaultFrameBufferShaderTextureView();
virtual bool BindTextureUnit(SSamplerState* pSamplerState, STextureUnitContext& kContext, CContext* pContext, const STextureUnitCache& kCurrentUnitCache);
bool m_bUsesTexture;
};
SShaderViewPtr CreateShaderResourceView(SResource* pResource, D3D11_RESOURCE_DIMENSION eDimension, const D3D11_SHADER_RESOURCE_VIEW_DESC& kViewDesc, CContext* pContext);
SShaderViewPtr CreateUnorderedAccessView(SResource* pResource, D3D11_RESOURCE_DIMENSION eDimension, const D3D11_UNORDERED_ACCESS_VIEW_DESC& kViewDesc, CContext* pContext);
SOutputMergerViewPtr CreateRenderTargetView(SResource* pResource, D3D11_RESOURCE_DIMENSION eDimension, const D3D11_RENDER_TARGET_VIEW_DESC& kViewDesc, CContext* pContext);
SOutputMergerViewPtr CreateDepthStencilView(SResource* pResource, D3D11_RESOURCE_DIMENSION eDimension, const D3D11_DEPTH_STENCIL_VIEW_DESC& kViewDesc, CContext* pContext);
}
#endif //__GLVIEW__