<commit_before>//------------------------------------------------------------------------------
//  ShapeBuilderTest.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "UnitTest++/src/UnitTest++.h"
#include "Render/Util/ShapeBuilder.h"
#include "Render/Core/stateWrapper.h"
#include "Render/Core/meshFactory.h"
#include "Render/Setup/RenderSetup.h"
#include "Render/Core/displayMgr.h"
#include "Render/Util/RawMeshLoader.h"
#include <cstring>

#if ORYOL_OPENGL
#include "Render/gl/gl_impl.h"
#endif

using namespace Oryol;
using namespace Oryol::IO;
using namespace Oryol::Core;
using namespace Oryol::Render;
using namespace Oryol::Resource;

//------------------------------------------------------------------------------
TEST(ShapeBuilderTest) {
    
    // setup a GL context
    auto renderSetup = RenderSetup::Windowed(400, 300, "Oryol Test");
    displayMgr displayManager;
    displayManager.SetupDisplay(renderSetup);
    
    // setup a meshFactory object
    stateWrapper stWrapper;
    meshFactory factory;
    factory.Setup(&stWrapper);
    factory.AttachLoader(RawMeshLoader::Create());
    
    // the state builder
    ShapeBuilder shapeBuilder;
    
    // build a simple cube
    shapeBuilder.AddComponent(VertexAttr::Position, VertexFormat::Float3);
    shapeBuilder.AddBox(1.0f, 1.0f, 1.0f, 1);
    shapeBuilder.Build();
    
    // ...create a mesh from it and verify the mesh
    mesh simpleCube;
    simpleCube.setSetup(MeshSetup::FromData(Locator("myCube")));
    simpleCube.setState(Resource::State::Setup);
    factory.SetupResource(simpleCube, shapeBuilder.GetStream());
    CHECK(simpleCube.GetVertexBufferAttrs().GetNumVertices() == 24);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetNumComponents() == 1);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetByteSize() == 12);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).IsValid());
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).GetAttr() == VertexAttr::Position);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).GetFormat() == VertexFormat::Float3);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).GetByteSize() == 12);
    CHECK(simpleCube.GetIndexBufferAttrs().GetNumIndices() == 36);
    CHECK(simpleCube.GetIndexBufferAttrs().GetIndexType() == IndexType::Index16);
    CHECK(simpleCube.GetIndexBufferAttrs().GetUsage() == Usage::Immutable);
    CHECK(simpleCube.GetNumPrimitiveGroups() == 1);<commit_msg>Fixed broken ShapeBuilderTest<commit_after>//------------------------------------------------------------------------------
//  ShapeBuilderTest.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "UnitTest++/src/UnitTest++.h"
#include "Render/Util/ShapeBuilder.h"
#include "Render/Core/stateWrapper.h"
#include "Render/Core/meshFactory.h"
#include "Render/Setup/RenderSetup.h"
#include "Render/Core/displayMgr.h"
#include "Render/Util/RawMeshLoader.h"
#include <cstring>

#if ORYOL_OPENGL
#include "Render/gl/gl_impl.h"
#endif

using namespace Oryol;
using namespace Oryol::IO;
using namespace Oryol::Core;
using namespace Oryol::Render;
using namespace Oryol::Resource;

//------------------------------------------------------------------------------
TEST(ShapeBuilderTest) {
    
    // setup a GL context
    auto renderSetup = RenderSetup::Windowed(400, 300, "Oryol Test");
    displayMgr displayManager;
    displayManager.SetupDisplay(renderSetup);
    
    // setup a meshFactory object
    stateWrapper stWrapper;
    meshFactory factory;
    factory.Setup(&stWrapper);
    factory.AttachLoader(RawMeshLoader::Create());
    
    // the state builder
    ShapeBuilder shapeBuilder;
    
    // build a simple cube
    shapeBuilder.AddComponent(VertexAttr::Position, VertexFormat::Float3);
    shapeBuilder.BeginPrimitiveGroup();
    shapeBuilder.AddBox(1.0f, 1.0f, 1.0f, 1);
    shapeBuilder.EndPrimitiveGroup();
    shapeBuilder.Build();
    
    // ...create a mesh from it and verify the mesh
    mesh simpleCube;
    simpleCube.setSetup(MeshSetup::FromData(Locator("myCube")));
    simpleCube.setState(Resource::State::Setup);
    factory.SetupResource(simpleCube, shapeBuilder.GetStream());
    CHECK(simpleCube.GetVertexBufferAttrs().GetNumVertices() == 24);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetNumComponents() == 1);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetByteSize() == 12);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).IsValid());
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).GetAttr() == VertexAttr::Position);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).GetFormat() == VertexFormat::Float3);
    CHECK(simpleCube.GetVertexBufferAttrs().GetVertexLayout().GetComponent(0).GetByteSize() == 12);
    CHECK(simpleCube.GetIndexBufferAttrs().GetNumIndices() == 36);
    CHECK(simpleCube.GetIndexBufferAttrs().GetIndexType() == IndexType::Index16);
    CHECK(simpleCube.GetIndexBufferAttrs().GetUsage() == Usage::Immutable);
    CHECK(simpleCube.GetNumPrimitiveGroups() == 1);
{'fraction_non_alphanumeric': 0.2174076865109269, 'fraction_numerical': 0.011680482290881688, 'mean_word_length': 3.2780016116035453, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131732', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1518, 'n_words': 235}