Files
UnrealEngineUWP/Engine/Source/Developer/ShaderFormatOpenGL/Private/ShaderFormatOpenGL.cpp
dmitriy dyomin 12eb52b317 Fixed: Water texture missing throughout the map in BR on Android
#rb peter.sauerbrei

[CL 21864603 by dmitriy dyomin in ue5-main branch]
2022-09-07 18:03:53 -04: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 = 106,
};
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);