Files
UnrealEngineUWP/Engine/Source/Developer/ShaderFormatOpenGL/Private/ShaderFormatOpenGL.cpp
jack porter 4f9b4635d3 Fix hlslcc depth fetch support on Android devices not supporting GL_ARM_shader_framebuffer_fetch_depth_stencil
Reapply change that did not correctly make it into 19.01.
#rb Chris.Babcock
[FYI] Chris.Babcock

#ROBOMERGE-AUTHOR: jack.porter
#ROBOMERGE-SOURCE: CL 18465602 via CL 18465606 via CL 18465616 via CL 18465618 via CL 18465694 via CL 18465699
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v899-18417669)

[CL 18465700 by jack porter in ue5-release-engine-test branch]
2021-12-15 04:14:37 -05:00

114 lines
2.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
//
#include "ShaderFormatOpenGL.h"
#include "HAL/FileManager.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IShaderFormat.h"
#include "Interfaces/IShaderFormatModule.h"
#include "ShaderCore.h"
#include "ShaderCompilerCore.h"
static FName NAME_GLSL_150_ES3_1(TEXT("GLSL_150_ES31"));
static FName NAME_GLSL_ES3_1_ANDROID(TEXT("GLSL_ES3_1_ANDROID"));
class FShaderFormatGLSL : public IShaderFormat
{
enum
{
/** Version for shader format, this becomes part of the DDC key. */
UE_SHADER_GLSL_VER = 103,
};
void CheckFormat(FName Format) const
{
check(Format == NAME_GLSL_150_ES3_1 || Format == NAME_GLSL_ES3_1_ANDROID);
}
public:
virtual uint32 GetVersion(FName Format) const override
{
CheckFormat(Format);
uint32 GLSLVersion = 0;
if (Format == NAME_GLSL_150_ES3_1 || Format == NAME_GLSL_ES3_1_ANDROID)
{
GLSLVersion = UE_SHADER_GLSL_VER;
}
else
{
check(0);
}
const uint16 Version = ((HLSLCC_VersionMinor & 0xff) << 8) | (GLSLVersion & 0xff);
return Version;
}
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const override
{
OutFormats.Add(NAME_GLSL_150_ES3_1);
OutFormats.Add(NAME_GLSL_ES3_1_ANDROID);
}
static GLSLVersion TranslateFormatNameToEnum(FName Format)
{
if (Format == NAME_GLSL_150_ES3_1)
{
return GLSL_150_ES3_1;
}
else if (Format == NAME_GLSL_ES3_1_ANDROID)
{
return GLSL_ES3_1_ANDROID;
}
else
{
check(0);
return GLSL_MAX;
}
}
virtual void CompileShader(FName Format, const struct FShaderCompilerInput& Input, struct FShaderCompilerOutput& Output,const FString& WorkingDirectory) const override
{
CheckFormat(Format);
GLSLVersion Version = TranslateFormatNameToEnum(Format);
FOpenGLFrontend Frontend;
// the frontend will run the cross compiler
Frontend.CompileShader(Input, Output, WorkingDirectory, Version);
}
virtual const TCHAR* GetPlatformIncludeDirectory() const
{
return TEXT("GL");
}
virtual bool UsesHLSLcc(const struct FShaderCompilerInput& Input) const override
{
return !Input.Environment.CompilerFlags.Contains(CFLAG_ForceDXC);
}
};
/**
* Module for OpenGL shaders
*/
static IShaderFormat* Singleton = NULL;
class FShaderFormatOpenGLModule : public IShaderFormatModule
{
public:
virtual ~FShaderFormatOpenGLModule()
{
delete Singleton;
Singleton = NULL;
}
virtual IShaderFormat* GetShaderFormat()
{
if (!Singleton)
{
Singleton = new FShaderFormatGLSL();
}
return Singleton;
}
};
IMPLEMENT_MODULE( FShaderFormatOpenGLModule, ShaderFormatOpenGL);