Skip to content

Commit 7b71dec

Browse files
committed
Move include related classes to matc
1 parent 3cd92cd commit 7b71dec

File tree

14 files changed

+93
-115
lines changed

14 files changed

+93
-115
lines changed

libs/filamat/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ set(PUBLIC_HDR_DIR include)
99
# ==================================================================================================
1010
set(HDRS
1111
include/filamat/Enums.h
12-
include/filamat/Includes.h
13-
include/filamat/IncludeCallback.h
1412
include/filamat/MaterialBuilder.h
1513
include/filamat/Package.h
1614
)
@@ -40,7 +38,6 @@ set(COMMON_SRCS
4038
src/shaders/SibGenerator.cpp
4139
src/shaders/UibGenerator.cpp
4240
src/Enums.cpp
43-
src/Includes.cpp
4441
src/MaterialBuilder.cpp
4542
src/MaterialVariants.cpp
4643
)
@@ -161,8 +158,7 @@ if (IS_HOST_PLATFORM)
161158
tests/test_filamat.cpp
162159
tests/test_argBufferFixup.cpp
163160
tests/test_clipDistanceFixup.cpp
164-
tests/test_line_dictionary.cpp
165-
tests/test_includes.cpp)
161+
tests/test_line_dictionary.cpp)
166162

167163
add_executable(${TARGET} ${SRCS})
168164
target_include_directories(${TARGET} PRIVATE src)

libs/filamat/include/filamat/MaterialBuilder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <filament/MaterialEnums.h>
2323

24-
#include <filamat/IncludeCallback.h>
2524
#include <filamat/Package.h>
2625

2726
#include <backend/DriverEnums.h>

libs/filamat/src/MaterialBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "filamat/MaterialBuilder.h"
1818

1919
#include <filamat/Enums.h>
20-
#include <filamat/IncludeCallback.h>
2120
#include <filamat/Package.h>
2221

2322
#include "GLSLPostProcessor.h"

libs/filamat/tests/test_filamat.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "sca/GLSLTools.h"
2121
#include "shaders/ShaderGenerator.h"
2222

23-
#include "MockIncluder.h"
24-
2523
#include <filamat/Enums.h>
2624
#include <filamat/MaterialBuilder.h>
2725

@@ -53,9 +51,7 @@ std::string shaderWithAllProperties(JobSystem& jobSystem, ShaderStage type,
5351
filamat::MaterialBuilder::Shading shadingModel = filamat::MaterialBuilder::Shading::LIT,
5452
filamat::MaterialBuilder::RefractionMode refractionMode = filamat::MaterialBuilder::RefractionMode::NONE,
5553
filamat::MaterialBuilder::VertexDomain vertexDomain = filamat::MaterialBuilder::VertexDomain::OBJECT) {
56-
MockIncluder includer;
57-
includer
58-
.sourceForInclude("modify_normal.h", "material.normal = vec3(0.8);");
54+
5955
filamat::MaterialBuilder builder;
6056
builder.material(fragmentCode.c_str());
6157
builder.materialVertex(vertexCode.c_str());
@@ -68,8 +64,7 @@ std::string shaderWithAllProperties(JobSystem& jobSystem, ShaderStage type,
6864
MaterialBuilder::PropertyList allProperties;
6965
std::fill_n(allProperties, MaterialBuilder::MATERIAL_PROPERTIES_COUNT, true);
7066

71-
// We need to "build" the material to resolve any includes in user code.
72-
builder.build(jobSystem);
67+
// Note: no need to call builder.build as we are only checking the properties.
7368

7469
return builder.peek(type, {
7570
ShaderModel::MOBILE,
@@ -735,25 +730,6 @@ TEST_F(MaterialCompiler, StaticCodeAnalyzerOutputFactor) {
735730
EXPECT_TRUE(PropertyListsMatch(expected, properties));
736731
}
737732

738-
TEST_F(MaterialCompiler, StaticCodeAnalyzerWithinInclude) {
739-
std::string fragmentCode(R"(
740-
void material(inout MaterialInputs material) {
741-
prepareMaterial(material);
742-
#include "modify_normal.h"
743-
}
744-
)");
745-
746-
std::string shaderCode = shaderWithAllProperties(*jobSystem, ShaderStage::FRAGMENT,
747-
fragmentCode);
748-
749-
GLSLTools glslTools;
750-
MaterialBuilder::PropertyList properties{ false };
751-
glslTools.findProperties(ShaderStage::FRAGMENT, shaderCode, properties);
752-
MaterialBuilder::PropertyList expected{ false };
753-
expected[size_t(filamat::MaterialBuilder::Property::NORMAL)] = true;
754-
EXPECT_TRUE(PropertyListsMatch(expected, properties));
755-
}
756-
757733
TEST_F(MaterialCompiler, EmptyName) {
758734
std::string shaderCode(R"(
759735
void material(inout MaterialInputs material) {

tools/matc/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ set(HDRS
1313
src/matc/CommandlineConfig.h
1414
src/matc/Compiler.h
1515
src/matc/DirIncluder.h
16+
src/matc/Includes.h
17+
src/matc/IncludeCallback.h
1618
src/matc/MaterialCompiler.h
1719
)
1820

1921
set(SRCS
2022
src/matc/Compiler.cpp
21-
src/matc/MaterialCompiler.cpp
2223
src/matc/CommandlineConfig.cpp
2324
src/matc/DirIncluder.cpp
25+
src/matc/Includes.cpp
26+
src/matc/MaterialCompiler.cpp
2427
)
2528

2629
# ==================================================================================================
@@ -70,10 +73,12 @@ install(TARGETS ${TARGET} RUNTIME DESTINATION bin)
7073
# ==================================================================================================
7174
project(test_matc)
7275
set(TARGET test_matc)
73-
set(SRCS tests/test_includer.cpp)
76+
set(SRCS tests/test_includer.cpp tests/test_includes.cpp)
7477

7578
add_executable(${TARGET} ${SRCS})
7679

7780
target_link_libraries(${TARGET} matlang gtest)
7881

82+
target_include_directories(${TARGET} PRIVATE ${filamat_SOURCE_DIR}/src)
83+
7984
set_target_properties(test_matc PROPERTIES FOLDER Tests)

tools/matc/src/matc/DirIncluder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace matc {
2424

25-
bool DirIncluder::operator()(const utils::CString& includedBy, filamat::IncludeResult& result) {
25+
bool DirIncluder::operator()(const utils::CString& includedBy, IncludeResult& result) {
2626
auto getHeaderPath = [&result, &includedBy, this]() {
2727
// includedBy is the path to the file that's including result.includeName.
2828
// If it's empty, then search from the root include directory.

tools/matc/src/matc/DirIncluder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef TNT_DIRINCLUDER_H_
1818
#define TNT_DIRINCLUDER_H_
1919

20-
#include <filamat/IncludeCallback.h>
20+
#include "IncludeCallback.h"
2121

2222
#include <utils/Path.h>
2323

@@ -31,7 +31,7 @@ class DirIncluder {
3131
mIncludeDirectory = dir;
3232
}
3333

34-
bool operator()(const utils::CString& includedBy, filamat::IncludeResult& result);
34+
bool operator()(const utils::CString& includedBy, IncludeResult& result);
3535

3636
private:
3737
utils::Path mIncludeDirectory;

libs/filamat/include/filamat/IncludeCallback.h renamed to tools/matc/src/matc/IncludeCallback.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef TNT_FILAMAT_INCLUDER_H
18-
#define TNT_FILAMAT_INCLUDER_H
17+
#ifndef TNT_INCLUDER_H
18+
#define TNT_INCLUDER_H
1919

2020
#include <utils/CString.h>
2121

2222
#include <functional>
2323

24-
namespace filamat {
24+
namespace matc {
2525

2626
struct IncludeResult {
2727
// The include name of the root file, as if it were being included.
@@ -64,6 +64,6 @@ using IncludeCallback = std::function<bool(
6464
const utils::CString& includedBy,
6565
IncludeResult& result)>;
6666

67-
} // namespace filamat
67+
} // namespace matc
6868

6969
#endif

libs/filamat/src/Includes.cpp renamed to tools/matc/src/matc/Includes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <filamat/Includes.h>
17+
#include "Includes.h"
1818

1919
#include <utils/Log.h>
2020
#include <utils/compiler.h>
2121
#include <utils/sstream.h>
2222

2323
#include <string>
2424

25-
namespace filamat {
25+
namespace matc {
2626

2727
static bool isWhitespace(char c) {
2828
return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
@@ -308,4 +308,4 @@ std::vector<FoundInclude> parseForIncludes(const utils::CString& source) {
308308
return results;
309309
}
310310

311-
} // namespace filamat
311+
} // namespace matc

libs/filamat/include/filamat/Includes.h renamed to tools/matc/src/matc/Includes.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef TNT_FILAMAT_INCLUDES_H
18-
#define TNT_FILAMAT_INCLUDES_H
17+
#ifndef TNT_INCLUDES_H
18+
#define TNT_INCLUDES_H
1919

20-
#include <filamat/IncludeCallback.h>
20+
#include "IncludeCallback.h"
2121

22-
#include <utils/CString.h>
22+
#include "utils/CString.h"
2323

2424
#include <vector>
2525

26-
namespace filamat {
26+
namespace matc {
2727

2828
struct ResolveOptions {
2929
// If true, insert #line directives before / after each include.
@@ -53,6 +53,6 @@ struct FoundInclude {
5353

5454
std::vector<FoundInclude> parseForIncludes(const utils::CString& source);
5555

56-
} // namespace filamat
56+
} // namespace matc
5757

5858
#endif

0 commit comments

Comments
 (0)