void RenderableObject::Init() { //setup vao and vbo stuff glGenVertexArrays(1, &vaoID); glGenBuffers(1, &vboVerticesID); glGenBuffers(1, &vboIndicesID); //get total vertices and indices totalVertices = GetTotalVertices(); totalIndices = GetTotalIndices(); primType = GetPrimitiveType(); //now allocate buffers glBindVertexArray(vaoID); glBindBuffer (GL_ARRAY_BUFFER, vboVerticesID); glBufferData (GL_ARRAY_BUFFER, totalVertices * sizeof(glm::vec3), 0, GL_STATIC_DRAW); GLfloat* pBuffer = static_cast<GLfloat*>(glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY)); FillVertexBuffer(pBuffer); glUnmapBuffer(GL_ARRAY_BUFFER); glEnableVertexAttribArray(shader["vVertex"]); glVertexAttribPointer(shader["vVertex"], 3, GL_FLOAT, GL_FALSE,0,0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, totalIndices * sizeof(GLuint), 0, GL_STATIC_DRAW); GLuint* pIBuffer = static_cast<GLuint*>(glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY)); FillIndexBuffer(pIBuffer); glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); glBindVertexArray(0); }
Word Burger::DisplayDirectX9Software8::Init(Word uWidth,Word uHeight,Word /* uDepth */,Word uFlags) { Word uResult = DisplayDirectX9::Init(uWidth,uHeight,32,uFlags); if (!uResult) { m_uDepth = 8; // // Create the vertex buffer for software rendering // if (AllocateResources()!=D3D_OK) { uResult = 10; } else { m_Renderer.SetClip(0,0,static_cast<int>(uWidth),static_cast<int>(uHeight)); Word8 TempPalette[768]; MemoryClear(TempPalette,sizeof(TempPalette)); TempPalette[765]=255; TempPalette[766]=255; TempPalette[767]=255; //SetPalette(pSelf,TempPalette); FillVertexBuffer(); } } return uResult; }
int Load3ds::ProcessNextObjectChunk(Chunk * aPreviousChunk) { mCurrentChunk = new Chunk; size_t numberOfBytesRead; while (aPreviousChunk->mBytesRead < aPreviousChunk->mLength) { ReadChunk(mCurrentChunk); switch (mCurrentChunk->mID) { case OBJTRIMESH: // at this point, mBuffer will contain the name of the object being described ProcessNextObjectChunk(mCurrentChunk); ComputeNormals(); break; case TRIVERT: FillVertexBuffer(mCurrentChunk); break; case TRIFACE: FillIndexBuffer(mCurrentChunk); break; case TRIFACEMAT: // your getting a list of triangles that belong to a certain material SortIndicesByMaterial(mCurrentChunk); break; case TRIUV: FillTexCoordBuffer(mCurrentChunk); break; default: // unrecognized/unsupported chunk mCurrentChunk->mBytesRead += numberOfBytesRead = fread(mBuffer, 1, mCurrentChunk->mLength - mCurrentChunk->mBytesRead, mFile); #ifdef __BIG_ENDIAN__ for (int i = 0; i < numberOfBytesRead; i++) { static_cast<short *>(mBuffer)[i] = OSReadSwapInt16(&static_cast<short*>(mBuffer)[i],0); } #endif break; } aPreviousChunk->mBytesRead += mCurrentChunk->mBytesRead; } delete mCurrentChunk; mCurrentChunk = aPreviousChunk; return 1; }
bool Sprite::CreateSpriteDrawInfoandFillVertexBuffer(const sSprite &i_spriteDetails, const sRectangle &i_texcoords) { //Once we have texture we can go ahead and create the SpriteDrawInfo D3DSURFACE_DESC surfaceDescription; assert(m_texture); HRESULT result = m_texture->GetLevelDesc(0, &surfaceDescription); float TextureOriginalWidth = static_cast<float>(surfaceDescription.Width) / i_spriteDetails.horizontalSpriteCount; float TextureOriginalHeight = static_cast<float>(surfaceDescription.Height) / i_spriteDetails.verticalSpriteCount; m_spriteDrawInfo = SpriteDrawInfo(i_spriteDetails, i_texcoords, TextureOriginalWidth, TextureOriginalHeight); return FillVertexBuffer(); }
void RBExport::AddMesh( int meshID, int startVByte, int startVert, int nVert, int startFace, int nFaces ) { if (nVert == 0) return; // create mesh JMesh* pMesh = new JMesh(); char nameBuf[_MAX_PATH]; const char* nodeName = m_Nodes[m_Vertices[startVert]->nodeID].m_pNode->GetName(); sprintf( nameBuf, "%s_mesh", nodeName ); // create skin bone list std::vector<int> boneReindex; boneReindex.resize( m_Nodes.size() ); std::fill( boneReindex.begin(), boneReindex.end(), -1 ); int nMeshBones = 0; for (int i = 0; i < nVert; i++) { ExpVertex& v = *m_Vertices[startVert + i]; for (int j = 0; j < v.nBones; j++) { int boneIdx = v.boneIdx[j]; if (boneIdx == -1) continue; if (boneReindex[boneIdx] == -1) { pMesh->AddBone( m_Nodes[boneIdx].m_pNode->GetName() ); boneReindex[boneIdx] = nMeshBones; nMeshBones++; } v.boneIdx[j] = boneReindex[boneIdx]; } } if (pMesh->GetNSkinBones() > c_MaxBonesPerSkin) { Err( "Mesh %s exceeds bone limit. Number of ones is %d, maximum allowed is %d.", nodeName, pMesh->GetNSkinBones(), c_MaxBonesPerSkin ); } // check whether all the references to bones within indices are in correct range for (int i = 0; i < nVert; i++) { const ExpVertex& v = *(m_Vertices[startVert + i]); for (int j = 0; j < v.nBones; j++) { if (v.boneIdx[j] >= 0 && v.boneIdx[j] < pMesh->GetNSkinBones()) { continue; } Err( "Skin of mesh %s has incorrect bone reference: %d.", nodeName, v.boneIdx[j] ); } } // create vertex declaration VertexDeclaration vertexDecl = GetVDecl( startVert, nVert ); int vertexStride = vertexDecl.m_VertexSize; // create vertex buffer int nVertBytes = nVert*vertexStride; Buffer vbuf( nVertBytes ); FillVertexBuffer( vbuf.GetData(), vertexDecl, startVert, nVert ); // add vertices to model m_pModel->AddVertices( vbuf.GetData(), nVertBytes ); int mtlID = m_Vertices[startVert]->mtlID; const char* mtlName = ""; if (mtlID >= 0) mtlName = m_Materials[mtlID]->GetName(); int nodeID = m_Vertices[startVert]->nodeID; JObject* pHostBone = m_Nodes[nodeID].m_pObject; pMesh->SetName ( nameBuf ); pMesh->SetVisible ( true ); pMesh->SetVertexRange( startVByte, nVert ); pMesh->SetIndexRange ( startFace*3, nFaces*3 ); pMesh->SetVDecl ( vertexDecl ); pMesh->SetMaterial ( mtlName ); pMesh->SetHostBone ( pHostBone->GetName() ); // add faces to model std::vector<WORD> idx; int nIdx = 3*nFaces; idx.resize( nIdx ); for (int j = 0; j < nIdx; j += 3) { ExpFace& face = m_Faces[startFace + j/3]; idx[j + 0] = face.pV0->index - startVert; idx[j + 1] = face.pV1->index - startVert; idx[j + 2] = face.pV2->index - startVert; } m_pModel->AddIndices( &idx[0], nIdx ); m_pModel->AddChild( pMesh ); } // RBExport::AddMeshData