Commit e61209af by Olli Etuaho Committed by Jamie Madill

Add option to support EXT_draw_buffers with NV_draw_buffers

After this patch, it is possible to set a flag to change EXT_draw_buffers extension directives to NV_draw_buffers in ESSL. This enables users of ANGLE to emulate EXT_draw_buffers by using NV_draw_buffers in combination with GLES3.0. Change-Id: I5dacdbd6cd0d0362424ea3791557342c42efd4bd Reviewed-on: https://chromium-review.googlesource.com/219941Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 955f5c05
...@@ -246,6 +246,12 @@ typedef struct ...@@ -246,6 +246,12 @@ typedef struct
int EXT_frag_depth; int EXT_frag_depth;
int EXT_shader_texture_lod; int EXT_shader_texture_lod;
// Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives
// with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate
// EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers
// function. This applies to Tegra K1 devices.
int NV_draw_buffers;
// Set to 1 if highp precision is supported in the fragment language. // Set to 1 if highp precision is supported in the fragment language.
// Default is 0. // Default is 0.
int FragmentPrecisionHigh; int FragmentPrecisionHigh;
......
...@@ -360,7 +360,8 @@ void TCompiler::setResourceString() ...@@ -360,7 +360,8 @@ void TCompiler::setResourceString()
<< ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
<< ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
<< ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
<< ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset; << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
<< ":NV_draw_buffers:" << compileResources.NV_draw_buffers;
builtInResourcesString = strstream.str(); builtInResourcesString = strstream.str();
} }
......
...@@ -201,6 +201,8 @@ void ShInitBuiltInResources(ShBuiltInResources* resources) ...@@ -201,6 +201,8 @@ void ShInitBuiltInResources(ShBuiltInResources* resources)
resources->EXT_frag_depth = 0; resources->EXT_frag_depth = 0;
resources->EXT_shader_texture_lod = 0; resources->EXT_shader_texture_lod = 0;
resources->NV_draw_buffers = 0;
// Disable highp precision in fragment shader by default. // Disable highp precision in fragment shader by default.
resources->FragmentPrecisionHigh = 0; resources->FragmentPrecisionHigh = 0;
......
...@@ -37,8 +37,13 @@ void TranslatorESSL::writeExtensionBehavior() { ...@@ -37,8 +37,13 @@ void TranslatorESSL::writeExtensionBehavior() {
for (TExtensionBehavior::const_iterator iter = extensionBehavior.begin(); for (TExtensionBehavior::const_iterator iter = extensionBehavior.begin();
iter != extensionBehavior.end(); ++iter) { iter != extensionBehavior.end(); ++iter) {
if (iter->second != EBhUndefined) { if (iter->second != EBhUndefined) {
sink << "#extension " << iter->first << " : " if (getResources().NV_draw_buffers && iter->first == "GL_EXT_draw_buffers") {
<< getBehaviorString(iter->second) << "\n"; sink << "#extension GL_NV_draw_buffers : "
<< getBehaviorString(iter->second) << "\n";
} else {
sink << "#extension " << iter->first << " : "
<< getBehaviorString(iter->second) << "\n";
}
} }
} }
} }
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NV_draw_buffers_test.cpp:
// Test for NV_draw_buffers setting
//
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
class NVDrawBuffersTest : public testing::Test
{
public:
NVDrawBuffersTest() {}
protected:
virtual void SetUp()
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
resources.MaxDrawBuffers = 8;
resources.EXT_draw_buffers = 1;
resources.NV_draw_buffers = 1;
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES2_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown()
{
delete mTranslator;
}
TranslatorESSL *mTranslator;
};
TEST_F(NVDrawBuffersTest, NVDrawBuffers)
{
const std::string &shaderString =
"#extension GL_EXT_draw_buffers : require\n"
"precision mediump float;\n"
"void main() {\n"
" gl_FragData[0] = vec4(1.0);\n"
" gl_FragData[1] = vec4(0.0);\n"
"}\n";
const char *shaderStrings[] = { shaderString.c_str() };
ASSERT_TRUE(mTranslator->compile(shaderStrings, 1, SH_OBJECT_CODE));
TInfoSink& infoSink = mTranslator->getInfoSink();
std::string objCode(infoSink.obj.c_str());
size_t nv_draw_buffers_ind = objCode.find("GL_NV_draw_buffers");
EXPECT_NE(std::string::npos, nv_draw_buffers_ind);
size_t ext_draw_buffers_ind = objCode.find("GL_EXT_draw_buffers");
EXPECT_EQ(std::string::npos, ext_draw_buffers_ind);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment