Merge pull request #6037 from rokuz/master-shaders-refactoring-2

Refactored shaders generation system
This commit is contained in:
Daria Volvenkova 2017-05-12 13:15:14 +03:00 committed by GitHub
commit 247edc9f71
150 changed files with 1472 additions and 2439 deletions

6
.gitignore vendored
View file

@ -18,6 +18,7 @@ data/*.mwmmeta
data/[!W]*.mwm
data/local_ads*.dat
data/local_ads_*/*.*
data/shaders_compiler/*
# Compiled Python
*.pyc
@ -119,7 +120,10 @@ tools/twine/.git
# shader preprocessing moc files
drape/shader_def.hpp
drape/shader_def.cpp
drape/drape_tests/enum_shaders.hpp
drape_frontend/shader_def.hpp
drape_frontend/shader_def.cpp
drape_frontend/drape_frontend_tests/shader_def_for_tests.hpp
drape_frontend/drape_frontend_tests/shader_def_for_tests.cpp
tizen/*/Debug/*
tizen/*/.*

Binary file not shown.

Binary file not shown.

View file

@ -2,13 +2,6 @@ project(drape)
get_filename_component(DRAPE_ROOT ${PROJECT_SOURCE_DIR} ABSOLUTE)
execute_process(
COMMAND python ${OMIM_ROOT}/tools/autobuild/shader_preprocessor.py
${DRAPE_ROOT}/shaders
shader_index.txt
shader_def
)
add_definitions(-DU_DISABLE_RENAMING)
include_directories(
@ -65,6 +58,7 @@ set(
${DRAPE_ROOT}/gpu_buffer.hpp
${DRAPE_ROOT}/gpu_program.cpp
${DRAPE_ROOT}/gpu_program.hpp
${DRAPE_ROOT}/gpu_program_info.hpp
${DRAPE_ROOT}/gpu_program_manager.cpp
${DRAPE_ROOT}/gpu_program_manager.hpp
${DRAPE_ROOT}/hw_texture.cpp
@ -89,8 +83,6 @@ set(
${DRAPE_ROOT}/render_bucket.hpp
${DRAPE_ROOT}/shader.cpp
${DRAPE_ROOT}/shader.hpp
${DRAPE_ROOT}/shader_def.cpp
${DRAPE_ROOT}/shader_def.hpp
${DRAPE_ROOT}/static_texture.cpp
${DRAPE_ROOT}/static_texture.hpp
${DRAPE_ROOT}/stipple_pen_resource.cpp

View file

@ -2,7 +2,6 @@
#include "drape/gpu_program_manager.hpp"
#include "drape/glfunctions.hpp"
#include "drape/shader_def.hpp"
namespace dp
{
@ -40,7 +39,7 @@ DebugRectRenderer::~DebugRectRenderer()
ASSERT_EQUAL(m_vertexBuffer, 0, ());
}
void DebugRectRenderer::Init(ref_ptr<dp::GpuProgramManager> mng)
void DebugRectRenderer::Init(ref_ptr<dp::GpuProgramManager> mng, int programId)
{
m_vertexBuffer = GLFunctions::glGenBuffer();
GLFunctions::glBindBuffer(m_vertexBuffer, gl_const::GLArrayBuffer);
@ -48,7 +47,7 @@ void DebugRectRenderer::Init(ref_ptr<dp::GpuProgramManager> mng)
m_VAO = GLFunctions::glGenVertexArray();
GLFunctions::glBindVertexArray(m_VAO);
m_program = mng->GetProgram(gpu::DEBUG_RECT_PROGRAM);
m_program = mng->GetProgram(programId);
int8_t attributeLocation = m_program->GetAttributeLocation("a_position");
ASSERT_NOT_EQUAL(attributeLocation, -1, ());
GLFunctions::glEnableVertexAttribute(attributeLocation);

View file

@ -16,7 +16,7 @@ class DebugRectRenderer
{
public:
static DebugRectRenderer & Instance();
void Init(ref_ptr<dp::GpuProgramManager> mng);
void Init(ref_ptr<dp::GpuProgramManager> mng, int programId);
void Destroy();
bool IsEnabled() const;

View file

@ -5,70 +5,9 @@ INCLUDEPATH += ../3party/icu/common ../3party/icu/i18n
DEFINES += U_DISABLE_RENAMING
ROOT_DIR = ..
SHADER_COMPILE_ARGS = $$PWD/shaders shader_index.txt shader_def
include($$ROOT_DIR/common.pri)
DRAPE_DIR = .
include($$DRAPE_DIR/drape_common.pri)
SOURCES += glfunctions.cpp
OTHER_FILES += \
shaders/area3d_vertex_shader.vsh \
shaders/area3d_outline_vertex_shader.vsh \
shaders/area_vertex_shader.vsh \
shaders/arrow3d_fragment_shader.fsh \
shaders/arrow3d_outline_fragment_shader.fsh \
shaders/arrow3d_shadow_fragment_shader.fsh \
shaders/arrow3d_shadow_vertex_shader.vsh \
shaders/arrow3d_vertex_shader.vsh \
shaders/circle_shader.fsh \
shaders/circle_shader.vsh \
shaders/colored_symbol_billboard_shader.vsh \
shaders/colored_symbol_shader.fsh \
shaders/colored_symbol_shader.vsh \
shaders/compass_vertex_shader.vsh \
shaders/dashed_fragment_shader.fsh \
shaders/dashed_vertex_shader.vsh \
shaders/debug_rect_fragment_shader.fsh \
shaders/debug_rect_vertex_shader.vsh \
shaders/discarded_texturing_fragment_shader.fsh \
shaders/hatching_area_fragment_shader.fsh \
shaders/hatching_area_vertex_shader.vsh \
shaders/line_fragment_shader.fsh \
shaders/line_vertex_shader.vsh \
shaders/masked_texturing_billboard_vertex_shader.vsh \
shaders/masked_texturing_fragment_shader.fsh \
shaders/masked_texturing_vertex_shader.vsh \
shaders/my_position_shader.vsh \
shaders/path_symbol_vertex_shader.vsh \
shaders/position_accuracy3d_shader.vsh \
shaders/route_arrow_vertex_shader.vsh \
shaders/route_dash_fragment_shader.fsh \
shaders/route_fragment_shader.fsh \
shaders/route_vertex_shader.vsh \
shaders/ruler_vertex_shader.vsh \
shaders/screen_quad_shader.vsh \
shaders/shader_index.txt \
shaders/solid_color_fragment_shader.fsh \
shaders/text_billboard_vertex_shader.vsh \
shaders/text_fixed_fragment_shader.fsh \
shaders/text_fixed_vertex_shader.vsh \
shaders/text_fragment_shader.fsh \
shaders/text_outlined_billboard_vertex_shader.vsh \
shaders/text_outlined_gui_vertex_shader.vsh \
shaders/text_outlined_vertex_shader.vsh \
shaders/text_vertex_shader.vsh \
shaders/texturing3d_fragment_shader.fsh \
shaders/texturing3d_vertex_shader.vsh \
shaders/texturing_billboard_vertex_shader.vsh \
shaders/texturing_fragment_shader.fsh \
shaders/texturing_vertex_shader.vsh \
shaders/trackpoint_vertex_shader.vsh \
shaders/trackpoint_fragment_shader.fsh \
shaders/traffic_fragment_shader.fsh \
shaders/traffic_vertex_shader.vsh \
shaders/traffic_line_fragment_shader.fsh \
shaders/traffic_line_vertex_shader.vsh \
shaders/user_mark.vsh \
shaders/user_mark_billboard.vsh \

View file

@ -1,6 +1,3 @@
CMDRES = $$system(python ../tools/autobuild/shader_preprocessor.py $$SHADER_COMPILE_ARGS)
!isEmpty($$CMDRES):message($$CMDRES)
INCLUDEPATH *= $$ROOT_DIR/3party/freetype/include
SOURCES += \
@ -33,7 +30,6 @@ SOURCES += \
$$DRAPE_DIR/pointers.cpp \
$$DRAPE_DIR/render_bucket.cpp \
$$DRAPE_DIR/shader.cpp \
$$DRAPE_DIR/shader_def.cpp \
$$DRAPE_DIR/static_texture.cpp \
$$DRAPE_DIR/stipple_pen_resource.cpp \
$$DRAPE_DIR/support_manager.cpp \
@ -77,6 +73,7 @@ HEADERS += \
$$DRAPE_DIR/glyph_manager.hpp \
$$DRAPE_DIR/gpu_buffer.hpp \
$$DRAPE_DIR/gpu_program.hpp \
$$DRAPE_DIR/gpu_program_info.hpp \
$$DRAPE_DIR/gpu_program_manager.hpp \
$$DRAPE_DIR/hw_texture.hpp \
$$DRAPE_DIR/index_buffer.hpp \
@ -90,7 +87,6 @@ HEADERS += \
$$DRAPE_DIR/pointers.hpp \
$$DRAPE_DIR/render_bucket.hpp \
$$DRAPE_DIR/shader.hpp \
$$DRAPE_DIR/shader_def.hpp \
$$DRAPE_DIR/static_texture.hpp \
$$DRAPE_DIR/stipple_pen_resource.hpp \
$$DRAPE_DIR/support_manager.hpp \

View file

@ -6,6 +6,11 @@
namespace dp
{
enum ApiVersion
{
OpenGLES2 = 0,
OpenGLES3
};
enum TextureFormat
{
@ -19,30 +24,23 @@ inline uint8_t GetBytesPerPixel(TextureFormat format)
uint8_t result = 0;
switch (format)
{
case RGBA8:
result = 4;
break;
case ALPHA:
result = 1;
break;
default:
ASSERT(false, ());
break;
case RGBA8: result = 4; break;
case ALPHA: result = 1; break;
default: ASSERT(false, ()); break;
}
return result;
}
enum Anchor
{
Center = 0,
Left = 0x1,
Right = Left << 1,
Top = Right << 1,
Bottom = Top << 1,
LeftTop = Left | Top,
RightTop = Right | Top,
LeftBottom = Left | Bottom,
Center = 0,
Left = 0x1,
Right = Left << 1,
Top = Right << 1,
Bottom = Top << 1,
LeftTop = Left | Top,
RightTop = Right | Top,
LeftBottom = Left | Bottom,
RightBottom = Right | Bottom
};
@ -63,11 +61,9 @@ enum LineJoin
struct FontDecl
{
FontDecl() = default;
FontDecl(Color const & color, float size, bool isSdf = true, Color const & outlineColor = Color::Transparent())
: m_color(color)
, m_outlineColor(outlineColor)
, m_size(size)
, m_isSdf(isSdf)
FontDecl(Color const & color, float size, bool isSdf = true,
Color const & outlineColor = Color::Transparent())
: m_color(color), m_outlineColor(outlineColor), m_size(size), m_isSdf(isSdf)
{
}
@ -76,5 +72,4 @@ struct FontDecl
float m_size = 0;
bool m_isSdf = true;
};
}
} // namespace dp

View file

@ -1,16 +1,8 @@
project(drape_tests)
execute_process(
COMMAND python ${OMIM_ROOT}/tools/autobuild/shader_preprocessor.py
${DRAPE_ROOT}/shaders
shader_index.txt
shader_def
)
add_definitions(
-DOGL_TEST_ENABLED
-DGTEST_DONT_DEFINE_TEST
-DCOMPILER_TESTS
)
include_directories(
@ -26,7 +18,6 @@ set(
bidi_tests.cpp
bingind_info_tests.cpp
buffer_tests.cpp
compile_shaders_test.cpp
dummy_texture.hpp
failure_reporter.cpp
font_texture_tests.cpp

View file

@ -1,11 +1,10 @@
#include "testing/testing.hpp"
#include "drape/drape_tests/memory_comparer.hpp"
#include "testing/testing.hpp"
#include "drape/glconstants.hpp"
#include "drape/batcher.hpp"
#include "drape/glconstants.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/index_storage.hpp"
#include "drape/shader_def.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "drape/drape_tests/glmock_functions.hpp"
@ -15,7 +14,6 @@
#include "std/bind.hpp"
#include "std/cstring.hpp"
#include "std/function.hpp"
#include "std/bind.hpp"
#include <gmock/gmock.h>
@ -51,7 +49,7 @@ public:
template <typename TBatcherCall>
void RunTest(float * vertexes, void * indexes,
uint32_t vertexCount, uint32_t vertexComponentCount,
uint32_t vertexCount, uint8_t vertexComponentCount,
uint32_t indexCount, TBatcherCall const & fn)
{
int const vertexSize = vertexCount * vertexComponentCount;

View file

@ -1,281 +0,0 @@
#include "testing/testing.hpp"
#include "drape/shader_def.hpp"
#include "drape/shader.hpp"
#include "drape/glconstants.hpp"
#include "drape/drape_tests/glmock_functions.hpp"
#include "base/scope_guard.hpp"
#include "platform/platform.hpp"
#include "std/sstream.hpp"
#include "std/target_os.hpp"
#include "std/vector.hpp"
#include "std/string.hpp"
#include <QtCore/QProcess>
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
#include <QTemporaryFile>
#include <gmock/gmock.h>
using testing::Return;
using testing::AnyNumber;
using namespace dp;
#if defined (OMIM_OS_MAC)
#define SHADERS_COMPILER "GLSLESCompiler_Series5.mac"
#define MALI_SHADERS_COMPILER "mali_compiler/malisc"
#define MALI_DIR "mali_compiler/"
#elif defined (OMIM_OS_LINUX)
#define SHADERS_COMPILER "GLSLESCompiler_Series5"
#define MALI_SHADERS_COMPILER "mali_compiler/malisc"
#define MALI_DIR "mali_compiler/"
#elif defined (OMIM_OS_WINDOWS)
#define SHADERS_COMPILER "GLSLESCompiler_Series5.exe"
#else
#error "Define shaders compiler for your platform"
#endif
string DebugPrint(QString const & s)
{
return s.toStdString();
}
struct ShaderEnumGuard
{
ShaderEnumGuard()
{
gpu::InitEnumeration();
}
~ShaderEnumGuard()
{
gpu::VertexEnum.clear();
gpu::FragmentEnum.clear();
}
};
void WriteShaderToFile(QTemporaryFile & file, string shader)
{
EXPECTGL(glGetInteger(gl_const::GLMaxFragmentTextures)).WillRepeatedly(Return(8));
PreprocessShaderSource(shader);
QTextStream out(&file);
out << QString::fromStdString(shader);
}
typedef function<void (QProcess & p)> TPrepareProcessFn;
typedef function<void (QStringList & args, QString const & fileName)> TPrepareArgumentsFn;
typedef function<bool (QString const & output)> TSuccessComparator;
void RunShaderTest(QString const & glslCompiler,
QString const & fileName,
TPrepareProcessFn const & procPrepare,
TPrepareArgumentsFn const & argsPrepare,
TSuccessComparator const & successComparator,
QTextStream & errorLog)
{
QProcess p;
procPrepare(p);
p.setProcessChannelMode(QProcess::MergedChannels);
QStringList args;
argsPrepare(args, fileName);
p.start(glslCompiler, args, QIODevice::ReadOnly);
TEST(p.waitForStarted(), ("GLSL compiler not started"));
TEST(p.waitForFinished(), ("GLSL compiler not finished in time"));
QString result = p.readAllStandardOutput();
if (!successComparator(result))
{
errorLog << "\n" << QString("SHADER COMPILE ERROR\n");
errorLog << fileName << "\n";
errorLog << result.trimmed() << "\n";
}
}
void ForEachShader(string const & defines,
vector<string> const & shaders,
QString const & glslCompiler,
TPrepareProcessFn const & procPrepare,
TPrepareArgumentsFn const & argsPrepare,
TSuccessComparator const & successComparator,
QTextStream & errorLog)
{
for (string src : shaders)
{
QTemporaryFile srcFile;
TEST(srcFile.open(), ("Temporary File can't be created!"));
string fullSrc = defines + src;
WriteShaderToFile(srcFile, fullSrc);
RunShaderTest(glslCompiler, srcFile.fileName(),
procPrepare, argsPrepare, successComparator, errorLog);
}
}
UNIT_TEST(CompileShaders_Test)
{
Platform & platform = GetPlatform();
string glslCompilerPath = platform.ResourcesDir() + "shaders_compiler/" SHADERS_COMPILER;
if (!platform.IsFileExistsByFullPath(glslCompilerPath))
{
glslCompilerPath = platform.WritableDir() + "shaders_compiler/" SHADERS_COMPILER;
TEST(platform.IsFileExistsByFullPath(glslCompilerPath), ("GLSL compiler not found"));
}
QString errorLog;
QTextStream ss(&errorLog);
ShaderEnumGuard guard;
QString compilerPath = QString::fromStdString(glslCompilerPath);
QString shaderType = "-v";
auto argsPrepareFn = [&shaderType] (QStringList & args, QString const & fileName)
{
args << fileName
<< fileName + ".bin"
<< shaderType;
};
auto successComparator = [] (QString const & output) { return output.indexOf("Success") != -1; };
string defines = "";
ForEachShader(defines, gpu::VertexEnum, compilerPath, [] (QProcess const &) {},
argsPrepareFn, successComparator, ss);
shaderType = "-f";
ForEachShader(defines, gpu::FragmentEnum, compilerPath,[] (QProcess const &) {},
argsPrepareFn, successComparator, ss);
TEST_EQUAL(errorLog.isEmpty(), true, ("PVR without defines :", errorLog));
defines = "#define ENABLE_VTF\n";
errorLog.clear();
shaderType = "-v";
ForEachShader(defines, gpu::VertexEnum, compilerPath, [] (QProcess const &) {},
argsPrepareFn, successComparator, ss);
shaderType = "-f";
ForEachShader(defines, gpu::FragmentEnum, compilerPath,[] (QProcess const &) {},
argsPrepareFn, successComparator, ss);
TEST_EQUAL(errorLog.isEmpty(), true, ("PVR with defines : ", defines, "\n", errorLog));
defines = "#define SAMSUNG_GOOGLE_NEXUS\n";
errorLog.clear();
shaderType = "-v";
ForEachShader(defines, gpu::VertexEnum, compilerPath, [] (QProcess const &) {},
argsPrepareFn, successComparator, ss);
shaderType = "-f";
ForEachShader(defines, gpu::FragmentEnum, compilerPath,[] (QProcess const &) {},
argsPrepareFn, successComparator, ss);
TEST_EQUAL(errorLog.isEmpty(), true, ("PVR with defines : ", defines, "\n", errorLog));
}
#ifdef OMIM_OS_MAC
void TestMaliShaders(QString const & driver,
QString const & hardware,
QString const & release)
{
Platform & platform = GetPlatform();
string glslCompilerPath = platform.ResourcesDir() + "shaders_compiler/" MALI_SHADERS_COMPILER;
TEST(platform.IsFileExistsByFullPath(glslCompilerPath), ("GLSL MALI compiler not found"));
QString errorLog;
QTextStream ss(&errorLog);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("MALICM_LOCATION", QString::fromStdString(platform.ResourcesDir() + "shaders_compiler/" MALI_DIR));
auto procPrepare = [&env] (QProcess & p) { p.setProcessEnvironment(env); };
QString shaderType = "-v";
auto argForming = [&] (QStringList & args, QString const & fileName)
{
args << shaderType
<< "-V"
<< "-r"
<< release
<< "-c"
<< hardware
<< "-d"
<< driver
<< fileName;
};
auto succesComparator = [] (QString const & output)
{
return output.indexOf("Compilation succeeded.") != -1;
};
string defines = "";
QString const compilerPath = QString::fromStdString(glslCompilerPath);
ForEachShader(defines, gpu::VertexEnum, compilerPath, procPrepare, argForming, succesComparator, ss);
shaderType = "-f";
ForEachShader(defines, gpu::FragmentEnum, compilerPath, procPrepare, argForming, succesComparator, ss);
TEST(errorLog.isEmpty(), (shaderType, release, hardware, driver, defines, errorLog));
// MALI GPUs do not support ENABLE_VTF. Do not test it here.
}
UNIT_TEST(MALI_CompileShaders_Test)
{
typedef pair<QString, QString> TReleaseVersion;
typedef vector<TReleaseVersion> TReleases;
struct DriverSet
{
TReleases m_releases;
QString m_driverName;
};
vector<DriverSet> models(3);
models[0].m_driverName = "Mali-400_r4p0-00rel1";
models[1].m_driverName = "Mali-T600_r4p0-00rel0";
models[2].m_driverName = "Mali-T600_r4p1-00rel0";
models[0].m_releases.push_back(make_pair("Mali-200", "r0p1"));
models[0].m_releases.push_back(make_pair("Mali-200", "r0p2"));
models[0].m_releases.push_back(make_pair("Mali-200", "r0p3"));
models[0].m_releases.push_back(make_pair("Mali-200", "r0p4"));
models[0].m_releases.push_back(make_pair("Mali-200", "r0p5"));
models[0].m_releases.push_back(make_pair("Mali-200", "r0p6"));
models[0].m_releases.push_back(make_pair("Mali-400", "r0p0"));
models[0].m_releases.push_back(make_pair("Mali-400", "r0p1"));
models[0].m_releases.push_back(make_pair("Mali-400", "r1p0"));
models[0].m_releases.push_back(make_pair("Mali-400", "r1p1"));
models[0].m_releases.push_back(make_pair("Mali-300", "r0p0"));
models[0].m_releases.push_back(make_pair("Mali-450", "r0p0"));
models[1].m_releases.push_back(make_pair("Mali-T600", "r0p0"));
models[1].m_releases.push_back(make_pair("Mali-T600", "r0p0_15dev0"));
models[1].m_releases.push_back(make_pair("Mali-T600", "r0p1"));
models[1].m_releases.push_back(make_pair("Mali-T620", "r0p1"));
models[1].m_releases.push_back(make_pair("Mali-T620", "r1p0"));
models[1].m_releases.push_back(make_pair("Mali-T670", "r1p0"));
models[2].m_releases.push_back(make_pair("Mali-T600", "r0p0"));
models[2].m_releases.push_back(make_pair("Mali-T600", "r0p0_15dev0"));
models[2].m_releases.push_back(make_pair("Mali-T600", "r0p1"));
models[2].m_releases.push_back(make_pair("Mali-T620", "r0p1"));
models[2].m_releases.push_back(make_pair("Mali-T620", "r1p0"));
models[2].m_releases.push_back(make_pair("Mali-T620", "r1p1"));
models[2].m_releases.push_back(make_pair("Mali-T720", "r0p0"));
models[2].m_releases.push_back(make_pair("Mali-T720", "r1p0"));
models[2].m_releases.push_back(make_pair("Mali-T760", "r0p0"));
models[2].m_releases.push_back(make_pair("Mali-T760", "r0p1"));
models[2].m_releases.push_back(make_pair("Mali-T760", "r0p1_50rel0"));
models[2].m_releases.push_back(make_pair("Mali-T760", "r0p2"));
models[2].m_releases.push_back(make_pair("Mali-T760", "r0p3"));
models[2].m_releases.push_back(make_pair("Mali-T760", "r1p0"));
ShaderEnumGuard guard;
for (DriverSet set : models)
{
for (TReleaseVersion version : set.m_releases)
TestMaliShaders(set.m_driverName, version.first, version.second);
}
}
#endif

View file

@ -8,7 +8,6 @@ DEFINES += OGL_TEST_ENABLED GTEST_DONT_DEFINE_TEST COMPILER_TESTS U_DISABLE_RENA
ROOT_DIR = ../..
DEPENDENCIES = qt_tstfrm indexer platform coding geometry base gmock freetype expat stats_client stb_image sdf_image icu
SHADER_COMPILE_ARGS = $$PWD/../shaders shader_index.txt shader_def
include($$ROOT_DIR/common.pri)
QT *= core gui widgets
@ -32,7 +31,6 @@ SOURCES += \
bidi_tests.cpp \
bingind_info_tests.cpp \
buffer_tests.cpp \
compile_shaders_test.cpp \
failure_reporter.cpp \
font_texture_tests.cpp \
glfunctions.cpp \

View file

@ -1,15 +1,17 @@
#include "testing/testing.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/gpu_program.hpp"
#include "drape/shader_def.hpp"
#include "drape/gpu_program_info.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/uniform_value.hpp"
#include "drape/drape_tests/glmock_functions.hpp"
#include "std/cstring.hpp"
#include <cstring>
#include <string>
#include <gmock/gmock.h>
#include <drape/drape_global.hpp>
using ::testing::_;
using ::testing::Return;
@ -77,6 +79,28 @@ void mock_glGetActiveUniform(uint32_t programID,
ASSERT(false, ("Undefined index:", index));
}
class TestShaderMapper : public gpu::GpuProgramGetter
{
public:
TestShaderMapper()
{
m_vertexShader = "void main() { gl_Position = vec4(0.0, 0.0, 0.0, 1.0); }";
m_fragmentShader = "void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); }";
m_info.m_vertexIndex = 0;
m_info.m_fragmentIndex = 1;
m_info.m_textureSlotsCount = 0;
m_info.m_vertexSource = m_vertexShader.c_str();
m_info.m_fragmentSource = m_fragmentShader.c_str();
}
gpu::GpuProgramInfo const & GetProgramInfo(int program) const override
{
return m_info;
}
private:
gpu::GpuProgramInfo m_info;
std::string m_vertexShader;
std::string m_fragmentShader;
};
} // namespace
UNIT_TEST(UniformValueTest)
@ -101,13 +125,13 @@ UNIT_TEST(UniformValueTest)
{
InSequence seq;
EXPECTGL(glGetInteger(gl_const::GLMaxVertexTextures)).Times(1);
// vertexShader->Ref()
EXPECTGL(glCreateShader(gl_const::GLVertexShader)).WillOnce(Return(VertexShaderID));
EXPECTGL(glShaderSource(VertexShaderID, _)).Times(1);
EXPECTGL(glCompileShader(VertexShaderID, _)).WillOnce(Return(true));
// fragmentShader->Ref()
EXPECTGL(glCreateShader(gl_const::GLFragmentShader)).WillOnce(Return(FragmentShaderID));
//EXPECTGL(glGetInteger(gl_const::GLMaxFragmentTextures)).WillOnce(Return(8));
EXPECTGL(glShaderSource(FragmentShaderID, _)).Times(1);
EXPECTGL(glCompileShader(FragmentShaderID, _)).WillOnce(Return(true));
@ -154,7 +178,8 @@ UNIT_TEST(UniformValueTest)
}
drape_ptr<GpuProgramManager> manager = make_unique_dp<GpuProgramManager>();
ref_ptr<GpuProgram> program = manager->GetProgram(gpu::TEXTURING_PROGRAM);
manager->Init(make_unique_dp<TestShaderMapper>());
ref_ptr<GpuProgram> program = manager->GetProgram(0);
program->Bind();

View file

@ -1,23 +1,17 @@
#include "drape/gpu_program.hpp"
#include "drape/glfunctions.hpp"
#include "drape/glstate.hpp"
#include "drape/shader_def.hpp"
#include "drape/support_manager.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#ifdef DEBUG
#include "std/map.hpp"
#endif
namespace dp
{
GpuProgram::GpuProgram(int programIndex, ref_ptr<Shader> vertexShader, ref_ptr<Shader> fragmentShader)
GpuProgram::GpuProgram(int programIndex, ref_ptr<Shader> vertexShader,
ref_ptr<Shader> fragmentShader, uint8_t textureSlotsCount)
: m_vertexShader(vertexShader)
, m_fragmentShader(fragmentShader)
, m_textureSlotsCount(gpu::GetTextureSlotsCount(programIndex))
, m_textureSlotsCount(textureSlotsCount)
{
m_programID = GLFunctions::glCreateProgram();
GLFunctions::glAttachShader(m_programID, m_vertexShader->GetID());
@ -27,8 +21,7 @@ GpuProgram::GpuProgram(int programIndex, ref_ptr<Shader> vertexShader, ref_ptr<S
if (!GLFunctions::glLinkProgram(m_programID, errorLog))
LOG(LERROR, ("Program ", m_programID, " link error = ", errorLog));
// originaly i detached shaders there, but then i try it on Tegra3 device.
// on Tegra3, glGetActiveUniform will not work if you detach shaders after linking
// On Tegra3 glGetActiveUniform isn't work if you detach shaders after linking.
LoadUniformLocations();
// On Tegra2 we cannot detach shaders at all.
@ -71,12 +64,12 @@ void GpuProgram::Unbind()
GLFunctions::glUseProgram(0);
}
int8_t GpuProgram::GetAttributeLocation(string const & attributeName) const
int8_t GpuProgram::GetAttributeLocation(std::string const & attributeName) const
{
return GLFunctions::glGetAttribLocation(m_programID, attributeName);
}
int8_t GpuProgram::GetUniformLocation(string const & uniformName) const
int8_t GpuProgram::GetUniformLocation(std::string const & uniformName) const
{
auto const it = m_uniforms.find(uniformName);
if (it == m_uniforms.end())
@ -92,10 +85,9 @@ void GpuProgram::LoadUniformLocations()
{
int32_t size = 0;
glConst type = gl_const::GLFloatVec4;
string name;
std::string name;
GLFunctions::glGetActiveUniform(m_programID, i, &size, &type, name);
m_uniforms[name] = GLFunctions::glGetUniformLocation(m_programID, name);
}
}
} // namespace dp
} // namespace dp

View file

@ -1,30 +1,26 @@
#pragma once
#include "drape/shader.hpp"
#include "drape/pointers.hpp"
#include "drape/glconstants.hpp"
#include "drape/pointers.hpp"
#include "drape/shader.hpp"
#include "std/string.hpp"
#ifdef DEBUG
#include "std/unique_ptr.hpp"
#endif
#include <map>
#include <string>
namespace dp
{
class GpuProgram
{
public:
GpuProgram(int programIndex, ref_ptr<Shader> vertexShader,
ref_ptr<Shader> fragmentShader);
GpuProgram(int programIndex, ref_ptr<Shader> vertexShader, ref_ptr<Shader> fragmentShader,
uint8_t textureSlotsCount);
~GpuProgram();
void Bind();
void Unbind();
int8_t GetAttributeLocation(string const & attributeName) const;
int8_t GetUniformLocation(string const & uniformName) const;
int8_t GetAttributeLocation(std::string const & attributeName) const;
int8_t GetUniformLocation(std::string const & uniformName) const;
private:
void LoadUniformLocations();
@ -35,10 +31,9 @@ private:
ref_ptr<Shader> m_vertexShader;
ref_ptr<Shader> m_fragmentShader;
using TUniformLocations = map<string, int8_t>;
using TUniformLocations = std::map<std::string, int8_t>;
TUniformLocations m_uniforms;
uint8_t const m_textureSlotsCount;
};
} // namespace dp
} // namespace dp

View file

@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include <string>
namespace gpu
{
struct GpuProgramInfo
{
GpuProgramInfo() = default;
GpuProgramInfo(int vertexIndex, int fragmentIndex, char const * vertexSource,
char const * fragmentSource, uint8_t textureSlotsCount)
: m_vertexIndex(vertexIndex)
, m_fragmentIndex(fragmentIndex)
, m_vertexSource(vertexSource)
, m_fragmentSource(fragmentSource)
, m_textureSlotsCount(textureSlotsCount)
{}
int m_vertexIndex = -1;
int m_fragmentIndex = -1;
char const * m_vertexSource = nullptr;
char const * m_fragmentSource = nullptr;
uint8_t m_textureSlotsCount = 0;
};
class GpuProgramGetter
{
public:
virtual ~GpuProgramGetter() {}
virtual gpu::GpuProgramInfo const & GetProgramInfo(int program) const = 0;
};
} // namespace gpu

View file

@ -1,55 +1,30 @@
#include "drape/gpu_program_manager.hpp"
#include "drape/shader_def.hpp"
#include "drape/glfunctions.hpp"
#include "drape/support_manager.hpp"
#include "base/stl_add.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include "base/stl_add.hpp"
namespace dp
{
namespace
{
class ShaderMapper
{
public:
ShaderMapper()
{
gpu::InitGpuProgramsLib(m_mapping);
}
gpu::ProgramInfo const & GetShaders(int program) const
{
map<int, gpu::ProgramInfo>::const_iterator it = m_mapping.find(program);
ASSERT(it != m_mapping.end(), ());
return it->second;
}
private:
map<int, gpu::ProgramInfo> m_mapping;
};
static ShaderMapper s_mapper;
} // namespace
GpuProgramManager::~GpuProgramManager()
{
m_programs.clear();
m_shaders.clear();
}
void GpuProgramManager::Init()
void GpuProgramManager::Init(drape_ptr<gpu::GpuProgramGetter> && programGetter)
{
m_programGetter = std::move(programGetter);
ASSERT(m_programGetter != nullptr, ());
// This feature is not supported on some Android devices (especially on Android 4.x version).
// Since we can't predict on which devices it'll work fine, we have to turn off for all devices.
#if !defined(OMIM_OS_ANDROID)
if (GLFunctions::glGetInteger(gl_const::GLMaxVertexTextures) > 0)
{
LOG(LINFO, ("VTF enabled"));
m_globalDefines.append("#define ENABLE_VTF\n"); // VTF == Vetrex Texture Fetch
m_globalDefines.append("#define ENABLE_VTF\n"); // VTF == Vetrex Texture Fetch
}
#endif
@ -59,19 +34,18 @@ void GpuProgramManager::Init()
ref_ptr<GpuProgram> GpuProgramManager::GetProgram(int index)
{
program_map_t::iterator it = m_programs.find(index);
auto it = m_programs.find(index);
if (it != m_programs.end())
return make_ref(it->second);
gpu::ProgramInfo const & programInfo = s_mapper.GetShaders(index);
ref_ptr<Shader> vertexShader = GetShader(programInfo.m_vertexIndex,
programInfo.m_vertexSource,
Shader::VertexShader);
ref_ptr<Shader> fragmentShader = GetShader(programInfo.m_fragmentIndex,
programInfo.m_fragmentSource,
Shader::FragmentShader);
auto const & programInfo = m_programGetter->GetProgramInfo(index);
auto vertexShader = GetShader(programInfo.m_vertexIndex, programInfo.m_vertexSource,
Shader::Type::VertexShader);
auto fragmentShader = GetShader(programInfo.m_fragmentIndex, programInfo.m_fragmentSource,
Shader::Type::FragmentShader);
drape_ptr<GpuProgram> program = make_unique_dp<GpuProgram>(index, vertexShader, fragmentShader);
drape_ptr<GpuProgram> program = make_unique_dp<GpuProgram>(index, vertexShader, fragmentShader,
programInfo.m_textureSlotsCount);
ref_ptr<GpuProgram> result = make_ref(program);
m_programs.emplace(index, move(program));
@ -80,15 +54,13 @@ ref_ptr<GpuProgram> GpuProgramManager::GetProgram(int index)
ref_ptr<Shader> GpuProgramManager::GetShader(int index, string const & source, Shader::Type t)
{
shader_map_t::iterator it = m_shaders.find(index);
if (it == m_shaders.end())
{
drape_ptr<Shader> shader = make_unique_dp<Shader>(source, m_globalDefines, t);
ref_ptr<Shader> result = make_ref(shader);
m_shaders.emplace(index, move(shader));
return result;
}
return make_ref(it->second);
}
auto it = m_shaders.find(index);
if (it != m_shaders.end())
return make_ref(it->second);
} // namespace dp
drape_ptr<Shader> shader = make_unique_dp<Shader>(source, m_globalDefines, t);
ref_ptr<Shader> result = make_ref(shader);
m_shaders.emplace(index, move(shader));
return result;
}
} // namespace dp

View file

@ -2,32 +2,36 @@
#include "drape/pointers.hpp"
#include "drape/gpu_program.hpp"
#include "drape/gpu_program_info.hpp"
#include "drape/shader.hpp"
#include "std/map.hpp"
#include "std/noncopyable.hpp"
#include "base/macros.hpp"
#include <map>
#include <string>
namespace dp
{
class GpuProgramManager : public noncopyable
class GpuProgramManager
{
public:
GpuProgramManager() = default;
~GpuProgramManager();
void Init();
void Init(drape_ptr<gpu::GpuProgramGetter> && programGetter);
ref_ptr<GpuProgram> GetProgram(int index);
private:
ref_ptr<Shader> GetShader(int index, string const & source, Shader::Type t);
private:
typedef map<int, drape_ptr<GpuProgram> > program_map_t;
typedef map<int, drape_ptr<Shader> > shader_map_t;
program_map_t m_programs;
shader_map_t m_shaders;
string m_globalDefines;
};
using ProgramMap = std::map<int, drape_ptr<GpuProgram>>;
using ShaderMap = std::map<int, drape_ptr<Shader>>;
ProgramMap m_programs;
ShaderMap m_shaders;
std::string m_globalDefines;
drape_ptr<gpu::GpuProgramGetter> m_programGetter;
} // namespace dp
DISALLOW_COPY_AND_MOVE(GpuProgramManager);
};
} // namespace dp

View file

@ -1,87 +1,28 @@
#include "drape/shader.hpp"
#include "drape/shader_def.hpp"
#include "drape/glfunctions.hpp"
#include "base/assert.hpp"
#include "base/string_utils.hpp"
#include "std/algorithm.hpp"
namespace dp
{
using strings::to_string;
namespace
{
glConst convert(Shader::Type t)
glConst ConvertType(Shader::Type t)
{
if (t == Shader::VertexShader)
if (t == Shader::Type::VertexShader)
return gl_const::GLVertexShader;
return gl_const::GLFragmentShader;
}
} // namespace
void ResolveGetTexel(string & result, string const & sampler, int count)
{
string const index = "index";
string const answer = "answer";
string const texIndex = "texIndex";
string const texCoord = "texCoord";
result.reserve(250 + 130 * count);
for (int i = 0; i < count; ++i)
{
string const number = to_string(i);
result.append("const int ").append(index).append(number).append(" = ").append(number).append(";\n");
}
result.append("uniform sampler2D u_textures[").append(to_string(count)).append("];\n");
// Function signature
result.append(LOW_P).append(" vec4 getTexel(int ").append(texIndex).append(", ")
.append(MAXPREC_P).append(" vec2 ").append(texCoord).append("){ \n");
// Declare result var;
result.append(LOW_P).append(" vec4 ").append(answer).append(";\n");
for (int i = 0; i < count; ++i)
{
string constIndex = index + to_string(i);
if (i != 0)
result.append("else ");
result.append("if (").append(texIndex).append("==").append(constIndex).append(")\n");
result.append(answer).append("=texture2D(")
.append(sampler).append("[").append(constIndex).append("],")
.append(texCoord).append(");\n");
}
result.append("return ").append(answer).append(";}");
}
}
void PreprocessShaderSource(string & src)
{
string const replacement("~getTexel~");
auto const pos = src.find(replacement);
if (pos == string::npos)
return;
string injector = "";
int const count = min(8, GLFunctions::glGetInteger(gl_const::GLMaxFragmentTextures));
ResolveGetTexel(injector, "u_textures", count);
src.replace(pos, replacement.length(), injector);
}
Shader::Shader(string const & shaderSource, string const & defines, Type type)
Shader::Shader(std::string const & shaderSource, std::string const & defines, Type type)
: m_glID(0)
{
m_glID = GLFunctions::glCreateShader(convert(type));
string source = shaderSource;
PreprocessShaderSource(source);
GLFunctions::glShaderSource(m_glID, source, defines);
string errorLog;
bool result = GLFunctions::glCompileShader(m_glID, errorLog);
m_glID = GLFunctions::glCreateShader(ConvertType(type));
GLFunctions::glShaderSource(m_glID, shaderSource, defines);
std::string errorLog;
bool const result = GLFunctions::glCompileShader(m_glID, errorLog);
CHECK(result, ("Shader compile error : ", errorLog));
}
@ -90,9 +31,8 @@ Shader::~Shader()
GLFunctions::glDeleteShader(m_glID);
}
int Shader::GetID() const
uint32_t Shader::GetID() const
{
return m_glID;
}
} // namespace dp
} // namespace dp

View file

@ -1,31 +1,25 @@
#pragma once
#include "drape/glfunctions.hpp"
#include "std/string.hpp"
#include "std/cstdint.hpp"
#include <cstdint>
#include <string>
namespace dp
{
class Shader
{
public:
enum Type
enum class Type
{
VertexShader,
FragmentShader
};
Shader(string const & shaderSource, string const & defines, Type type);
Shader(std::string const & shaderSource, std::string const & defines, Type type);
~Shader();
int GetID() const;
uint32_t GetID() const;
private:
uint32_t m_glID;
};
void PreprocessShaderSource(string & src);
} // namespace dp
} // namespace dp

View file

@ -1,25 +0,0 @@
varying vec2 v_intensity;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
void main()
{
#ifdef SAMSUNG_GOOGLE_NEXUS
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
const float kFakeColorScalar = 0.0;
lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar;
#endif
float alpha = smoothstep(0.8, 1.0, v_intensity.y);
vec4 resColor = vec4((v_intensity.x * 0.5 + 0.5) * u_color.rgb, u_color.a * alpha);
#ifdef SAMSUNG_GOOGLE_NEXUS
gl_FragColor = resColor + fakeColor;
#else
gl_FragColor = resColor;
#endif
}

View file

@ -1,24 +0,0 @@
varying float v_intensity;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
void main()
{
#ifdef SAMSUNG_GOOGLE_NEXUS
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
const float kFakeColorScalar = 0.0;
lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar;
#endif
vec4 resColor = vec4(u_color.rgb, u_color.a * smoothstep(0.7, 1.0, v_intensity));
#ifdef SAMSUNG_GOOGLE_NEXUS
gl_FragColor = resColor + fakeColor;
#else
gl_FragColor = resColor;
#endif
}

View file

@ -1,24 +0,0 @@
varying float v_intensity;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
void main()
{
#ifdef SAMSUNG_GOOGLE_NEXUS
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
const float kFakeColorScalar = 0.0;
lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar;
#endif
vec4 resColor = vec4(u_color.rgb, u_color.a * v_intensity);
#ifdef SAMSUNG_GOOGLE_NEXUS
gl_FragColor = resColor + fakeColor;
#else
gl_FragColor = resColor;
#endif
}

View file

@ -1,6 +0,0 @@
uniform vec4 u_color;
void main(void)
{
gl_FragColor = u_color;
}

View file

@ -1,40 +0,0 @@
varying vec3 v_length;
varying vec4 v_color;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
uniform vec2 u_pattern;
const float kAntialiasingThreshold = 0.92;
float GetAlphaFromPattern(float curLen, float dashLen, float gapLen)
{
float len = dashLen + gapLen;
float offset = fract(curLen / len) * len;
return step(offset, dashLen);
}
void main(void)
{
#ifdef SAMSUNG_GOOGLE_NEXUS
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
const float kFakeColorScalar = 0.0;
lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar;
#endif
vec4 color = u_color;
if (v_length.x < v_length.z)
color.a = 0.0;
else
color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y))) *
GetAlphaFromPattern(v_length.x, u_pattern.x, u_pattern.y);
#ifdef SAMSUNG_GOOGLE_NEXUS
gl_FragColor = color + fakeColor;
#else
gl_FragColor = color;
#endif
}

View file

@ -1,39 +0,0 @@
TEXTURING_PROGRAM texturing_vertex_shader.vsh texturing_fragment_shader.fsh
MASKED_TEXTURING_PROGRAM masked_texturing_vertex_shader.vsh masked_texturing_fragment_shader.fsh
COLORED_SYMBOL_PROGRAM colored_symbol_shader.vsh colored_symbol_shader.fsh
TEXT_OUTLINED_PROGRAM text_outlined_vertex_shader.vsh text_fragment_shader.fsh
TEXT_PROGRAM text_vertex_shader.vsh text_fragment_shader.fsh
TEXT_FIXED_PROGRAM text_vertex_shader.vsh text_fixed_fragment_shader.fsh
TEXT_OUTLINED_GUI_PROGRAM text_outlined_gui_vertex_shader.vsh text_fragment_shader.fsh
AREA_PROGRAM area_vertex_shader.vsh solid_color_fragment_shader.fsh
HATCHING_AREA_PROGRAM hatching_area_vertex_shader.vsh hatching_area_fragment_shader.fsh
AREA_OUTLINE_PROGRAM area_vertex_shader.vsh solid_color_fragment_shader.fsh
AREA_3D_PROGRAM area3d_vertex_shader.vsh texturing3d_fragment_shader.fsh
AREA_3D_OUTLINE_PROGRAM area3d_outline_vertex_shader.vsh solid_color_fragment_shader.fsh
LINE_PROGRAM line_vertex_shader.vsh line_fragment_shader.fsh
CAP_JOIN_PROGRAM circle_shader.vsh circle_shader.fsh
DASHED_LINE_PROGRAM dashed_vertex_shader.vsh dashed_fragment_shader.fsh
PATH_SYMBOL_LINE path_symbol_vertex_shader.vsh texturing_fragment_shader.fsh
TEXTURING_GUI_PROGRAM texturing_gui_vertex_shader.vsh texturing_fragment_shader.fsh
RULER_PROGRAM ruler_vertex_shader.vsh texturing_fragment_shader.fsh
ACCURACY_PROGRAM position_accuracy3d_shader.vsh texturing_fragment_shader.fsh
MY_POSITION_PROGRAM my_position_shader.vsh texturing_fragment_shader.fsh
BOOKMARK_PROGRAM user_mark.vsh texturing_fragment_shader.fsh
ROUTE_PROGRAM route_vertex_shader.vsh route_fragment_shader.fsh
ROUTE_DASH_PROGRAM route_vertex_shader.vsh route_dash_fragment_shader.fsh
ROUTE_ARROW_PROGRAM route_arrow_vertex_shader.vsh discarded_texturing_fragment_shader.fsh
TRACK_POINT_PROGRAM trackpoint_vertex_shader.vsh trackpoint_fragment_shader.fsh
DEBUG_RECT_PROGRAM debug_rect_vertex_shader.vsh debug_rect_fragment_shader.fsh
SCREEN_QUAD_PROGRAM screen_quad_shader.vsh texturing_fragment_shader.fsh
ARROW_3D_PROGRAM arrow3d_vertex_shader.vsh arrow3d_fragment_shader.fsh
ARROW_3D_SHADOW_PROGRAM arrow3d_shadow_vertex_shader.vsh arrow3d_shadow_fragment_shader.fsh
ARROW_3D_OUTLINE_PROGRAM arrow3d_shadow_vertex_shader.vsh arrow3d_outline_fragment_shader.fsh
COLORED_SYMBOL_BILLBOARD_PROGRAM colored_symbol_billboard_shader.vsh colored_symbol_shader.fsh
TEXTURING_BILLBOARD_PROGRAM texturing_billboard_vertex_shader.vsh texturing_fragment_shader.fsh
MASKED_TEXTURING_BILLBOARD_PROGRAM masked_texturing_billboard_vertex_shader.vsh masked_texturing_fragment_shader.fsh
TEXT_OUTLINED_BILLBOARD_PROGRAM text_outlined_billboard_vertex_shader.vsh text_fragment_shader.fsh
TEXT_BILLBOARD_PROGRAM text_billboard_vertex_shader.vsh text_fragment_shader.fsh
TEXT_FIXED_BILLBOARD_PROGRAM text_billboard_vertex_shader.vsh text_fixed_fragment_shader.fsh
BOOKMARK_BILLBOARD_PROGRAM user_mark_billboard.vsh texturing_fragment_shader.fsh
TRAFFIC_PROGRAM traffic_vertex_shader.vsh traffic_fragment_shader.fsh
TRAFFIC_LINE_PROGRAM traffic_line_vertex_shader.vsh traffic_line_fragment_shader.fsh

View file

@ -1,45 +0,0 @@
attribute vec4 a_position;
attribute vec2 a_normal;
attribute vec2 a_colorTexCoord;
attribute vec2 a_outlineColorTexCoord;
attribute vec2 a_maskTexCoord;
uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;
uniform float u_isOutlinePass;
#ifdef ENABLE_VTF
uniform sampler2D u_colorTex;
varying lowp vec4 v_color;
#else
varying vec2 v_colorTexCoord;
#endif
varying vec2 v_maskTexCoord;
const float Zero = 0.0;
const float One = 1.0;
const float BaseDepthShift = -10.0;
void main()
{
float isOutline = step(0.5, u_isOutlinePass);
float notOutline = One - isOutline;
float depthShift = BaseDepthShift * isOutline;
vec4 pos = (vec4(a_position.xyz, 1) + vec4(Zero, Zero, depthShift, Zero)) * modelView;
vec4 shiftedPos = vec4(a_normal, Zero, Zero) + pos;
shiftedPos = shiftedPos * projection;
float w = shiftedPos.w;
shiftedPos.xyw = (pivotTransform * vec4(shiftedPos.xy, 0.0, w)).xyw;
shiftedPos.z *= shiftedPos.w / w;
gl_Position = shiftedPos;
vec2 colorTexCoord = a_colorTexCoord * notOutline + a_outlineColorTexCoord * isOutline;
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, colorTexCoord);
#else
v_colorTexCoord = colorTexCoord;
#endif
v_maskTexCoord = a_maskTexCoord;
}

View file

@ -1,27 +0,0 @@
attribute vec4 a_position;
attribute vec2 a_normal;
attribute vec2 a_colorTexCoords;
uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;
uniform float zScale;
varying vec2 v_colorTexCoords;
void main(void)
{
vec4 pivot = vec4(a_position.xyz, 1.0) * modelView;
vec4 offset = vec4(a_normal, 0.0, 0.0) * projection;
float pivotZ = a_position.w;
vec4 projectedPivot = pivot * projection;
float logicZ = projectedPivot.z / projectedPivot.w;
vec4 transformedPivot = pivotTransform * vec4(projectedPivot.xy, pivotZ * zScale, projectedPivot.w);
vec4 scale = pivotTransform * vec4(1.0, -1.0, 0.0, 1.0);
gl_Position = vec4(transformedPivot.xy / transformedPivot.w, logicZ, 1.0) + vec4(offset.xy / scale.w * scale.x, 0.0, 0.0);
v_colorTexCoords = a_colorTexCoords;
}

View file

@ -1,35 +0,0 @@
attribute vec3 a_normal;
attribute vec3 a_position;
attribute vec4 a_color;
uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
varying lowp vec4 v_fakeColor;
#endif
varying vec3 v_radius;
varying vec4 v_color;
void main(void)
{
vec3 radius = a_normal * a_position.z;
vec4 pos = vec4(a_position.xy, 0, 1) * modelView;
vec4 shiftedPos = vec4(radius.xy, 0, 0) + pos;
vec4 finalPos = shiftedPos * projection;
float w = finalPos.w;
finalPos.xyw = (pivotTransform * vec4(finalPos.xy, 0.0, w)).xyw;
finalPos.z *= finalPos.w / w;
gl_Position = finalPos;
v_radius = radius;
v_color = a_color;
#ifdef SAMSUNG_GOOGLE_NEXUS
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
v_fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0));
#endif
}

View file

@ -1,5 +1,14 @@
project(drape_frontend)
execute_process(
COMMAND python ${OMIM_ROOT}/tools/autobuild/shader_preprocessor.py
${OMIM_ROOT}/drape_frontend/shaders
shader_index.txt
shaders_lib.glsl
${OMIM_ROOT}/drape_frontend
shader_def
)
include_directories(
.
watch
@ -166,6 +175,8 @@ set(
screen_quad_renderer.hpp
selection_shape.cpp
selection_shape.hpp
shader_def.cpp
shader_def.hpp
shape_view_params.hpp
stylist.cpp
stylist.hpp
@ -229,4 +240,66 @@ set(
add_library(${PROJECT_NAME} ${SRC})
set(
DRAPE_SHADERS_SRC
shaders/area.vsh.glsl
shaders/area3d.vsh.glsl
shaders/area3d_outline.vsh.glsl
shaders/arrow3d.fsh.glsl
shaders/arrow3d.vsh.glsl
shaders/arrow3d_outline.fsh.glsl
shaders/arrow3d_shadow.fsh.glsl
shaders/arrow3d_shadow.vsh.glsl
shaders/circle.fsh.glsl
shaders/circle.vsh.glsl
shaders/colored_symbol.fsh.glsl
shaders/colored_symbol.vsh.glsl
shaders/colored_symbol_billboard.vsh.glsl
shaders/dashed_line.fsh.glsl
shaders/dashed_line.vsh.glsl
shaders/debug_rect.fsh.glsl
shaders/debug_rect.vsh.glsl
shaders/discarded_texturing.fsh.glsl
shaders/hatching_area.fsh.glsl
shaders/hatching_area.vsh.glsl
shaders/line.fsh.glsl
shaders/line.vsh.glsl
shaders/masked_texturing.fsh.glsl
shaders/masked_texturing.vsh.glsl
shaders/masked_texturing_billboard.vsh.glsl
shaders/my_position.vsh.glsl
shaders/path_symbol.vsh.glsl
shaders/position_accuracy3d.vsh.glsl
shaders/route.fsh.glsl
shaders/route.vsh.glsl
shaders/route_arrow.vsh.glsl
shaders/route_dash.fsh.glsl
shaders/ruler.vsh.glsl
shaders/screen_quad.vsh.glsl
shaders/shader_index.txt
shaders/shaders_lib.glsl
shaders/solid_color.fsh.glsl
shaders/text.fsh.glsl
shaders/text.vsh.glsl
shaders/text_billboard.vsh.glsl
shaders/text_fixed.fsh.glsl
shaders/text_outlined.vsh.glsl
shaders/text_outlined_billboard.vsh.glsl
shaders/text_outlined_gui.vsh.glsl
shaders/texturing.fsh.glsl
shaders/texturing.vsh.glsl
shaders/texturing3d.fsh.glsl
shaders/texturing_billboard.vsh.glsl
shaders/texturing_gui.vsh.glsl
shaders/trackpoint.fsh.glsl
shaders/trackpoint.vsh.glsl
shaders/traffic.fsh.glsl
shaders/traffic.vsh.glsl
shaders/traffic_line.fsh.glsl
shaders/traffic_line.vsh.glsl
shaders/user_mark.vsh.glsl
shaders/user_mark_billboard.vsh.glsl
)
add_custom_target(shaders SOURCES ${DRAPE_SHADERS_SRC})
omim_add_test_subdirectory(drape_frontend_tests)

View file

@ -1,9 +1,9 @@
#include "drape_frontend/area_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/shader_def.hpp"
#include "drape/glstate.hpp"
#include "drape/batcher.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/batcher.hpp"
#include "drape/glstate.hpp"
#include "drape/texture_manager.hpp"
#include "drape/utils/vertex_decl.hpp"

View file

@ -1,6 +1,7 @@
#include "drape_frontend/arrow3d.hpp"
#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/glconstants.hpp"
@ -10,7 +11,6 @@
#include "drape/glsl_types.hpp"
#include "drape/glstate.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/shader_def.hpp"
#include "drape/texture_manager.hpp"
#include "drape/uniform_values_storage.hpp"

View file

@ -1,4 +1,5 @@
#include "drape_frontend/colored_symbol_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/attribute_provider.hpp"
@ -7,7 +8,6 @@
#include "drape/glsl_types.hpp"
#include "drape/glstate.hpp"
#include "drape/overlay_handle.hpp"
#include "drape/shader_def.hpp"
#include "drape/texture_manager.hpp"
#include "drape/utils/vertex_decl.hpp"

View file

@ -1,8 +1,8 @@
#include "drape_frontend/drape_api_renderer.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/shader_def.hpp"
#include "drape/overlay_handle.hpp"
#include "drape/vertex_array_buffer.hpp"

View file

@ -2,6 +2,10 @@ TARGET = drape_frontend
TEMPLATE = lib
CONFIG += staticlib
SHADER_COMPILE_ARGS = $$PWD/shaders shader_index.txt shaders_lib.glsl $$PWD shader_def
CMDRES = $$system(python $$PWD/../tools/autobuild/shader_preprocessor.py $$SHADER_COMPILE_ARGS)
!isEmpty($$CMDRES):message($$CMDRES)
ROOT_DIR = ..
include($$ROOT_DIR/common.pri)
@ -82,6 +86,7 @@ SOURCES += \
screen_operations.cpp \
screen_quad_renderer.cpp \
selection_shape.cpp \
shader_def.cpp \
stylist.cpp \
text_handle.cpp \
text_layout.cpp \
@ -191,6 +196,7 @@ HEADERS += \
screen_operations.hpp \
screen_quad_renderer.hpp \
selection_shape.hpp \
shader_def.hpp \
shape_view_params.hpp \
stylist.hpp \
text_handle.hpp \
@ -227,3 +233,62 @@ HEADERS += \
watch/brush_info.hpp \
watch/geometry_processors.hpp \
watch/feature_processor.hpp \
OTHER_FILES += \
shaders/area.vsh.glsl \
shaders/area3d.vsh.glsl \
shaders/area3d_outline.vsh.glsl \
shaders/arrow3d.fsh.glsl \
shaders/arrow3d.vsh.glsl \
shaders/arrow3d_outline.fsh.glsl \
shaders/arrow3d_shadow.fsh.glsl \
shaders/arrow3d_shadow.vsh.glsl \
shaders/circle.fsh.glsl \
shaders/circle.vsh.glsl \
shaders/colored_symbol.fsh.glsl \
shaders/colored_symbol.vsh.glsl \
shaders/colored_symbol_billboard.vsh.glsl \
shaders/dashed_line.fsh.glsl \
shaders/dashed_line.vsh.glsl \
shaders/debug_rect.fsh.glsl \
shaders/debug_rect.vsh.glsl \
shaders/discarded_texturing.fsh.glsl \
shaders/hatching_area.fsh.glsl \
shaders/hatching_area.vsh.glsl \
shaders/line.fsh.glsl \
shaders/line.vsh.glsl \
shaders/masked_texturing.fsh.glsl \
shaders/masked_texturing.vsh.glsl \
shaders/masked_texturing_billboard.vsh.glsl \
shaders/my_position.vsh.glsl \
shaders/path_symbol.vsh.glsl \
shaders/position_accuracy3d.vsh.glsl \
shaders/route.fsh.glsl \
shaders/route.vsh.glsl \
shaders/route_arrow.vsh.glsl \
shaders/route_dash.fsh.glsl \
shaders/ruler.vsh.glsl \
shaders/screen_quad.vsh.glsl \
shaders/shader_index.txt \
shaders/shaders_lib.glsl \
shaders/solid_color.fsh.glsl \
shaders/text.fsh.glsl \
shaders/text.vsh.glsl \
shaders/text_billboard.vsh.glsl \
shaders/text_fixed.fsh.glsl \
shaders/text_outlined.vsh.glsl \
shaders/text_outlined_billboard.vsh.glsl \
shaders/text_outlined_gui.vsh.glsl \
shaders/texturing.fsh.glsl \
shaders/texturing.vsh.glsl \
shaders/texturing3d.fsh.glsl \
shaders/texturing_billboard.vsh.glsl \
shaders/texturing_gui.vsh.glsl \
shaders/trackpoint.fsh.glsl \
shaders/trackpoint.vsh.glsl \
shaders/traffic.fsh.glsl \
shaders/traffic.vsh.glsl \
shaders/traffic_line.fsh.glsl \
shaders/traffic_line.vsh.glsl \
shaders/user_mark.vsh.glsl \
shaders/user_mark_billboard.vsh.glsl \

View file

@ -1,9 +1,33 @@
project(drape_frontend_tests)
add_definitions(
-DCOMPILER_TESTS
)
execute_process(
COMMAND python ${OMIM_ROOT}/tools/autobuild/shader_preprocessor.py
${OMIM_ROOT}/drape_frontend/shaders
shader_index.txt
shaders_lib.glsl
${OMIM_ROOT}/drape_frontend/drape_frontend_tests
shader_def_for_tests
)
execute_process(
COMMAND rm -rf ${OMIM_ROOT}/data/shaders_compiler
)
execute_process(
COMMAND cp -r ${OMIM_ROOT}/tools/shaders_compiler ${OMIM_ROOT}/data
)
set(
SRC
compile_shaders_test.cpp
navigator_test.cpp
object_pool_tests.cpp
shader_def_for_tests.cpp
shader_def_for_tests.hpp
user_event_stream_tests.cpp
)

View file

@ -0,0 +1,281 @@
#include "testing/testing.hpp"
#include "drape_frontend/drape_frontend_tests/shader_def_for_tests.hpp"
#include "platform/platform.hpp"
#include "coding/file_name_utils.hpp"
#include <functional>
#include <sstream>
#include <string>
#include <vector>
#include <QTemporaryFile>
#include <QtCore/QDebug>
#include <QtCore/QProcess>
#include <QtCore/QTextStream>
#if defined(OMIM_OS_MAC)
std::string const kCompilersDir = "shaders_compiler";
std::string const kMaliCompilerOpenGLES2Dir = "mali_compiler";
std::string const kMaliCompilerOpenGLES3Dir = "mali_compiler_es3";
std::string const kCompilerOpenGLES2 = "GLSLESCompiler_Series5.mac";
std::string const kCompilerMaliOpenGLES2 = kMaliCompilerOpenGLES2Dir + "/malisc";
std::string const kCompilerOpenGLES3 = "GLSLESCompiler_Series6.mac";
std::string const kCompilerMaliOpenGLES3 = kMaliCompilerOpenGLES3Dir + "/malisc";
std::string DebugPrint(QString const & s) { return s.toStdString(); }
std::string DebugPrint(dp::ApiVersion apiVersion)
{
if (apiVersion == dp::OpenGLES2)
return "OpenGLES2";
else if (apiVersion == dp::OpenGLES3)
return "OpenGLES3";
return "Unknown";
}
namespace
{
void WriteShaderToFile(QTemporaryFile & file, std::string const & shader)
{
QTextStream out(&file);
out << QString::fromStdString(shader);
}
using PrepareProcessFn = std::function<void(QProcess & p)>;
using PrepareArgumentsFn = std::function<void(QStringList & args, QString const & fileName)>;
using SuccessChecker = std::function<bool(QString const & output)>;
void RunShaderTest(dp::ApiVersion apiVersion, std::string const & shaderName,
QString const & glslCompiler, QString const & fileName,
PrepareProcessFn const & procPrepare, PrepareArgumentsFn const & argsPrepare,
SuccessChecker const & successChecker, QTextStream & errorLog)
{
QProcess p;
procPrepare(p);
p.setProcessChannelMode(QProcess::MergedChannels);
QStringList args;
argsPrepare(args, fileName);
p.start(glslCompiler, args, QIODevice::ReadOnly);
TEST(p.waitForStarted(), ("GLSL compiler not started", glslCompiler));
TEST(p.waitForFinished(), ("GLSL compiler not finished in time", glslCompiler));
QString result = p.readAllStandardOutput();
if (!successChecker(result))
{
errorLog << "\n"
<< QString(DebugPrint(apiVersion).c_str()) << ": " << QString(shaderName.c_str())
<< QString(": SHADER COMPILE ERROR:\n");
errorLog << result.trimmed() << "\n";
}
}
void TestShaders(dp::ApiVersion apiVersion, std::string const & defines,
gpu::ShadersEnum const & shaders, QString const & glslCompiler,
PrepareProcessFn const & procPrepare, PrepareArgumentsFn const & argsPrepare,
SuccessChecker const & successChecker, QTextStream & errorLog)
{
for (auto const & src : shaders)
{
QTemporaryFile srcFile;
TEST(srcFile.open(), ("Temporary file can't be created!"));
std::string fullSrc;
if (src.second.find("#version") != std::string::npos)
{
auto pos = src.second.find('\n');
ASSERT_NOT_EQUAL(pos, std::string::npos, ());
fullSrc = src.second;
fullSrc.insert(pos + 1, defines);
}
else
{
fullSrc = defines + src.second;
}
WriteShaderToFile(srcFile, fullSrc);
RunShaderTest(apiVersion, src.first, glslCompiler, srcFile.fileName(), procPrepare, argsPrepare,
successChecker, errorLog);
}
}
std::string GetCompilerPath(std::string const & compilerName)
{
Platform & platform = GetPlatform();
std::string compilerPath =
my::JoinFoldersToPath({platform.ResourcesDir(), kCompilersDir}, compilerName);
if (!platform.IsFileExistsByFullPath(compilerPath))
{
compilerPath = my::JoinFoldersToPath({platform.WritableDir(), kCompilersDir}, compilerName);
TEST(platform.IsFileExistsByFullPath(compilerPath), ("GLSL compiler not found"));
}
return compilerPath;
}
} // namespace
UNIT_TEST(CompileShaders_Test)
{
struct CompilerData
{
dp::ApiVersion m_apiVersion;
std::string m_compilerPath;
};
std::vector<CompilerData> const compilers = {
{dp::ApiVersion::OpenGLES2, GetCompilerPath(kCompilerOpenGLES2)},
{dp::ApiVersion::OpenGLES3, GetCompilerPath(kCompilerOpenGLES3)},
};
auto successChecker = [](QString const & output) { return output.indexOf("Success") != -1; };
for (auto const & compiler : compilers)
{
QString errorLog;
QTextStream ss(&errorLog);
QString compilerPath = QString::fromStdString(compiler.m_compilerPath);
QString shaderType = "-v";
auto argsPrepareFn = [&shaderType](QStringList & args, QString const & fileName) {
args << fileName << fileName + ".bin" << shaderType;
};
string defines = "";
TestShaders(compiler.m_apiVersion, defines, gpu::GetVertexShaders(compiler.m_apiVersion),
compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss);
shaderType = "-f";
TestShaders(compiler.m_apiVersion, defines, gpu::GetFragmentShaders(compiler.m_apiVersion),
compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss);
TEST_EQUAL(errorLog.isEmpty(), true, ("PVR without defines :", errorLog));
defines = "#define ENABLE_VTF\n";
errorLog.clear();
shaderType = "-v";
TestShaders(compiler.m_apiVersion, defines, gpu::GetVertexShaders(compiler.m_apiVersion),
compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss);
shaderType = "-f";
TestShaders(compiler.m_apiVersion, defines, gpu::GetFragmentShaders(compiler.m_apiVersion),
compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss);
TEST_EQUAL(errorLog.isEmpty(), true, ("PVR with defines : ", defines, "\n", errorLog));
defines = "#define SAMSUNG_GOOGLE_NEXUS\n";
errorLog.clear();
shaderType = "-v";
TestShaders(compiler.m_apiVersion, defines, gpu::GetVertexShaders(compiler.m_apiVersion),
compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss);
shaderType = "-f";
TestShaders(compiler.m_apiVersion, defines, gpu::GetFragmentShaders(compiler.m_apiVersion),
compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss);
TEST_EQUAL(errorLog.isEmpty(), true, ("PVR with defines : ", defines, "\n", errorLog));
}
}
UNIT_TEST(MALI_CompileShaders_Test)
{
using ReleaseVersion = std::pair<QString, QString>;
using Releases = std::vector<ReleaseVersion>;
struct DriverSet
{
QString m_driverName;
Releases m_releases;
};
struct CompilerData
{
dp::ApiVersion m_apiVersion;
std::string m_compilerPath;
std::string m_compilerAdditionalPath;
std::vector<DriverSet> m_driverSets;
};
std::vector<CompilerData> const compilers = {
{dp::ApiVersion::OpenGLES2,
GetCompilerPath(kCompilerMaliOpenGLES2),
GetCompilerPath(kMaliCompilerOpenGLES2Dir),
{{"Mali-400_r4p0-00rel1",
{std::make_pair("Mali-200", "r0p1"), std::make_pair("Mali-200", "r0p2"),
std::make_pair("Mali-200", "r0p3"), std::make_pair("Mali-200", "r0p4"),
std::make_pair("Mali-200", "r0p5"), std::make_pair("Mali-200", "r0p6"),
std::make_pair("Mali-400", "r0p0"), std::make_pair("Mali-400", "r0p1"),
std::make_pair("Mali-400", "r1p0"), std::make_pair("Mali-400", "r1p1"),
std::make_pair("Mali-300", "r0p0"), std::make_pair("Mali-450", "r0p0")}},
{"Mali-T600_r4p0-00rel0",
{std::make_pair("Mali-T600", "r0p0"), std::make_pair("Mali-T600", "r0p0_15dev0"),
std::make_pair("Mali-T600", "r0p1"), std::make_pair("Mali-T620", "r0p1"),
std::make_pair("Mali-T620", "r1p0"), std::make_pair("Mali-T670", "r1p0")}},
{"Mali-T600_r4p1-00rel0",
{std::make_pair("Mali-T600", "r0p0"), std::make_pair("Mali-T600", "r0p0_15dev0"),
std::make_pair("Mali-T600", "r0p1"), std::make_pair("Mali-T620", "r0p1"),
std::make_pair("Mali-T620", "r1p0"), std::make_pair("Mali-T620", "r1p1"),
std::make_pair("Mali-T720", "r0p0"), std::make_pair("Mali-T720", "r1p0"),
std::make_pair("Mali-T760", "r0p0"), std::make_pair("Mali-T760", "r0p1"),
std::make_pair("Mali-T760", "r0p1_50rel0"), std::make_pair("Mali-T760", "r0p2"),
std::make_pair("Mali-T760", "r0p3"), std::make_pair("Mali-T760", "r1p0")}}}},
{dp::ApiVersion::OpenGLES3,
GetCompilerPath(kCompilerMaliOpenGLES3),
GetCompilerPath(kMaliCompilerOpenGLES3Dir),
{{"Mali-T600_r5p0-00rel0",
{std::make_pair("Mali-T600", "r0p0"), std::make_pair("Mali-T600", "r0p0_15dev0"),
std::make_pair("Mali-T600", "r0p1"), std::make_pair("Mali-T620", "r0p1"),
std::make_pair("Mali-T620", "r1p0"), std::make_pair("Mali-T620", "r1p1"),
std::make_pair("Mali-T760", "r0p0"), std::make_pair("Mali-T760", "r0p1"),
std::make_pair("Mali-T760", "r0p1_50rel0"), std::make_pair("Mali-T760", "r0p2"),
std::make_pair("Mali-T760", "r0p3"), std::make_pair("Mali-T760", "r1p0")}},
{"Mali-T600_r5p1-00rel0",
{std::make_pair("Mali-T600", "r0p0"), std::make_pair("Mali-T600", "r0p0_15dev0"),
std::make_pair("Mali-T600", "r0p1"), std::make_pair("Mali-T620", "r0p1"),
std::make_pair("Mali-T620", "r1p0"), std::make_pair("Mali-T620", "r1p1"),
std::make_pair("Mali-T760", "r0p0"), std::make_pair("Mali-T760", "r0p1"),
std::make_pair("Mali-T760", "r0p1_50rel0"), std::make_pair("Mali-T760", "r0p2"),
std::make_pair("Mali-T760", "r0p3"), std::make_pair("Mali-T760", "r1p0")}},
{"Mali-T600_r6p0-00rel0",
{std::make_pair("Mali-T600", "r0p0"), std::make_pair("Mali-T600", "r0p0_15dev0"),
std::make_pair("Mali-T600", "r0p1"), std::make_pair("Mali-T620", "r0p1"),
std::make_pair("Mali-T620", "r1p0"), std::make_pair("Mali-T620", "r1p1"),
std::make_pair("Mali-T760", "r0p0"), std::make_pair("Mali-T760", "r0p1"),
std::make_pair("Mali-T760", "r0p1_50rel0"), std::make_pair("Mali-T760", "r0p2"),
std::make_pair("Mali-T760", "r0p3"), std::make_pair("Mali-T760", "r1p0")}}}},
};
auto successChecker = [](QString const & output) {
return output.indexOf("Compilation succeeded.") != -1;
};
for (auto const & compiler : compilers)
{
for (auto const & set : compiler.m_driverSets)
{
for (auto const & version : set.m_releases)
{
QString errorLog;
QTextStream ss(&errorLog);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("MALICM_LOCATION", QString::fromStdString(compiler.m_compilerAdditionalPath));
auto procPrepare = [&env](QProcess & p) { p.setProcessEnvironment(env); };
QString shaderType = "-v";
auto argForming = [&](QStringList & args, QString const & fileName) {
args << shaderType << "-V"
<< "-r" << version.second << "-c" << version.first << "-d" << set.m_driverName
<< fileName;
};
std::string defines = "";
QString const compilerPath = QString::fromStdString(compiler.m_compilerPath);
TestShaders(compiler.m_apiVersion, defines, gpu::GetVertexShaders(compiler.m_apiVersion),
compilerPath, procPrepare, argForming, successChecker, ss);
shaderType = "-f";
TestShaders(compiler.m_apiVersion, defines, gpu::GetFragmentShaders(compiler.m_apiVersion),
compilerPath, procPrepare, argForming, successChecker, ss);
TEST(errorLog.isEmpty(),
(shaderType, version.second, version.first, set.m_driverName, defines, errorLog));
// MALI GPUs do not support ENABLE_VTF. Do not test it here.
// SAMSUNG_GOOGLE_NEXUS doesn't use Mali GPU. Do not test it here.
}
}
}
}
#endif

View file

@ -4,8 +4,20 @@ CONFIG += console warn_on
CONFIG -= app_bundle
TEMPLATE = app
DEFINES += COMPILER_TESTS
DEPENDENCIES = drape_frontend drape platform indexer geometry coding base expat stats_client stb_image sdf_image icu
SHADER_COMPILE_ARGS = $$PWD/../shaders shader_index.txt shaders_lib.glsl $$PWD shader_def_for_tests
CMDRES = $$system(python $$PWD/../../tools/autobuild/shader_preprocessor.py $$SHADER_COMPILE_ARGS)
!isEmpty($$CMDRES):message($$CMDRES)
DEL_SHADERS_COMPILERS = $$system(rm -rf $$PWD/../../data/shaders_compiler)
!isEmpty(DEL_SHADERS_COMPILERS):message(DEL_SHADERS_COMPILERS)
COPY_SHADERS_COMPILERS = $$system(cp -r $$PWD/../../tools/shaders_compiler $$PWD/../../data)
!isEmpty(COPY_SHADERS_COMPILERS):message(COPY_SHADERS_COMPILERS)
ROOT_DIR = ../..
include($$ROOT_DIR/common.pri)
@ -21,7 +33,11 @@ win32*|linux* {
SOURCES += \
../../testing/testingmain.cpp \
compile_shaders_test.cpp \
navigator_test.cpp \
object_pool_tests.cpp \
shader_def_for_tests.cpp \
user_event_stream_tests.cpp \
HEADERS += \
shader_def_for_tests.hpp \

View file

@ -10,11 +10,11 @@
#include "drape_frontend/scenario_manager.hpp"
#include "drape_frontend/screen_operations.hpp"
#include "drape_frontend/screen_quad_renderer.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/user_mark_shapes.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/debug_rect_renderer.hpp"
#include "drape/shader_def.hpp"
#include "drape/support_manager.hpp"
#include "drape/utils/glyph_usage_tracker.hpp"
@ -1693,13 +1693,13 @@ void FrontendRenderer::OnContextCreate()
dp::SupportManager::Instance().Init();
m_gpuProgramManager = make_unique_dp<dp::GpuProgramManager>();
m_gpuProgramManager->Init();
m_gpuProgramManager->Init(make_unique_dp<gpu::ShaderMapper>(dp::ApiVersion::OpenGLES2));
dp::BlendingParams blendingParams;
blendingParams.Apply();
#ifdef RENDER_DEBUG_RECTS
dp::DebugRectRenderer::Instance().Init(make_ref(m_gpuProgramManager));
dp::DebugRectRenderer::Instance().Init(make_ref(m_gpuProgramManager), gpu::DEBUG_RECT_PROGRAM);
#endif
// resources recovering

View file

@ -1,11 +1,11 @@
#include "drape_frontend/gps_track_renderer.hpp"
#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/glsl_func.hpp"
#include "drape/shader_def.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "indexer/map_style_reader.hpp"

View file

@ -1,10 +1,10 @@
#include "drape_frontend/gps_track_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/batcher.hpp"
#include "drape/glsl_func.hpp"
#include "drape/glsl_types.hpp"
#include "drape/shader_def.hpp"
#include "drape/texture_manager.hpp"
#include "base/logging.hpp"

View file

@ -1,7 +1,6 @@
#include "choose_position_mark.hpp"
#include "drape_gui.hpp"
#include "drape/shader_def.hpp"
#include "drape_frontend/gui/choose_position_mark.hpp"
#include "drape_frontend/gui/drape_gui.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/utils/vertex_decl.hpp"

View file

@ -1,11 +1,11 @@
#include "compass.hpp"
#include "drape_gui.hpp"
#include "drape_frontend/gui/compass.hpp"
#include "drape_frontend/animation/show_hide_animation.hpp"
#include "drape_frontend/gui/drape_gui.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/glsl_types.hpp"
#include "drape/glsl_func.hpp"
#include "drape/shader_def.hpp"
#include "drape/glsl_types.hpp"
#include "drape/utils/vertex_decl.hpp"

View file

@ -1,5 +1,6 @@
#include "gui_text.hpp"
#include "drape_frontend/gui/gui_text.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/visual_params.hpp"
#include "base/string_utils.hpp"
@ -7,7 +8,6 @@
#include "drape/bidi.hpp"
#include "drape/glsl_func.hpp"
#include "drape/shader_def.hpp"
#include "std/algorithm.hpp"
#include "std/type_traits.hpp"

View file

@ -1,13 +1,13 @@
#include "drape_gui.hpp"
#include "gui_text.hpp"
#include "ruler.hpp"
#include "ruler_helper.hpp"
#include "drape_frontend/gui/ruler.hpp"
#include "drape_frontend/animation/show_hide_animation.hpp"
#include "drape_frontend/gui/drape_gui.hpp"
#include "drape_frontend/gui/gui_text.hpp"
#include "drape_frontend/gui/ruler_helper.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/glsl_func.hpp"
#include "drape/glsl_types.hpp"
#include "drape/shader_def.hpp"
#include "std/bind.hpp"

View file

@ -1,13 +1,13 @@
#include "drape_frontend/line_shape.hpp"
#include "drape_frontend/line_shape_helper.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/batcher.hpp"
#include "drape/glsl_types.hpp"
#include "drape/glsl_func.hpp"
#include "drape/shader_def.hpp"
#include "drape/support_manager.hpp"
#include "drape/texture_manager.hpp"
#include "drape/utils/vertex_decl.hpp"

View file

@ -1,6 +1,7 @@
#include "drape_frontend/my_position.hpp"
#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/tile_utils.hpp"
@ -9,7 +10,6 @@
#include "drape/glsl_types.hpp"
#include "drape/overlay_handle.hpp"
#include "drape/render_bucket.hpp"
#include "drape/shader_def.hpp"
#include "indexer/map_style_reader.hpp"

View file

@ -1,11 +1,11 @@
#include "drape_frontend/path_symbol_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/utils/vertex_decl.hpp"
#include "drape/glsl_types.hpp"
#include "drape/glsl_func.hpp"
#include "drape/overlay_handle.hpp"
#include "drape/shader_def.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/texture_manager.hpp"
#include "drape/glstate.hpp"

View file

@ -1,12 +1,12 @@
#include "drape_frontend/path_text_shape.hpp"
#include "drape_frontend/intrusive_vector.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/text_handle.hpp"
#include "drape_frontend/text_layout.hpp"
#include "drape_frontend/intrusive_vector.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/batcher.hpp"
#include "drape/glstate.hpp"
#include "drape/shader_def.hpp"
#include "drape/overlay_handle.hpp"
#include "base/math.hpp"

View file

@ -1,10 +1,10 @@
#include "drape_frontend/poi_symbol_shape.hpp"
#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/batcher.hpp"
#include "drape/texture_manager.hpp"
#include "drape/shader_def.hpp"
#include "drape/utils/vertex_decl.hpp"
namespace

View file

@ -1,8 +1,8 @@
#include "drape_frontend/render_group.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/debug_rect_renderer.hpp"
#include "drape/shader_def.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "geometry/screenbase.hpp"

View file

@ -1,10 +1,10 @@
#include "drape_frontend/route_renderer.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/message_subclasses.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/visual_params.hpp"
#include "drape/glsl_func.hpp"
#include "drape/shader_def.hpp"
#include "drape/utils/projection.hpp"
#include "drape/vertex_array_buffer.hpp"

View file

@ -1,5 +1,6 @@
#include "drape_frontend/route_shape.hpp"
#include "drape_frontend/line_shape_helper.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/tile_utils.hpp"
#include "drape_frontend/traffic_generator.hpp"
@ -8,7 +9,6 @@
#include "drape/batcher.hpp"
#include "drape/glsl_func.hpp"
#include "drape/glsl_types.hpp"
#include "drape/shader_def.hpp"
#include "drape/texture_manager.hpp"
#include "indexer/map_style_reader.hpp"

View file

@ -427,8 +427,9 @@ void RuleDrawer::operator()(FeatureType const & f)
strings::to_string(key.m_zoomLevel);
tp.m_primaryTextFont = dp::FontDecl(dp::Color::Red(), 30);
tp.m_primaryOffset = {0.f, 0.f};
drape_ptr<TextShape> textShape = make_unique_dp<TextShape>(r.Center(), tp, false, 0, false);
tp.m_primaryOffset = {0.0f, 0.0f};
drape_ptr<TextShape> textShape =
make_unique_dp<TextShape>(r.Center(), tp, m_context->GetTileKey(), false, 0, false);
textShape->DisableDisplacing();
insertShape(move(textShape));
#endif

View file

@ -1,4 +1,5 @@
#include "drape_frontend/screen_quad_renderer.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape/data_buffer.hpp"
#include "drape/glconstants.hpp"
@ -6,7 +7,6 @@
#include "drape/glfunctions.hpp"
#include "drape/glstate.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/shader_def.hpp"
#include "drape/uniform_values_storage.hpp"
#include <vector>

View file

@ -1,6 +1,7 @@
#include "drape_frontend/selection_shape.hpp"
#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/shader_def.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/tile_utils.hpp"
#include "drape_frontend/visual_params.hpp"
@ -11,7 +12,6 @@
#include "drape/glsl_func.hpp"
#include "drape/glsl_types.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/shader_def.hpp"
#include "drape/texture_manager.hpp"
#include "drape/uniform_values_storage.hpp"

View file

@ -12,13 +12,10 @@ varying lowp vec4 v_color;
varying vec2 v_colorTexCoords;
#endif
void main(void)
void main()
{
vec4 pos = vec4(a_position, 1) * modelView * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos, pivotTransform, 0.0);
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, a_colorTexCoords);
#else

View file

@ -12,7 +12,7 @@ varying float v_intensity;
const vec4 lightDir = vec4(1.0, 0.0, 3.0, 0.0);
void main(void)
void main()
{
vec4 pos = vec4(a_position, 1.0) * modelView;

View file

@ -13,7 +13,7 @@ varying lowp vec4 v_color;
varying vec2 v_colorTexCoords;
#endif
void main(void)
void main()
{
vec4 pos = vec4(a_position, 1.0) * modelView;
pos.xyw = (pos * projection).xyw;

View file

@ -0,0 +1,14 @@
varying vec2 v_intensity;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
void main()
{
float alpha = smoothstep(0.8, 1.0, v_intensity.y);
vec4 resColor = vec4((v_intensity.x * 0.5 + 0.5) * u_color.rgb, u_color.a * alpha);
gl_FragColor = samsungGoogleNexusWorkaround(resColor);
}

View file

@ -0,0 +1,13 @@
varying float v_intensity;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
void main()
{
vec4 resColor = vec4(u_color.rgb, u_color.a * smoothstep(0.7, 1.0, v_intensity));
gl_FragColor = samsungGoogleNexusWorkaround(resColor);
}

View file

@ -0,0 +1,13 @@
varying float v_intensity;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
void main()
{
vec4 resColor = vec4(u_color.rgb, u_color.a * v_intensity);
gl_FragColor = samsungGoogleNexusWorkaround(resColor);
}

View file

@ -10,7 +10,7 @@ varying vec3 v_radius;
const float aaPixelsCount = 2.5;
void main(void)
void main()
{
#ifdef ENABLE_VTF
lowp vec4 finalColor = v_color;

View file

@ -14,16 +14,11 @@ varying lowp vec4 v_color;
varying vec2 v_colorTexCoords;
#endif
void main(void)
void main()
{
vec4 p = vec4(a_position, 1) * modelView;
vec4 pos = vec4(a_normal.xy, 0, 0) + p;
pos = pos * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos * projection, pivotTransform, 0.0);
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, a_colorTexCoords);
#else

View file

@ -10,7 +10,7 @@ varying vec2 v_colorTexCoords;
const float aaPixelsCount = 2.5;
void main(void)
void main()
{
#ifdef ENABLE_VTF
lowp vec4 color = v_color;

View file

@ -14,16 +14,11 @@ varying lowp vec4 v_color;
varying vec2 v_colorTexCoords;
#endif
void main(void)
void main()
{
vec4 p = vec4(a_position, 1) * modelView;
vec4 pos = vec4(a_normal.xy + a_colorTexCoords.zw, 0, 0) + p;
pos = pos * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos * projection, pivotTransform, 0.0);
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, a_colorTexCoords.xy);

View file

@ -14,17 +14,11 @@ varying lowp vec4 v_color;
varying vec2 v_colorTexCoords;
#endif
void main(void)
void main()
{
vec4 pivot = vec4(a_position.xyz, 1.0) * modelView;
vec4 offset = vec4(a_normal.xy + a_colorTexCoords.zw, 0.0, 0.0) * projection;
vec4 projectedPivot = pivot * projection;
float logicZ = projectedPivot.z / projectedPivot.w;
vec4 transformedPivot = pivotTransform * vec4(projectedPivot.xy, 0.0, projectedPivot.w);
vec4 scale = pivotTransform * vec4(1.0, -1.0, 0.0, 1.0);
gl_Position = vec4(transformedPivot.xy / transformedPivot.w, logicZ, 1.0) + vec4(offset.xy / scale.w * scale.x, 0.0, 0.0);
gl_Position = applyBillboardPivotTransform(pivot * projection, pivotTransform, 0.0, offset.xy);
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, a_colorTexCoords.xy);

View file

@ -8,7 +8,7 @@ uniform float u_opacity;
const float aaPixelsCount = 2.5;
void main(void)
void main()
{
vec4 color = texture2D(u_colorTex, v_colorTexCoord);
vec4 mask = texture2D(u_maskTex, v_maskTexCoord);

View file

@ -11,18 +11,15 @@ varying vec2 v_colorTexCoord;
varying vec2 v_maskTexCoord;
varying vec2 v_halfLength;
const float kShapeCoordScalar = 1000.0;
void main(void)
void main()
{
vec2 normal = a_normal.xy;
float halfWidth = length(normal);
vec2 transformedAxisPos = (vec4(a_position.xy, 0.0, 1.0) * modelView).xy;
if (halfWidth != 0.0)
{
vec4 glbShiftPos = vec4(a_position.xy + normal, 0.0, 1.0);
vec2 shiftPos = (glbShiftPos * modelView).xy;
transformedAxisPos = transformedAxisPos + normalize(shiftPos - transformedAxisPos) * halfWidth;
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal,
modelView, halfWidth);
}
float uOffset = min(length(vec4(kShapeCoordScalar, 0, 0, 0) * modelView) * a_maskTexCoord.x, 1.0);
@ -30,8 +27,6 @@ void main(void)
v_maskTexCoord = vec2(a_maskTexCoord.y + uOffset * a_maskTexCoord.z, a_maskTexCoord.w);
v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z));
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos, pivotTransform, 0.0);
}

View file

@ -0,0 +1,10 @@
uniform vec4 u_color;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
void main()
{
gl_FragColor = samsungGoogleNexusWorkaround(u_color);
}

View file

@ -1,6 +1,6 @@
attribute vec2 a_position;
void main(void)
void main()
{
gl_Position = vec4(a_position, 0, 1);
}

View file

@ -7,7 +7,7 @@ uniform float u_opacity;
varying vec2 v_colorTexCoords;
void main(void)
void main()
{
vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords);
finalColor.a *= u_opacity;

View file

@ -10,7 +10,7 @@ varying vec2 v_colorTexCoords;
uniform sampler2D u_maskTex;
varying vec2 v_maskTexCoords;
void main(void)
void main()
{
#ifdef ENABLE_VTF
lowp vec4 color = v_color;

View file

@ -14,13 +14,10 @@ varying vec2 v_colorTexCoords;
#endif
varying vec2 v_maskTexCoords;
void main(void)
void main()
{
vec4 pos = vec4(a_position, 1) * modelView * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos, pivotTransform, 0.0);
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, a_colorTexCoords);
#else

View file

@ -10,7 +10,7 @@ varying vec2 v_colorTexCoord;
const float aaPixelsCount = 2.5;
void main(void)
void main()
{
#ifdef ENABLE_VTF
lowp vec4 color = v_color;

View file

@ -15,16 +15,15 @@ varying vec2 v_colorTexCoord;
varying vec2 v_halfLength;
void main(void)
void main()
{
vec2 normal = a_normal.xy;
float halfWidth = length(normal);
vec2 transformedAxisPos = (vec4(a_position.xy, 0.0, 1.0) * modelView).xy;
if (halfWidth != 0.0)
{
vec4 glbShiftPos = vec4(a_position.xy + normal, 0.0, 1.0);
vec2 shiftPos = (glbShiftPos * modelView).xy;
transformedAxisPos = transformedAxisPos + normalize(shiftPos - transformedAxisPos) * halfWidth;
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal,
modelView, halfWidth);
}
#ifdef ENABLE_VTF
@ -34,8 +33,5 @@ void main(void)
#endif
v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z));
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos, pivotTransform, 0.0);
}

View file

@ -5,7 +5,7 @@ uniform float u_opacity;
varying vec2 v_colorTexCoords;
varying vec2 v_maskTexCoords;
void main(void)
void main()
{
vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords) * texture2D(u_maskTex, v_maskTexCoords);
finalColor.a *= u_opacity;

View file

@ -10,15 +10,11 @@ uniform mat4 pivotTransform;
varying vec2 v_colorTexCoords;
varying vec2 v_maskTexCoords;
void main(void)
void main()
{
vec4 pos = vec4(a_position.xyz, 1) * modelView;
vec4 shiftedPos = vec4(a_normal, 0, 0) + pos;
shiftedPos = shiftedPos * projection;
float w = shiftedPos.w;
shiftedPos.xyw = (pivotTransform * vec4(shiftedPos.xy, 0.0, w)).xyw;
shiftedPos.z *= shiftedPos.w / w;
gl_Position = shiftedPos;
gl_Position = applyPivotTransform(shiftedPos * projection, pivotTransform, 0.0);
v_colorTexCoords = a_colorTexCoords;
v_maskTexCoords = a_maskTexCoords;
}

View file

@ -11,19 +11,11 @@ uniform float zScale;
varying vec2 v_colorTexCoords;
varying vec2 v_maskTexCoords;
void main(void)
void main()
{
vec4 pivot = vec4(a_position.xyz, 1.0) * modelView;
vec4 offset = vec4(a_normal, 0.0, 0.0) * projection;
float pivotZ = a_position.w;
vec4 projectedPivot = pivot * projection;
float logicZ = projectedPivot.z / projectedPivot.w;
vec4 transformedPivot = pivotTransform * vec4(projectedPivot.xy, pivotZ * zScale, projectedPivot.w);
vec4 scale = pivotTransform * vec4(1.0, -1.0, 0.0, 1.0);
gl_Position = vec4(transformedPivot.xy / transformedPivot.w, logicZ, 1.0) + vec4(offset.xy / scale.w * scale.x, 0.0, 0.0);
gl_Position = applyBillboardPivotTransform(pivot * projection, pivotTransform, a_position.w * zScale, offset.xy);
v_colorTexCoords = a_colorTexCoords;
v_maskTexCoords = a_maskTexCoords;

View file

@ -10,7 +10,7 @@ uniform mat4 pivotTransform;
varying vec2 v_colorTexCoords;
void main(void)
void main()
{
float sinV = sin(u_azimut);
float cosV = cos(u_azimut);
@ -25,10 +25,6 @@ void main(void)
vec4 normal = vec4(a_normal, 0, 0);
vec4 shiftedPos = normal * rotation + pos;
shiftedPos = shiftedPos * projection;
float w = shiftedPos.w;
shiftedPos.xyw = (pivotTransform * vec4(shiftedPos.xy, 0.0, w)).xyw;
shiftedPos.z *= shiftedPos.w / w;
gl_Position = shiftedPos;
gl_Position = applyPivotTransform(shiftedPos * projection, pivotTransform, 0.0);
v_colorTexCoords = a_colorTexCoords;
}

View file

@ -8,9 +8,7 @@ uniform mat4 pivotTransform;
varying vec2 v_colorTexCoords;
const float kShapeCoordScalar = 1000.0;
void main(void)
void main()
{
vec4 pos = vec4(a_position.xyz, 1) * modelView;
@ -19,10 +17,6 @@ void main(void)
vec4 norm = n * normalLen;
vec4 shiftedPos = norm + pos;
shiftedPos = shiftedPos * projection;
float w = shiftedPos.w;
shiftedPos.xyw = (pivotTransform * vec4(shiftedPos.xy, 0.0, w)).xyw;
shiftedPos.z *= shiftedPos.w / w;
gl_Position = shiftedPos;
gl_Position = applyPivotTransform(shiftedPos * projection, pivotTransform, 0.0);
v_colorTexCoords = a_colorTexCoords;
}

View file

@ -11,16 +11,12 @@ uniform float zScale;
varying vec2 v_colorTexCoords;
void main(void)
void main()
{
vec4 position = vec4(u_position.xy, 0.0, 1.0) * modelView;
vec4 normal = vec4(normalize(a_normal) * u_accuracy, 0.0, 0.0);
position = (position + normal) * projection;
float w = position.w;
position.xyw = (pivotTransform * vec4(position.xy, u_position.z * zScale, w)).xyw;
position.z *= position.w / w;
gl_Position = position;
gl_Position = applyPivotTransform(position, pivotTransform, u_position.z * zScale);
v_colorTexCoords = a_colorTexCoords;
}

View file

@ -14,14 +14,8 @@ const float kAntialiasingThreshold = 0.92;
const float kOutlineThreshold1 = 0.81;
const float kOutlineThreshold2 = 0.71;
void main(void)
void main()
{
#ifdef SAMSUNG_GOOGLE_NEXUS
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
const float kFakeColorScalar = 0.0;
lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar;
#endif
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
if (v_length.x >= v_length.z)
{
@ -30,10 +24,5 @@ void main(void)
color = mix(color, u_outlineColor, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_length.y)));
color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y)));
}
#ifdef SAMSUNG_GOOGLE_NEXUS
gl_FragColor = color + fakeColor;
#else
gl_FragColor = color;
#endif
gl_FragColor = samsungGoogleNexusWorkaround(color);
}

View file

@ -12,7 +12,7 @@ uniform vec4 u_routeParams;
varying vec3 v_length;
varying vec4 v_color;
void main(void)
void main()
{
float normalLen = length(a_normal);
vec2 transformedAxisPos = (vec4(a_position.xy, 0.0, 1.0) * modelView).xy;
@ -20,12 +20,8 @@ void main(void)
if (u_routeParams.x != 0.0 && normalLen != 0.0)
{
vec2 norm = a_normal * u_routeParams.x;
float actualHalfWidth = length(norm);
vec4 glbShiftPos = vec4(a_position.xy + norm, 0.0, 1.0);
vec2 shiftPos = (glbShiftPos * modelView).xy;
transformedAxisPos = transformedAxisPos + normalize(shiftPos - transformedAxisPos) * actualHalfWidth;
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm,
modelView, length(norm));
if (u_routeParams.y != 0.0)
len = vec2(a_length.x + a_length.y * u_routeParams.y, a_length.z);
}
@ -33,8 +29,5 @@ void main(void)
v_length = vec3(len, u_routeParams.z);
v_color = a_color;
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos, pivotTransform, 0.0);
}

View file

@ -10,25 +10,19 @@ uniform float u_arrowHalfWidth;
varying vec2 v_colorTexCoords;
void main(void)
void main()
{
float normalLen = length(a_normal);
vec2 transformedAxisPos = (vec4(a_position.xy, 0.0, 1.0) * modelView).xy;
if (normalLen != 0.0)
{
vec2 norm = a_normal * u_arrowHalfWidth;
float actualHalfWidth = length(norm);
vec4 glbShiftPos = vec4(a_position.xy + norm, 0.0, 1.0);
vec2 shiftPos = (glbShiftPos * modelView).xy;
transformedAxisPos = transformedAxisPos + normalize(shiftPos - transformedAxisPos) * actualHalfWidth;
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm,
modelView, length(norm));
}
v_colorTexCoords = a_colorTexCoords;
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
float w = pos.w;
pos.xyw = (pivotTransform * vec4(pos.xy, 0.0, w)).xyw;
pos.z *= pos.w / w;
gl_Position = pos;
gl_Position = applyPivotTransform(pos, pivotTransform, 0.0);
}

View file

@ -0,0 +1,33 @@
varying vec3 v_length;
varying vec4 v_color;
#ifdef SAMSUNG_GOOGLE_NEXUS
uniform sampler2D u_colorTex;
#endif
uniform vec4 u_color;
uniform vec2 u_pattern;
const float kAntialiasingThreshold = 0.92;
float alphaFromPattern(float curLen, float dashLen, float gapLen)
{
float len = dashLen + gapLen;
float offset = fract(curLen / len) * len;
return step(offset, dashLen);
}
void main()
{
vec4 color = u_color;
if (v_length.x < v_length.z)
{
color.a = 0.0;
}
else
{
color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y))) *
alphaFromPattern(v_length.x, u_pattern.x, u_pattern.y);
}
gl_FragColor = samsungGoogleNexusWorkaround(color);
}

View file

@ -8,7 +8,7 @@ uniform mat4 projection;
varying vec2 v_colorTexCoords;
void main(void)
void main()
{
gl_Position = vec4(u_position + a_position + u_length * a_normal, 0, 1) * projection;
v_colorTexCoords = a_colorTexCoords;

View file

@ -0,0 +1,39 @@
TEXTURING_PROGRAM texturing.vsh.glsl texturing.fsh.glsl
MASKED_TEXTURING_PROGRAM masked_texturing.vsh.glsl masked_texturing.fsh.glsl
COLORED_SYMBOL_PROGRAM colored_symbol.vsh.glsl colored_symbol.fsh.glsl
TEXT_OUTLINED_PROGRAM text_outlined.vsh.glsl text.fsh.glsl
TEXT_PROGRAM text.vsh.glsl text.fsh.glsl
TEXT_FIXED_PROGRAM text.vsh.glsl text_fixed.fsh.glsl
TEXT_OUTLINED_GUI_PROGRAM text_outlined_gui.vsh.glsl text.fsh.glsl
AREA_PROGRAM area.vsh.glsl solid_color.fsh.glsl
HATCHING_AREA_PROGRAM hatching_area.vsh.glsl hatching_area.fsh.glsl
AREA_OUTLINE_PROGRAM area.vsh.glsl solid_color.fsh.glsl
AREA_3D_PROGRAM area3d.vsh.glsl texturing3d.fsh.glsl
AREA_3D_OUTLINE_PROGRAM area3d_outline.vsh.glsl solid_color.fsh.glsl
LINE_PROGRAM line.vsh.glsl line.fsh.glsl
CAP_JOIN_PROGRAM circle.vsh.glsl circle.fsh.glsl
DASHED_LINE_PROGRAM dashed_line.vsh.glsl dashed_line.fsh.glsl
PATH_SYMBOL_LINE path_symbol.vsh.glsl texturing.fsh.glsl
TEXTURING_GUI_PROGRAM texturing_gui.vsh.glsl texturing.fsh.glsl
RULER_PROGRAM ruler.vsh.glsl texturing.fsh.glsl
ACCURACY_PROGRAM position_accuracy3d.vsh.glsl texturing.fsh.glsl
MY_POSITION_PROGRAM my_position.vsh.glsl texturing.fsh.glsl
BOOKMARK_PROGRAM user_mark.vsh.glsl texturing.fsh.glsl
ROUTE_PROGRAM route.vsh.glsl route.fsh.glsl
ROUTE_DASH_PROGRAM route.vsh.glsl route_dash.fsh.glsl
ROUTE_ARROW_PROGRAM route_arrow.vsh.glsl discarded_texturing.fsh.glsl
TRACK_POINT_PROGRAM trackpoint.vsh.glsl trackpoint.fsh.glsl
DEBUG_RECT_PROGRAM debug_rect.vsh.glsl debug_rect.fsh.glsl
SCREEN_QUAD_PROGRAM screen_quad.vsh.glsl texturing.fsh.glsl
ARROW_3D_PROGRAM arrow3d.vsh.glsl arrow3d.fsh.glsl
ARROW_3D_SHADOW_PROGRAM arrow3d_shadow.vsh.glsl arrow3d_shadow.fsh.glsl
ARROW_3D_OUTLINE_PROGRAM arrow3d_shadow.vsh.glsl arrow3d_outline.fsh.glsl
COLORED_SYMBOL_BILLBOARD_PROGRAM colored_symbol_billboard.vsh.glsl colored_symbol.fsh.glsl
TEXTURING_BILLBOARD_PROGRAM texturing_billboard.vsh.glsl texturing.fsh.glsl
MASKED_TEXTURING_BILLBOARD_PROGRAM masked_texturing_billboard.vsh.glsl masked_texturing.fsh.glsl
TEXT_OUTLINED_BILLBOARD_PROGRAM text_outlined_billboard.vsh.glsl text.fsh.glsl
TEXT_BILLBOARD_PROGRAM text_billboard.vsh.glsl text.fsh.glsl
TEXT_FIXED_BILLBOARD_PROGRAM text_billboard.vsh.glsl text_fixed.fsh.glsl
BOOKMARK_BILLBOARD_PROGRAM user_mark_billboard.vsh.glsl texturing.fsh.glsl
TRAFFIC_PROGRAM traffic.vsh.glsl traffic.fsh.glsl
TRAFFIC_LINE_PROGRAM traffic_line.vsh.glsl traffic_line.fsh.glsl

View file

@ -0,0 +1,48 @@
// This is a library of functions which we are use in our shaders.
// Common (DO NOT modify this comment, it marks up block of common functions).
// Scale factor in shape's coordinates transformation from tile's coorinate
// system.
const float kShapeCoordScalar = 1000.0;
// VS (DO NOT modify this comment, it marks up block of vertex shader functions).
// This function applies a 2D->3D transformation matrix |pivotTransform| to |pivot|.
vec4 applyPivotTransform(vec4 pivot, mat4 pivotTransform, float pivotRealZ)
{
vec4 transformedPivot = pivot;
float w = transformedPivot.w;
transformedPivot.xyw = (pivotTransform * vec4(transformedPivot.xy, pivotRealZ, w)).xyw;
transformedPivot.z *= transformedPivot.w / w;
return transformedPivot;
}
// This function applies a 2D->3D transformation matrix to billboards.
vec4 applyBillboardPivotTransform(vec4 pivot, mat4 pivotTransform, float pivotRealZ, vec2 offset)
{
float logicZ = pivot.z / pivot.w;
vec4 transformedPivot = pivotTransform * vec4(pivot.xy, pivotRealZ, pivot.w);
vec4 scale = pivotTransform * vec4(1.0, -1.0, 0.0, 1.0);
return vec4(transformedPivot.xy / transformedPivot.w, logicZ, 1.0) + vec4(offset / scale.w * scale.x, 0.0, 0.0);
}
// This function calculates transformed position on an axis for line shaders family.
vec2 calcLineTransformedAxisPos(vec2 originalAxisPos, vec2 shiftedPos, mat4 modelView, float halfWidth)
{
vec2 p = (vec4(shiftedPos, 0.0, 1.0) * modelView).xy;
return originalAxisPos + normalize(p - originalAxisPos) * halfWidth;
}
// FS (DO NOT modify this comment, it marks up block of fragment shader functions).
// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here.
// It must be used in shaders which do not have any sampler2D usage.
vec4 samsungGoogleNexusWorkaround(vec4 color)
{
#ifdef SAMSUNG_GOOGLE_NEXUS
const float kFakeColorScalar = 0.0;
return color + texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar;
#else
return color;
#endif
}

View file

@ -7,7 +7,7 @@ uniform sampler2D u_colorTex;
varying vec2 v_colorTexCoords;
#endif
void main(void)
void main()
{
#ifdef ENABLE_VTF
lowp vec4 finalColor = v_color;

Some files were not shown because too many files have changed in this diff Show more