void MaterialServer::load( Resource &r ) { GraphicsSettingsWidget::Settings s = GraphicsSettingsWidget::Settings::settings(); res = &r; mat.clear(); efect.clear(); gbufPass.clear(); sspass.clear(); blpass.clear(); auto m = r.unitsMaterials(); for( auto i = m.begin(); i!=m.end(); ++i ) pushMaterial(*res, *i); blt = pushEfect(*res, "blt"); blt_to_tex = pushEfect(*res, "blt_to_tex"); mirron_blt = pushEfect(*res, "mirron_blt"); shadow_main[1] = idOfMaterial("shadow_main" ); shadow_main[2] = idOfMaterial("shadow_bias" ); shadow_main[3] = idOfMaterial("shadow_atest"); { Tempest::RenderState r = mat[shadow_main[2]]->m.renderState(); r.setCullFaceMode( Tempest::RenderState::CullMode::front ); mat[shadow_main[2]]->m.setRenderState(r); } { Tempest::RenderState r = mat[shadow_main[3]]->m.renderState(); r.setCullFaceMode( Tempest::RenderState::CullMode::front ); mat[shadow_main[3]]->m.setRenderState(r); } if( !s.atest ) shadow_main[3] = shadow_main[2]; { size_t id = idOfMaterial("terrain_minor"); Tempest::RenderState r; r.setZTestMode( Tempest::RenderState::ZTestMode::LEqual ); r.setBlend(1); r.setBlendMode( Tempest::RenderState::AlphaBlendMode::one, Tempest::RenderState::AlphaBlendMode::one ); mat[id]->m.setRenderState(r); } { size_t id = idOfMaterial("terrain"); Tempest::RenderState r; r.setZTestMode( Tempest::RenderState::ZTestMode::LEqual ); mat[id]->m.setRenderState(r); } main_material = idOfMaterial("main"); water = idOfMaterial("water"); hWater[0] = r.texture("water/height0"); hWater[1] = r.texture("water/height1"); Mat *waterM = mat[water].get(); sswater = find( sspass, waterM )!=sspass.end(); remove( sspass, waterM ); remove( gbufPass, waterM ); }
void GlModelData::initialize(const vector<tinyobj::shape_c_t>& shapes_c) { vector<float> positions; vector<float> normals; vector<float> texcoords; vector<float> tangents; vector<float> bitangents; vector<unsigned int> indices; int indexCount = 0; int shapeMeshIndexOffset = 0; for (vector<tinyobj::shape_c_t>::const_iterator shape = shapes_c.begin(); shape != shapes_c.end(); ++shape) { shapeMeshIndexOffset = positions.size() / 3; positions.insert(positions.end(), shape->mesh.positions.begin(), shape->mesh.positions.end()); normals.insert(normals.end(), shape->mesh.normals.begin(), shape->mesh.normals.end()); texcoords.insert(texcoords.end(), shape->mesh.texcoords.begin(), shape->mesh.texcoords.end()); tangents.insert(tangents.end(), shape->mesh.tangents.begin(), shape->mesh.tangents.end()); bitangents.insert(bitangents.end(), shape->mesh.bitangents.begin(), shape->mesh.bitangents.end()); // Offset new shape indices by previously pushed unique indices for (std::vector<unsigned int>::const_iterator shapeMeshIndex = shape->mesh.indices.begin(); shapeMeshIndex != shape->mesh.indices.end(); ++shapeMeshIndex) { indices.push_back(*shapeMeshIndex + shapeMeshIndexOffset); } shapeIndexStart.push_back(indexCount); shapeIndexCount.push_back(shape->mesh.indices.size()); indexCount += shape->mesh.indices.size(); materials.push_back(shape->material); pushMaterial(shape->material); } pushTextureSamplers(); unsigned int sizeOfPositions = sizeof(positions[0]) * positions.size(); unsigned int sizeOfNormals = sizeof(normals[0]) * normals.size(); unsigned int sizeOfTexcoords = sizeof(texcoords[0]) * texcoords.size(); unsigned int sizeOfTangents = sizeof(tangents[0]) * tangents.size(); unsigned int sizeOfBitangents = sizeof(bitangents[0]) * bitangents.size(); unsigned int sizeOfIndices = sizeof(indices[0]) * indices.size(); glGenBuffers(EboCount, m_ebos); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ebos[EboTriangles]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfIndices, &indices[0], GL_STATIC_DRAW); //No Vertex Attrib Pointer for Index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glGenVertexArrays(VaoCount, m_vaos); glGenBuffers(VboCount, m_vbos); glBindVertexArray(m_vaos[VaoTriangles]); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VboTriangles]); glBufferData(GL_ARRAY_BUFFER, sizeOfPositions + sizeOfNormals + sizeOfTexcoords + sizeOfTangents + sizeOfBitangents, NULL, GL_STATIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeOfPositions, &positions[0]); glBufferSubData(GL_ARRAY_BUFFER, sizeOfPositions, sizeOfNormals, &normals[0]); glBufferSubData(GL_ARRAY_BUFFER, sizeOfPositions + sizeOfNormals, sizeOfTexcoords, &texcoords[0]); glBufferSubData(GL_ARRAY_BUFFER, sizeOfPositions + sizeOfNormals + sizeOfTexcoords, sizeOfTangents, &tangents[0]); glBufferSubData(GL_ARRAY_BUFFER, sizeOfPositions + sizeOfNormals + sizeOfTexcoords + sizeOfTangents, sizeOfBitangents, &bitangents[0]); glVertexAttribPointer(AttributePosition, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); glVertexAttribPointer(AttributeNormal, 3, GL_FLOAT, GL_TRUE, 0, BUFFER_OFFSET(sizeOfPositions)); glVertexAttribPointer(AttributeTexcoord, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeOfPositions + sizeOfNormals)); glVertexAttribPointer(AttributeTangent, 3, GL_FLOAT, GL_TRUE, 0, BUFFER_OFFSET(sizeOfPositions + sizeOfNormals + sizeOfTexcoords)); glVertexAttribPointer(AttributeBitangent, 3, GL_FLOAT, GL_TRUE, 0, BUFFER_OFFSET(sizeOfPositions + sizeOfNormals + sizeOfTexcoords + sizeOfTangents)); glEnableVertexAttribArray(AttributePosition); glEnableVertexAttribArray(AttributeNormal); glEnableVertexAttribArray(AttributeTexcoord); glEnableVertexAttribArray(AttributeTangent); glEnableVertexAttribArray(AttributeBitangent); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); positions.clear(); normals.clear(); texcoords.clear(); tangents.clear(); bitangents.clear(); indices.clear(); }