bool CD3DBuffer::CreateBuffer(const void* pData) { CD3D11_BUFFER_DESC bDesc(m_length, m_type, m_usage, m_cpuFlags); D3D11_SUBRESOURCE_DATA initData; initData.pSysMem = pData; return (S_OK == g_Windowing.Get3D11Device()->CreateBuffer(&bDesc, (pData ? &initData : nullptr), &m_buffer)); }
Map::Map() { m_iCurrentTexture = 0; m_timed = false; m_tex1 = Renderer::CreateTexture(TEX_WIDTH, TEX_HEIGHT); m_tex2 = Renderer::CreateTexture(TEX_WIDTH, TEX_HEIGHT); m_texture = m_tex1; m_vertices = NULL; //--------------------------------------------------------------------------- // Create verticies buffer CD3D11_BUFFER_DESC bDesc(GRID_WIDTH * GRID_HEIGHT * sizeof(PosColNormalUVVertex), D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE ); Renderer::GetDevice()->CreateBuffer(&bDesc, NULL, &m_vBuffer); //--------------------------------------------------------------------------- // Build verticies D3D11_MAPPED_SUBRESOURCE res; Renderer::GetContext()->Map(m_vBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res); PosColNormalUVVertex* v = (PosColNormalUVVertex*)res.pData; for (int y = 0; y < GRID_HEIGHT; y++) { for (int x = 0; x < GRID_WIDTH; x ++) { // 0-(32 / 2) / (32 / 2) = -1 // 15-(32 / 2) / (32 / 2) = -1 v->Coord.x = ((float)x - ((GRID_WIDTH -1 ) / 2.0f)) / ((GRID_WIDTH -1 ) / 2.0f); v->Coord.y = -(((float)y - ((GRID_HEIGHT -1 ) / 2.0f)) / ((GRID_HEIGHT -1 ) / 2.0f)); v->FDiffuse.x = 1.0f; v->FDiffuse.y = 1.0f; v->FDiffuse.z = 1.0f; v->FDiffuse.w = 1.0f; v->Coord.z = 0.0f; // v->u = ((((float)x - ((GRID_WIDTH -1 ) / 2.0f)) / ((GRID_WIDTH -1 ) / 2.0f) * 256 + 256) * (1.0f / 512)) + (0.5f / 512); // v->v = ((((float)y - ((GRID_HEIGHT -1 ) / 2.0f)) / ((GRID_HEIGHT -1 ) / 2.0f) * 256 + 256) * (1.0f / 512)) + (0.5f / 512); v->u = ((float)x / (GRID_WIDTH -1));// + (0.5f / TEX_SIZE); v->v = ((float)y / (GRID_HEIGHT -1));// + (0.5f / TEX_SIZE) ;//+ (5 / 512.0f); v++; } } Renderer::GetContext()->Unmap(m_vBuffer, 0); //--------------------------------------------------------------------------- // Build indices unsigned short indices[NUM_INDICES * 2], *pIndices = indices; int numIndices = 0; unsigned short iIndex = 0; for (int a = 0; a < GRID_HEIGHT - 1; ++a) { for (int i = 0; i < GRID_WIDTH; ++i, pIndices += 2, ++iIndex ) { pIndices[ 0 ] = iIndex + GRID_WIDTH; pIndices[ 1 ] = iIndex; numIndices+=2; } // connect two strips by inserting two degenerate triangles if (GRID_WIDTH - 2 > a) { pIndices[0] = iIndex - 1; pIndices[1] = iIndex + GRID_WIDTH; pIndices += 2; numIndices += 2; } } m_numIndices = numIndices - 2; //--------------------------------------------------------------------------- // Create indices buffer bDesc.ByteWidth = sizeof(indices); bDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; bDesc.Usage = D3D11_USAGE_IMMUTABLE; bDesc.CPUAccessFlags = 0; D3D11_SUBRESOURCE_DATA bData = { 0 }; bData.pSysMem = indices; Renderer::GetDevice()->CreateBuffer(&bDesc, &bData, &m_iBuffer); }