Skip to content

Commit b1add8d

Browse files
authored
Merge pull request #74 from brenocq/tutorial-fixes
Tutorial fixes
2 parents 696e7aa + 365fc3d commit b1add8d

File tree

14 files changed

+77
-61
lines changed

14 files changed

+77
-61
lines changed

CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
project(atta VERSION 0.3.6 LANGUAGES CXX C)
3+
project(atta VERSION 0.3.7 LANGUAGES CXX C)
44

55
option(ATTA_BUILD_TESTS "Set to ON to build also the test executables" ON)
66
option(ATTA_BUILD_DOCS "Build the documentation" OFF)
@@ -92,9 +92,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)#----- Web build
9292
endif()
9393

9494
if(ATTA_STATIC_PROJECT_FILE)
95-
# Copy project filee
95+
# Copy project file
9696
configure_file(${ATTA_STATIC_PROJECT_FILE} project/project.atta COPYONLY)
9797

98+
# Copy project resources
99+
# TODO it may fail if the resources are populated by the project CMakeLists.txt during the first build
98100
get_filename_component(projectDir ${ATTA_STATIC_PROJECT_FILE} DIRECTORY)
99101
if(EXISTS "${projectDir}/resources")
100102
file(COPY "${projectDir}/resources" DESTINATION "project")
@@ -222,10 +224,13 @@ if(ATTA_STATIC_PROJECT)
222224
set(ATTA_INSTALL_PCH ${ATTA_PCH})
223225
configure_file(cmake/attaConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/attaConfig.cmake" @ONLY)
224226

227+
# Build static project and link it if CMakeLists.txt exists
225228
get_filename_component(projectDirectory ${ATTA_STATIC_PROJECT_FILE} DIRECTORY)
226-
add_subdirectory(${projectDirectory} ${projectDirectory}/build)
227-
# The project targets will are saved to ATTA_PROJECT_TARGETS (atta_add_target macro)
228-
target_link_libraries(atta PUBLIC ${ATTA_PROJECT_TARGETS})
229+
if(EXISTS "${projectDirectory}/CMakeLists.txt")
230+
add_subdirectory(${projectDirectory} ${projectDirectory}/build)
231+
# The project targets will are saved to ATTA_PROJECT_TARGETS (atta_add_target macro)
232+
target_link_libraries(atta PUBLIC ${ATTA_PROJECT_TARGETS})
233+
endif()
229234

230235
# Populate ATTA_STATIC_PROJECT_SCRIPTS to write includes to scripts.h file
231236
set(ATTA_STATIC_PROJECT_SCRIPTS "")
@@ -260,10 +265,10 @@ if(NOT (ATTA_SYSTEM_NAME MATCHES "Web") AND NOT ATTA_STATIC_PROJECT_FILE)
260265
PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE}
261266
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE}
262267
)
263-
# Install atta-X.X.X.X executable
268+
# Install atta-X.X.X executable
264269
install(FILES $<TARGET_FILE:atta> TYPE BIN RENAME ${ATTA_VERSION_SAFE} PERMISSIONS WORLD_EXECUTE)
265270

266-
# Install atta_test-X.X.X.X executable
271+
# Install atta_test-X.X.X executable
267272
if(ATTA_BUILD_TESTS)
268273
install(TARGETS atta_test RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
269274
install(FILES $<TARGET_FILE:atta_test> TYPE BIN RENAME atta_test-${CMAKE_PROJECT_VERSION} PERMISSIONS WORLD_EXECUTE)
@@ -278,6 +283,8 @@ if(NOT (ATTA_SYSTEM_NAME MATCHES "Web") AND NOT ATTA_STATIC_PROJECT_FILE)
278283
FILES_MATCHING REGEX ".*\.(h|inl)$")
279284
install(DIRECTORY ${CMAKE_BINARY_DIR}/_deps/implot-src/ DESTINATION include/${ATTA_VERSION_SAFE}/extern/implot
280285
FILES_MATCHING REGEX ".*\.(h|cpp)$")
286+
install(DIRECTORY ${CMAKE_BINARY_DIR}/_deps/implot3d-src/ DESTINATION include/${ATTA_VERSION_SAFE}/extern/implot3d
287+
FILES_MATCHING REGEX ".*\.(h|cpp)$")
281288
install(DIRECTORY ${CMAKE_BINARY_DIR}/_deps/bullet3-src/ DESTINATION include/${ATTA_VERSION_SAFE}/extern/bullet3
282289
FILES_MATCHING REGEX ".*\.(h|cpp)$")
283290
install(DIRECTORY src/extern/glad/ DESTINATION include/${ATTA_VERSION_SAFE}/extern/glad
@@ -289,6 +296,7 @@ if(NOT (ATTA_SYSTEM_NAME MATCHES "Web") AND NOT ATTA_STATIC_PROJECT_FILE)
289296
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE})
290297
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE}/extern/imgui)
291298
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE}/extern/implot)
299+
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE}/extern/implot3d)
292300
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE}/extern/bullet3/src)
293301
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE}/extern/glad/include)
294302
list(APPEND ATTA_INSTALL_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include/${ATTA_VERSION_SAFE}/extern/stb_image)

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN_AFTER="false"
1515
PROJECT_TO_RUN=""
1616
INSTALL_AFTER="false"
1717
NUM_JOBS=""
18-
CMAKE_VULKAN=""
18+
CMAKE_VULKAN="-DATTA_VULKAN_SUPPORT=ON"
1919

2020
printHelp()
2121
{

cmake/attaConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro(atta_add_target target sources)
3535
endforeach()
3636
list(APPEND ATTA_PROJECT_HEADERS ${headers})
3737

38-
# This variable is used to know which targets shuld be linked to atta when building statically
38+
# This variable is used to know which targets should be linked to atta when building statically
3939
list(APPEND ATTA_PROJECT_TARGETS ${target})
4040
# Update variable
4141
get_directory_property(hasParent PARENT_DIRECTORY)

src/atta/component/factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Factory {
3535
Entity _firstClone; ///< First clone created
3636

3737
uint64_t _numEntitiesCloned; ///< Number of entities cloned (prototype entity and its children)
38-
uint64_t _numEntitiesInitialized; ///< Auxiliar variable to keep track of component creation
38+
uint64_t _numEntitiesInitialized; ///< Auxiliary variable to keep track of component creation
3939
};
4040
} // namespace atta::component
4141

src/atta/file/project/projectSerializer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ std::vector<Section> ProjectSerializer::serializeViewports() {
213213
section["camera.position"] = camera->getPosition();
214214
section["camera.lookAt"] = camera->getPosition() + camera->getFront();
215215
section["camera.up"] = camera->getUp();
216+
if (camera->getName() == "OrthographicCamera") {
217+
section["camera.height"] = std::dynamic_pointer_cast<gfx::OrthographicCamera>(camera)->getHeight();
218+
}
216219

217220
sections.push_back(std::move(section));
218221
}
@@ -580,6 +583,8 @@ void ProjectSerializer::deserializeViewport(const Section& section) {
580583
cInfo.lookAt = vec3(section["camera.lookAt"]);
581584
if (section.contains("camera.up"))
582585
cInfo.up = vec3(section["camera.up"]);
586+
if (section.contains("camera.height"))
587+
cInfo.height = float(section["camera.height"]);
583588
info.camera = std::make_shared<gfx::OrthographicCamera>(cInfo);
584589
} else if (cameraType == "PerspectiveCamera") {
585590
gfx::PerspectiveCamera::CreateInfo cInfo{};

src/atta/graphics/cameras/orthographicCamera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class OrthographicCamera : public Camera {
2727

2828
mat4 getView() const override;
2929
mat4 getProj() const override;
30+
float getHeight() const { return _height; }
3031

3132
private:
3233
virtual void movePlanar() override;

src/atta/graphics/manager.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,27 +343,33 @@ void Manager::onImageLoadEvent(event::Event& event) {
343343
}
344344

345345
void Manager::onImageUpdateEvent(event::Event& event) {
346-
// TODO update image
347-
// event::ImageUpdate& e = reinterpret_cast<event::ImageUpdate&>(event);
348-
// resource::Image* image = resource::get<resource::Image>(e.sid.getString());
349-
// if (image == nullptr) {
350-
// LOG_WARN("gfx::OpenGLAPI", "Could not create OpenGL texture from [w]$0[], image resource does not exists", e.sid.getString());
351-
// return;
352-
//}
353-
// if (_openGLImages.find(e.sid.getId()) == _openGLImages.end()) {
354-
// LOG_WARN("gfx::OpenGLAPI", "OpenGL texture [w]$0[] was not loaded before update", e.sid.getString());
355-
// return;
356-
//}
357-
358-
// std::shared_ptr<gl::Image> openGLImage = _openGLImages[e.sid.getId()];
359-
// if (openGLImage->getWidth() != image->getWidth() || openGLImage->getHeight() != image->getHeight())
360-
// openGLImage->resize(image->getWidth(), image->getHeight());
361-
// else
362-
// openGLImage->write(image->getData());
346+
event::ImageUpdate& e = reinterpret_cast<event::ImageUpdate&>(event);
347+
348+
// Get image resource
349+
resource::Image* imageRes = resource::get<resource::Image>(e.sid.getString());
350+
if (imageRes == nullptr) {
351+
LOG_WARN("gfx::Manager", "Could not update image from [w]$0[], image resource does not exists", e.sid.getString());
352+
return;
353+
}
354+
355+
// Get image
356+
if (_images.find(e.sid) == _images.end()) {
357+
_images[e.sid]->write(resource::get<resource::Image>(e.sid.getString())->getData());
358+
LOG_WARN("gfx::Manager", "Could not update image [w]$0[] that does not exists", e.sid);
359+
return;
360+
}
361+
std::shared_ptr<gfx::Image> image = _images[e.sid];
362+
363+
// Resize image if needed
364+
if (image->getWidth() != imageRes->getWidth() || image->getHeight() != imageRes->getHeight())
365+
image->resize(imageRes->getWidth(), imageRes->getHeight());
366+
367+
// Update image data
368+
image->write(imageRes->getData());
363369
}
364370

365371
void Manager::createMesh(StringId sid) {
366-
LOG_DEBUG("gfx::Manager", "Create mesh [w]$0[]", sid);
372+
LOG_VERBOSE("gfx::Manager", "Create mesh [w]$0[]", sid);
367373
resource::Mesh* mesh = resource::get<resource::Mesh>(sid.getString());
368374

369375
VertexBuffer::CreateInfo vertexInfo{};
@@ -402,7 +408,7 @@ void Manager::createMesh(StringId sid) {
402408
}
403409

404410
void Manager::createImage(StringId sid) {
405-
LOG_DEBUG("gfx::Manager", "Create image [w]$0[]", sid);
411+
LOG_VERBOSE("gfx::Manager", "Create image [w]$0[]", sid);
406412
resource::Image* image = resource::get<resource::Image>(sid);
407413
if (image == nullptr)
408414
LOG_WARN("gfx::Manager", "Could not initialize gfx::Image from [w]$0[]", sid);

src/atta/graphics/renderers/fastRenderer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ void FastRenderer::render(std::shared_ptr<Camera> camera) {
9898
_geometryPipeline->setMat4("uModel", model);
9999

100100
if (material) {
101-
if (material->colorIsImage()) {
102-
_geometryPipeline->setImageGroup(compMat->sid);
103-
_geometryPipeline->setVec3("uAlbedo", {-1, -1, -1});
104-
} else
105-
_geometryPipeline->setVec3("uAlbedo", material->getColor());
101+
_geometryPipeline->setImageGroup(compMat->sid);
102+
_geometryPipeline->setVec3("uAlbedo", material->colorIsImage() ? vec3(-1, -1, -1) : material->getColor());
106103
} else {
107104
resource::Material::CreateInfo defaultMaterial{};
108105
_geometryPipeline->setVec3("uAlbedo", defaultMaterial.color);

src/atta/script/interface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,27 @@ std::vector<StringId> getScriptSids();
2222
ProjectScript* getProjectScript();
2323
StringId getProjectScriptSid();
2424

25+
//----- Script Registration -----//
2526
#ifdef ATTA_STATIC_PROJECT
2627
ProjectScript* registerProjectScript(std::string name, ProjectScript* projectScript);
2728
Script* registerScript(std::string name, Script* script);
2829
#endif
2930

31+
#ifdef ATTA_STATIC_PROJECT
32+
template <typename T>
33+
class ScriptRegistration {
34+
static Script* reg;
35+
};
36+
#define ATTA_REGISTER_SCRIPT(TYPE) \
37+
template <> \
38+
inline ::atta::script::Script* ::atta::script::ScriptRegistration<TYPE>::reg = ::atta::script::registerScript(#TYPE, new TYPE());
39+
#else
40+
#define ATTA_REGISTER_SCRIPT(TYPE) \
41+
extern "C" { \
42+
std::pair<const char*, atta::script::Script*> createScript() { return {#TYPE, static_cast<atta::script::Script*>(new TYPE())}; } \
43+
}
44+
#endif
45+
3046
} // namespace atta::script
3147

3248
#endif // ATTA_SCRIPT_INTERFACE_H

src/atta/script/script.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,10 @@ namespace atta::script {
1313
class Script {
1414
public:
1515
Script() = default;
16-
virtual ~Script(){};
16+
virtual ~Script() {};
1717
virtual void update(component::Entity entity, float dt) = 0;
1818
};
1919

20-
#ifdef ATTA_STATIC_PROJECT
21-
template <typename T>
22-
class ScriptRegistration {
23-
static Script* reg;
24-
};
25-
#define ATTA_REGISTER_SCRIPT(TYPE) \
26-
template <> \
27-
inline ::atta::script::Script* ::atta::script::ScriptRegistration<TYPE>::reg = ::atta::script::registerScript(#TYPE, new TYPE());
28-
#else
29-
#define ATTA_REGISTER_SCRIPT(TYPE) \
30-
extern "C" { \
31-
std::pair<const char*, atta::script::Script*> createScript() { return {#TYPE, static_cast<atta::script::Script*>(new TYPE())}; } \
32-
}
33-
#endif
34-
3520
} // namespace atta::script
3621

3722
#endif // ATTA_SCRIPT_SCRIPT_H

0 commit comments

Comments
 (0)