Index VertexPositionSet::addVertex(Vector3 position) { std::set<VertexPosition, std::less<VertexPosition>, Eigen::aligned_allocator<VertexPosition> >::iterator iterator = set_.find(VertexPosition(position)); if(iterator == set_.end()) { //New position Index new_index = mesh_->addVertex(position); std::pair< std::set<VertexPosition, std::less<VertexPosition>, Eigen::aligned_allocator<VertexPosition> >::iterator, bool> returned = set_.insert(VertexPosition(new_index, position)); assert(returned.second == true); iterator = returned.first; } return iterator->index(); }
/* Constructor shader = shader to use for drawing filenames = locations of the 6 textures cubemapVertices = (36) vertices of the cubemap Author: Bas Rops - 22-05-2014 Last edit: <name> - dd-mm-yyyy */ Cubemap::Cubemap(ShaderProgram* shader, std::string filenames[6], const std::vector<glm::vec3> &cubemapVertices) { if (shader != NULL) this->shader = shader; else std::cout << "Error initializing Cubemap: Shader == NULL" << std::endl; //Generate 1 texture glGenTextures(1, &texid); //Bind the texture as a cubemap texture glBindTexture(GL_TEXTURE_CUBE_MAP, texid); //Set cubemap parameters glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); //Load all 6 textures for the cubemap for (int i = 0; i < 6; i++) { std::string* filename = &filenames[i]; //Open the file FILE* pFile = fopen(filename->c_str(), "rb"); if (pFile) { //Get the data from the texture BYTE* data = stbi_load_from_file(pFile, &width, &height, &components, 4); //Close the file fclose(pFile); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); //Data no longer required, since it has been copied into a texture delete data; } else std::cout << "Error while loading cubemap texture: " << *filename << " does not exist." << std::endl; } //Add all vertices of the cubemap to a VBO std::vector<VertexPosition> vertices; for(const glm::vec3 &vertex : cubemapVertices) { vertices.push_back(VertexPosition(vertex)); } vbo = new VBO<VertexPosition>(); vbo->bind(); vbo->setData(vertices.size(), &vertices[0], GL_DYNAMIC_DRAW); vertices.clear(); }
void Filter::PreparePerPixelVertices() { int width = Texture::DefaultWidth; int height = Texture::DefaultHeight; List<VertexPosition> vertices; for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) vertices.push_back(VertexPosition(Vector3(x, y, 0))); PerPixelVertices = New<VertexBuffer>(); PerPixelVertices->SetData(vertices); }
Mesh* CreateWireframePlane(float xSize, float zSize, int xSegments, int zSegments, const glm::mat4& transform) { // sanity check if (xSegments < 1 || zSegments < 1) { return NULL; } float y = 0; float x = -0.5f * xSize; float z = -0.5f * zSize; float x1 = -0.5f * xSize; float x2 = 0.5f * xSize; float z1 = -0.5f * zSize; float z2 = 0.5f * zSize; float xSpacing = xSize / xSegments; float zSpacing = zSize / zSegments; // define world grid mesh data std::vector<VertexPosition> verts; // add back-to-front segments for (int i = 0; i <= xSegments; i++) { float x = x1 + i * xSpacing; verts.push_back(VertexPosition(x, y, z1)); verts.push_back(VertexPosition(x, y, z2)); } // add left-to-right segments for (int i = 0; i <= zSegments; i++) { float z = z1 + i * zSpacing; verts.push_back(VertexPosition(x1, y, z)); verts.push_back(VertexPosition(x2, y, z)); } // transform the vertices using the user-supplied transformation matrix TransformPositions(verts, transform); return CreateMesh(GL_LINES, verts); }
Mesh* CreateWireframeBox(float width, float height, float depth, const glm::mat4& transform) { float x1 = -0.5f * width; float x2 = 0.5f * width ; float y1 = -0.5f * height; float y2 = 0.5f * height; float z1 = -0.5f * depth; float z2 = 0.5f * depth; VertexPosition verts[] = { VertexPosition(x1, y1, z1), // 0 (left-bottom-back) VertexPosition(x1, y1, z2), // 1 (left-bottom-front) VertexPosition(x1, y2, z1), // 2 (left-top-back) VertexPosition(x1, y2, z2), // 3 (left-top-front) VertexPosition(x2, y1, z1), // 4 (right-bottom-back) VertexPosition(x2, y1, z2), // 5 (right-bottom-front) VertexPosition(x2, y2, z1), // 6 (right-top-back) VertexPosition(x2, y2, z2), // 7 (right-top-front) }; // line segments unsigned char inds[] = { // back-to-front 0, 1, 2, 3, 4, 5, 6, 7, // bottom-to-top 0, 2, 1, 3, 4, 6, 5, 7, // left-to-right 0, 4, 1, 5, 2, 6, 3, 7, }; unsigned numVerts = sizeof(verts) / sizeof(verts[0]); unsigned numInds = sizeof(inds) / sizeof(inds[0]); // transform the vertices using the user-supplied transformation matrix TransformPositions(verts, numVerts, transform); return CreateMesh(GL_LINES, verts, numVerts, inds, numInds); }
/** * Initializes the buffer with the given vertices, used to convert legacy layouts. * @param InVertices - The vertices to initialize the buffer with. */ void FPositionVertexBuffer::Init(const TArray<FStaticMeshBuildVertex>& InVertices) { NumVertices = InVertices.Num(); // Allocate the vertex data storage type. AllocateData(); // Allocate the vertex data buffer. VertexData->ResizeBuffer(NumVertices); Data = VertexData->GetDataPointer(); // Copy the vertices into the buffer. for(int32 VertexIndex = 0;VertexIndex < InVertices.Num();VertexIndex++) { const FStaticMeshBuildVertex& SourceVertex = InVertices[VertexIndex]; const uint32 DestVertexIndex = VertexIndex; VertexPosition(DestVertexIndex) = SourceVertex.Position; } }
Mesh MeshManager::createRectangle(const Gre::Surface &surface) { if ( surface.height > 0 && surface.width > 0 ) { std::string name = std::string ( "MeshRectangle#" ) + std::to_string(iMeshes.size()); std::string svbname = name + "/svb"; std::string sibname = name + "/sib"; // To create a Mesh, we have to fill a SoftwareVertexBuffer. SoftwareVertexBufferHolder svbholder = SoftwareVertexBufferHolder ( new SoftwareVertexBufferPrivate(svbname) ); if ( !svbholder.isInvalid() ) { VertexDescriptor vdesc; vdesc << VertexComponentType::Position; svbholder->setVertexDescriptor(vdesc); VertexPosition* data = (VertexPosition*) new VertexPosition[4]; data[0] = VertexPosition ( surface.left , surface.top , 0.0f ); data[1] = VertexPosition ( surface.left + surface.width , surface.top , 0.0f ); data[2] = VertexPosition ( surface.left + surface.width , surface.top - surface.height , 0.0f ); data[3] = VertexPosition ( surface.left , surface.top - surface.height , 0.0f ); svbholder->addData((const char*) data, sizeof(VertexPosition) * 4); } else { #ifdef GreIsDebugMode GreDebugPretty() << "SoftwareVertexBuffer '" << svbname << "' couldn't be created." << std::endl; #endif return Mesh ( nullptr ); } // We also try to fill a SoftwareIndexBuffer. SoftwareIndexBufferHolder sibholder = SoftwareIndexBufferHolder ( new SoftwareIndexBufferPrivate(sibname) ); if ( !sibholder.isInvalid() ) { IndexDescriptor idesc; idesc.setType(IndexType::UnsignedInteger); unsigned int data[6] = { 0, 1, 2, 2, 3, 0 }; sibholder->setIndexDescriptor(idesc, 0); sibholder->addDataToIndexBatch((const char*) data, sizeof(unsigned int) * 6, 0); } else { #ifdef GreIsDebugMode GreDebugPretty() << "SoftwareIndexBuffer '" << sibname << "' couldn't be created." << std::endl; #endif return Mesh ( nullptr ); } // Now we can add those two HardwareBuffer to a Mesh object. MeshHolder rectangle = MeshHolder ( new MeshPrivate(name) ); if ( !rectangle.isInvalid() ) { rectangle->setSoftwareVertexBuffer(SoftwareVertexBuffer(svbholder)); rectangle->setSoftwareIndexBuffer(SoftwareIndexBuffer(sibholder)); // Everything is set, just add this Mesh to the list and return it. iMeshes.add(rectangle); return Mesh ( rectangle ); } else { #ifdef GreIsDebugMode GreDebugPretty() << "Mesh '" << name << "' couldn't be created." << std::endl; #endif return Mesh ( nullptr ); } } else { #ifdef GreIsDebugMode GreDebugPretty() << "Can't create a Mesh Resource using null Surface." << std::endl; #endif return Mesh ( nullptr ); } }