Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gamedev/fggl
  • onuralpsezer/fggl
2 results
Show changes
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 23/07/22.
//
#include <gtest/gtest.h>
#include "fggl/util/safety.hpp"
namespace {
using TestType = fggl::util::OpaqueName<unsigned int, struct TestTag>;
TEST(SafetyHandle, CheckZero) {
auto v1 = TestType::make(0);
auto v2 = TestType::make(0);
EXPECT_EQ(v1, v2);
}
TEST(SafetyHandle, CheckValue) {
auto v1 = TestType::make(0x12345678);
auto v2 = TestType::make(0x12345678);
EXPECT_EQ(v1, v2);
}
TEST(SafetyHandle, CheckValueNE) {
auto v1 = TestType::make(0x12345678);
auto v2 = TestType::make(0x87654321);
EXPECT_NE(v1, v2);
}
}
\ No newline at end of file
add_executable(fgpak)
target_link_libraries(fgpak fggl)
target_sources(fgpak
PRIVATE
src/main.cpp
)
\ No newline at end of file
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 11/09/22.
//
#ifndef FGGL_TOOLS_PACK_SRC_BINARY_HPP
#define FGGL_TOOLS_PACK_SRC_BINARY_HPP
#include <cstdint>
#include <iostream>
#include <cstdio>
#include "fggl/data/model.hpp"
namespace fggl::data {
enum class ModelType {
OPENGL
};
struct ModelHeader {
unsigned long guid;
std::size_t size;
ModelType type;
};
void write_mesh(FILE* file, const Mesh& mesh) {
static_assert( std::is_standard_layout_v<Vertex> );
static_assert( std::is_standard_layout_v<Mesh::IndexType> );
// write vertex data
std::size_t vertexCount = mesh.vertexCount();
fwrite( &vertexCount, sizeof(vertexCount), 1, file );
fwrite( mesh.vertexList().data(), sizeof(Vertex), vertexCount, file );
std::size_t indexCount = mesh.indexCount();
fwrite( &indexCount, sizeof(indexCount), 1, file);
fwrite( mesh.indexList().data(), sizeof(Mesh::IndexType), indexCount, file);
}
void write_model(FILE* file, const ModelHeader& header, const Mesh& mesh) {
assert( header.type == ModelType::OPENGL );
fwrite( &header , sizeof(ModelHeader), 1, file);
write_mesh(file, mesh);
}
void read_mesh(FILE* fin, data::Mesh& mesh) {
static_assert( std::is_standard_layout_v<Vertex> );
static_assert( std::is_standard_layout_v<Mesh::IndexType> );
std::size_t readCount;
// vertex data
std::size_t vertexCount = 0;
readCount = fread( &vertexCount, sizeof(vertexCount), 1, fin );
assert(ferror(fin) == 0);
if (readCount != 1) {
std::cerr << "failed to read vertex count" << std::endl;
return;
}
// push vertex data into mesh
auto* vertexData = new data::Vertex[vertexCount];
readCount = fread( vertexData, sizeof(Vertex), vertexCount, fin );
assert(ferror(fin) == 0);
if ( readCount != vertexCount ) {
std::cerr << "failed to read vertex data" << std::endl;
return;
}
for ( std::size_t i = 0; i < vertexCount; ++i) {
mesh.pushVertex(vertexData[i]);
}
delete[] vertexData;
// read index size
std::size_t indexCount = 0;
readCount = fread( &indexCount, sizeof(indexCount), 1, fin);
assert(ferror(fin) == 0);
if (readCount != 1 ) {
std::cerr << "failed to read index count" << std::endl;
return;
}
// read index data
auto* idxData = new Mesh::IndexType[indexCount];
readCount = fread( idxData, sizeof(Mesh::IndexType), indexCount, fin);
assert(ferror(fin) == 0);
if (readCount != indexCount) {
std::cerr << "failed to read index data, expected: " << indexCount << ", got: " << readCount << std::endl;
return;
}
for (int i=0; i < indexCount; ++i) {
mesh.pushIndex( idxData[i] );
}
delete[] idxData;
}
void read_model(FILE* file, ModelHeader& header, Mesh& mesh) {
fread( &header, sizeof(ModelHeader), 1, file);
if ( header.type == ModelType::OPENGL ) {
read_mesh(file, mesh);
}
}
}
#endif //FGGL_TOOLS_PACK_SRC_BINARY_HPP