Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OpenGL ES as a shading language #1497

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/OpenColorIO/OpenColorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ enum GpuLanguage
GPU_LANGUAGE_GLSL_1_3, ///< OpenGL Shading Language
GPU_LANGUAGE_GLSL_4_0, ///< OpenGL Shading Language
GPU_LANGUAGE_HLSL_DX11, ///< DirectX Shading Language
LANGUAGE_OSL_1 ///< Open Shading Language
LANGUAGE_OSL_1, ///< Open Shading Language
GPU_LANGUAGE_GLSL_ES_1_0, ///< OpenGL ES Shading Language
GPU_LANGUAGE_GLSL_ES_3_0, ///< OpenGL ES Shading Language
amyspark marked this conversation as resolved.
Show resolved Hide resolved
};

enum EnvironmentMode
Expand Down
40 changes: 40 additions & 0 deletions src/OpenColorIO/GpuShaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ std::string getVecKeyword(GpuLanguage lang)
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
kw << "vec" << N;
break;
Expand Down Expand Up @@ -85,6 +87,8 @@ void getTexDecl(GpuLanguage lang,
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_CG:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
textureDecl = "";

Expand Down Expand Up @@ -132,6 +136,15 @@ std::string getTexSample(GpuLanguage lang,
kw << "texture" << N << "D(" << samplerName << ", " << coords << ")";
break;
}
case GPU_LANGUAGE_GLSL_ES_1_0:
{
if (N == 1) {
throw Exception("1D textures are unsupported by OpenGL ES.");
}

kw << "texture" << N << "D(" << samplerName << ", " << coords << ")";
break;
}
case GPU_LANGUAGE_CG:
{
kw << "tex" << N << "D(" << samplerName << ", " << coords << ")";
Expand All @@ -147,6 +160,15 @@ std::string getTexSample(GpuLanguage lang,
kw << "texture(" << samplerName << ", " << coords << ")";
break;
}
case GPU_LANGUAGE_GLSL_ES_3_0:
{
if (N == 1) {
throw Exception("1D textures are unsupported by OpenGL ES.");
}

kw << "texture(" << samplerName << ", " << coords << ")";
break;
}
case LANGUAGE_OSL_1:
{
throw Exception("Unsupported by the Open Shading language (OSL) translation.");
Expand Down Expand Up @@ -299,6 +321,8 @@ std::string GpuShaderText::floatKeywordConst() const
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
case GPU_LANGUAGE_HLSL_DX11:
{
str += "const";
Expand Down Expand Up @@ -404,6 +428,8 @@ void GpuShaderText::declareFloatArrayConst(const std::string & name, int size, c
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
nl << floatKeywordConst() << " " << name << "[" << size << "] = ";
nl << floatKeyword() << "[" << size << "](";
Expand Down Expand Up @@ -455,6 +481,8 @@ void GpuShaderText::declareIntArrayConst(const std::string & name, int size, con
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
nl << "const " << intKeyword() << " " << name << "[" << size << "] = "
<< intKeyword() << "[" << size << "](";
Expand Down Expand Up @@ -798,6 +826,8 @@ std::string matrix4Mul(const T * m4x4, const std::string & vecName, GpuLanguage
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
// OpenGL shader program requests a transposed matrix
kw << "mat4("
Expand Down Expand Up @@ -858,6 +888,8 @@ std::string GpuShaderText::lerp(const std::string & x,
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
kw << "mix(" << x << ", " << y << ", " << a << ")";
break;
Expand Down Expand Up @@ -886,6 +918,8 @@ std::string GpuShaderText::float3GreaterThan(const std::string & a,
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
case GPU_LANGUAGE_CG:
{
kw << float3Keyword() << "(greaterThan( " << a << ", " << b << "))";
Expand Down Expand Up @@ -918,6 +952,8 @@ std::string GpuShaderText::float4GreaterThan(const std::string & a,
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
case GPU_LANGUAGE_CG:
{
kw << float4Keyword() << "(greaterThan( " << a << ", " << b << "))";
Expand Down Expand Up @@ -960,6 +996,8 @@ std::string GpuShaderText::atan2(const std::string & y,
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
{
// note: "atan" not "atan2"
kw << "atan(" << y << ", " << x << ")";
Expand Down Expand Up @@ -990,6 +1028,8 @@ std::string GpuShaderText::sign(const std::string & v) const
case GPU_LANGUAGE_GLSL_1_2:
case GPU_LANGUAGE_GLSL_1_3:
case GPU_LANGUAGE_GLSL_4_0:
case GPU_LANGUAGE_GLSL_ES_1_0:
case GPU_LANGUAGE_GLSL_ES_3_0:
case GPU_LANGUAGE_HLSL_DX11:
{
kw << "sign(" << v << ");";
Expand Down
4 changes: 4 additions & 0 deletions src/OpenColorIO/ParseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ const char * GpuLanguageToString(GpuLanguage language)
case GPU_LANGUAGE_GLSL_1_2: return "glsl_1.2";
case GPU_LANGUAGE_GLSL_1_3: return "glsl_1.3";
case GPU_LANGUAGE_GLSL_4_0: return "glsl_4.0";
case GPU_LANGUAGE_GLSL_ES_1_0: return "glsl_es_1.0";
case GPU_LANGUAGE_GLSL_ES_3_0: return "glsl_es_3.0";
case GPU_LANGUAGE_HLSL_DX11: return "hlsl_dx11";
case LANGUAGE_OSL_1: return "osl_1";
}
Expand All @@ -277,6 +279,8 @@ GpuLanguage GpuLanguageFromString(const char * s)
else if(str == "glsl_1.2") return GPU_LANGUAGE_GLSL_1_2;
else if(str == "glsl_1.3") return GPU_LANGUAGE_GLSL_1_3;
else if(str == "glsl_4.0") return GPU_LANGUAGE_GLSL_4_0;
else if(str == "glsl_es_1.0") return GPU_LANGUAGE_GLSL_ES_1_0;
else if(str == "glsl_es_3.0") return GPU_LANGUAGE_GLSL_ES_3_0;
else if(str == "hlsl_dx11") return GPU_LANGUAGE_HLSL_DX11;
else if(str == "osl_1") return LANGUAGE_OSL_1;

Expand Down
11 changes: 8 additions & 3 deletions src/OpenColorIO/ops/lut1d/Lut1DOpGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,12 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,

// Add the LUT code to the OCIO shader program.

if (height > 1 || lutData->isInputHalfDomain())
if (height > 1 || lutData->isInputHalfDomain()
|| shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_1_0
|| shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_3_0)
{
// In case the 1D LUT length exceeds the 1D texture maximum length
// In case the 1D LUT length exceeds the 1D texture maximum length,
// or the language doesn't support 1D textures,
// a 2D texture is used.

{
Expand Down Expand Up @@ -321,7 +324,9 @@ void GetLut1DGPUShaderProgram(GpuShaderCreatorRcPtr & shaderCreator,
ss.newLine() << "";
}

if (height > 1 || lutData->isInputHalfDomain())
if (height > 1 || lutData->isInputHalfDomain()
|| shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_1_0
|| shaderCreator->getLanguage() == GPU_LANGUAGE_GLSL_ES_3_0)
{
const std::string str = name + "_computePos(" + shaderCreator->getPixelName();

Expand Down
4 changes: 4 additions & 0 deletions src/bindings/python/PyTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ void bindPyTypes(py::module & m)
DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_1_3))
.value("GPU_LANGUAGE_GLSL_4_0", GPU_LANGUAGE_GLSL_4_0,
DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_4_0))
.value("GPU_LANGUAGE_GLSL_ES_1_0", GPU_LANGUAGE_GLSL_ES_1_0,
DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_ES_1_0))
.value("GPU_LANGUAGE_GLSL_ES_3_0", GPU_LANGUAGE_GLSL_ES_3_0,
DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_GLSL_ES_3_0))
.value("GPU_LANGUAGE_HLSL_DX11", GPU_LANGUAGE_HLSL_DX11,
DOC(PyOpenColorIO, GpuLanguage, GPU_LANGUAGE_HLSL_DX11))
.export_values();
Expand Down
24 changes: 17 additions & 7 deletions src/libutils/oglapphelpers/glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,27 @@ void OpenGLBuilder::useAllUniforms()

std::string OpenGLBuilder::getGLSLVersionString()
{
if (m_shaderDesc->getLanguage() == GPU_LANGUAGE_GLSL_1_3)
switch (m_shaderDesc->getLanguage())
{
case GPU_LANGUAGE_GLSL_1_2:
// That's the minimal version supported.
return "#version 120";
case GPU_LANGUAGE_GLSL_1_3:
return "#version 130";
}
else if (m_shaderDesc->getLanguage() == GPU_LANGUAGE_GLSL_4_0)
{
case GPU_LANGUAGE_GLSL_4_0:
return "#version 400 core";
case GPU_LANGUAGE_GLSL_ES_1_0:
return "#version 100";
case GPU_LANGUAGE_GLSL_ES_3_0:
return "#version 300 es";
case GPU_LANGUAGE_CG:
case GPU_LANGUAGE_HLSL_DX11:
case LANGUAGE_OSL_1:
default:
// These are all impossible in OpenGL contexts.
// The shader will be unusable, so let's throw
throw Exception("Invalid shader language for OpenGLBuilder");
}

// That's the minimal version supported.
return "#version 120";
}

unsigned OpenGLBuilder::buildProgram(const std::string & clientShaderProgram)
Expand Down