Example #1
0
int main(int argc, char *argv[])
/* Process command line and call passes. */
{
char *command;

if (argc < 3)
    usage();
command = argv[1];
if (sameWord(command, "1"))
    {
    if (argc != 5)
	usage();
    firstPass(argv[2], argv[3], argv[4]);
    }
else if (sameWord(command, "2"))
    {
    if (argc != 4)
	usage();
    secondPass(argv[2], argv[3]);
    }
else if (sameWord(command, "3"))
    {
    if (argc != 4)
	usage();
    thirdPass(argv[2], argv[3]);
    }
else if (sameWord(command, "all"))
    {
    struct tempName tn1,tn2;
    if (argc != 5)
	usage();
    makeTempName(&tn1, "waba", ".1");
    makeTempName(&tn2, "waba", ".2");
    firstPass(argv[2], argv[3], tn1.forCgi);
    secondPass(tn1.forCgi,tn2.forCgi);
    thirdPass(tn2.forCgi,argv[4]);
    remove(tn1.forCgi);
    remove(tn2.forCgi);
    }
else if (sameWord(command, "view"))
    {
    if (argc != 3)
        usage();
    viewWaba(argv[2]);
    }
else
    {
    usage();
    }
}
Example #2
0
int main(int argc, char *argv[])
{
	char hackFileName[LENGTH_MAX];
	
	/* Init the fisrt available RAM address */
	RAMaddress = 16;

	/* Create the hack file (output) name */
	strcpy(hackFileName, argv[1]);
	createHackFileName(hackFileName);

	/* Init the symbol table */
	constructor();

	asmFile = fopen(argv[1], "r");

	/* First pass : create the symbol table */
	firstPass();

	fclose(asmFile);

	asmFile = fopen(argv[1], "r");
	hackFile = fopen(hackFileName, "w+");

	/* Second pass : create the binairy code */
	secondPass();

	fclose(asmFile);
	fclose(hackFile);

	return 0;
}
Example #3
0
Model*
ObjModelLoader::parseMultipass(string _fname, bool verbose)
{
	mPriFName.assign(_fname);

	mPriModelPtr = new Model();
	firstPass();

	secondPass();
	mPriModelPtr->resetGrpPtr();
	if (verbose) {
		cout << "Loaded model '" << mPriFName << "' with "
				<< mPriModelPtr->getFaceCount() << " # of Triangles in "
				<< mPriModelPtr->getGrpCount() << " Group(s)." << endl;
		cout << "# of Vertices: " << mPriModelPtr->getVertexCount() << " ("
				<< mPriModelPtr->getUniqueVertexCount() << " unique)." << endl;
		cout << "# of Normals: " << mPriModelPtr->getNormalCount() << " ("
				<< mPriModelPtr->getUniqueNormalCount() << " unique)." << endl;
		cout << "BoundingBox-Max: "
				<< mPriModelPtr->getBB()->getMax().toString() << endl;
		cout << "BoundingBox-Min: "
				<< mPriModelPtr->getBB()->getMin().toString() << endl;
		cout << "Variable-Content Vertices: " << mPriModelPtr->getVertexCount()
				<< endl;
		// TODO find out why he does not count the number of vertices correctly
		cout << "Variable-Content Triangles: " << mPriModelPtr->getFaceCount()
				<< endl;
	}

	Model *tempModel = mPriModelPtr;
	tempModel->setColorTable(mCTable);
	// do the cleanup - to get the model again one has to reload the file from disk
	cleanup();
	return tempModel;
}
Example #4
0
vector<LPPACKAGE> cvPic::getPrintPack()
{
    string srcImg = ImgName;									// 源图片的位置
    int num = 0;															// 连通图个数
    cv::Mat grayImg = cv::imread( srcImg );									// 将图片加载
    cv::Mat labelImg;
    vector<int> stRun,enRun,rowRun,runLabels;
    vector<pair<int,int>> equivalences;

    vector<int> imgX,imgY,imgColor;
    int imgWidth,imgHeight;

    cv::cvtColor( grayImg, labelImg, CV_BGR2GRAY );							// 灰度化图像
    cv::threshold( labelImg, labelImg, 150, 255, CV_THRESH_BINARY );		// 二值化图像

    packagePictureInfo( labelImg, imgX, imgY, imgColor );
    imgWidth = labelImg.cols;
    imgHeight = labelImg.rows;

    fillRunVectors( labelImg, num, stRun, enRun, rowRun );					// 完成团的标记与等价对列表的生成
    firstPass( stRun, enRun, rowRun, num, runLabels, equivalences, 1 );		// 八邻接
    replaceSameLabel( runLabels, equivalences );

    printf( "连通图数目为:%d\n", num );
    return getPackages(imgWidth,imgHeight,imgX,imgY,imgColor);
}
void CRUDependenceGraph::DumpGraph(CDSString &to)
{
	to += "\n\t\tDEPENDENCE GRAPH DRAWING START\n";

	to += "digraph G { \n\n";

	to += " graph [	fontname = \"Helvetica-Oblique\",page = \"8,10\", margin = \"1.5,1.5\"];\n\n";
	to += "node [style=filled,fontsize=14];\n\n";

	CRUTask *pTask;
	CRUTopologicalDGIterator firstPass(*this, CRUTopologicalDGIterator::DIRECT);

	for (; (pTask = firstPass.GetCurrentTask()) != NULL; firstPass.Next())
	{
		pTask->DumpGraphNode(to);
	}
	
	CRUTopologicalDGIterator secondPass(*this, CRUTopologicalDGIterator::DIRECT);

	for (; (pTask = secondPass.GetCurrentTask()) != NULL; secondPass.Next())
	{
		pTask->DumpGraphEdges(to);
	}

	to += "\n}\n\n\t\tDEPENDENCE GRAPH DRAWING END\n";
}
Example #6
0
size_t FieldStatic::firstPasses(size_t fromRow, bool first, bool async) {
    if (async && checkIncomingFirstPass(fromRow) == false) {
        return 0;
    }

    bool shouldProcess = recieveFirstPass(fromRow, first); // (crf + b + c + f) x [calculatingRows]

    if (shouldProcess == false) {
        // Sorry for that "workaround"
        return height * 2;
    }

    size_t row = fromRow;
    for (size_t bundleSize = 0; row < height && bundleSize < bundleSizeLimit; ++row) {
        if (calculatingRows[row] == false) {
            continue;
        }

        fillFactors(row, first);
        firstPass(row);
        ++bundleSize;
    }
    sendFirstPass(fromRow); // (crf + b + c + f) x [calculatingRows]

    return row;
}
//找最大的团并返回外轮廓
std::vector<MYPOINT> FindBiggestContour(cimg_library::CImg<unsigned char> origin, std::vector<MYPOINT> Points)
{
	std::vector<MYPOINT> contour;
	cimg_library::CImg<unsigned char> mask;
	//compute the binary img
	int threshold = otsu(origin, Points, mask, 1);
	unsigned char *bi_img = new unsigned char[origin.width()*origin.height()];
	for (int i = 0; i < origin.height(); i++){
		for (int j = 0; j < origin.width(); j++){
			if (origin.atXY(j, i) >= threshold && mask.atXY(j, i) == 255)
				bi_img[i*origin.width() + j] = 255;
			else
				bi_img[i*origin.width() + j] = 0;
		}
	}
	//返回二值图像
	cimg_library::CImg<unsigned char> bi(bi_img, origin.width(), origin.height());
	//done
	
	//找团
	std::vector<int> stRun, enRun, rowRun, masRun;
	int NumberofRuns = 0, offset = 1, maxRun = 1;
	fillRunVector(bi, NumberofRuns, stRun, enRun, rowRun, masRun);
	std::vector<int> runLabels;
	std::vector<std::pair<int, int>> equivalences;
	firstPass(stRun, enRun, rowRun, NumberofRuns, runLabels, equivalences, offset);
	if (!NumberofRuns){
		std::cout << "NOTHING FOUND!!!" << std::endl 
			<<"size of contour is: "<< contour.size() <<  std::endl;
		return contour;
	}
	replaceSameLabel(runLabels, equivalences);

	int maxLabel = *max_element(runLabels.begin(), runLabels.end());
	int *MassofRuns = new int[maxLabel + 1];
	memset(MassofRuns, 0, (maxLabel + 1)*sizeof(int));

	memset(bi_img, 0, (bi.height()*bi.width())*sizeof(unsigned char));
	for (int c = 0; c < NumberofRuns; c++){
		MassofRuns[runLabels[c]] += masRun[c];
		if (MassofRuns[runLabels[c]]>maxRun){
			maxRun = MassofRuns[runLabels[c]];
			maxLabel = runLabels[c];
		}
		int i = rowRun[c]; 
		for (int j = stRun[c]; j <= enRun[c]; j++){
			bi_img[i*bi.width() + j] = runLabels[c];
		}
	}
	for (int i = 0; i < bi.height(); i++)
	for (int j = 0; j < bi.width(); j++) {
		if (bi_img[i*bi.width()+j] == maxLabel)
			bi_img[i*bi.width() + j] = 255;
		else
			bi_img[i*bi.width() + j] = 0;
	}

	return FindContour(bi_img, bi.width(), bi.height());
}
SieveOfAtkin::SieveOfAtkin(const unsigned max_num)
{
    limit = max_num;
    sievelen = limit / DWORD_BITS + 1;
    mark = 0;

    sieve = new unsigned char[sievelen];
    for (unsigned i = 0; i < sievelen; i++)
    {
        sieve[i] = 0;
    }

    firstPass();
}
// constructor.
Sort::Sort ( char* inFile, char* outFile, int len_in, AttrType in[],
	     short str_sizes[], int fld_no, TupleOrder sort_order,
	     int amt_of_buf, Status& s )
{

	/* Setting the values for the member variables used inside tupleCmp function */

	int temp_offset=0;
	int temp_len=0;
	for (int i=0; i < len_in; i++)
	{
		if (i==fld_no) {
			offset = temp_offset;
			break;
		}
		else
		{
		  temp_offset=temp_offset+str_sizes[i];
		}

	}
	fieldLength=str_sizes[fld_no];
	attrType=in[fld_no];
	sortOrder1=sort_order;

	/*cout << "\noffset: " << offset;
	cout << "\nfieldLength: " <<fieldLength;
	cout << "\nattrType: " << attrType;
	cout << "\nsortOrder1: " <<sortOrder1 <<"\n";*/

	/* Computing the record length   */

	for (int i=0;i < len_in;i++)
	{
		temp_len = temp_len + str_sizes[i];
	}
	rec_len=temp_len;

	/* Setting the outFileName value */

	outFileName=outFile;

	firstPass(inFile,amt_of_buf,run_no);
	//cout <<"\nThe number of runs after First Pass is : " <<run_no<<"\n";
	followingPass(1,run_no,amt_of_buf,followingpass_run_no);

}
Example #10
0
int main(
    int  argc,
    char *argv[]
)
{
    double start = usecs();

        initCallback(argc, argv);
        mapBlockChainFiles();
        initHashtables();
        firstPass();
        secondPass();
        cleanMaps();

    double elapsed = (usecs()-start)*1e-6;
    info("all done in %.3f seconds\n", elapsed);
    return 0;
}
void ObstacleDetection::ObstacleDetecting(const int obstacleMap[120][120], RobPose cRobotPos)
{

    int cObstacleMap[120][120];
    memcpy(cObstacleMap, obstacleMap, 120*120*sizeof(int));

    stRun.clear();
    enRun.clear();
    rowRun.clear();
    runLabels.clear();
    equivalences.clear();
    numberOfRuns = 0;
    offset = 1;
    obsNum = 0;
    obsPoses.clear();

    std::stringstream out;
    out<<frames_num;
    std::string filename = "ObstacleMap" + out.str() + ".txt";
    std::ofstream Obstaclemapfile(filename);
    if (Obstaclemapfile.is_open())
    {
        for(int i = 0; i < 120; i++)
        {
            for(int j = 0; j < 120; j++)
            {
                Obstaclemapfile<<cObstacleMap[i][j]<<" ";
            }
            Obstaclemapfile<<std::endl;
        }
    }
    frames_num++;

    fillRunVectors(cObstacleMap, numberOfRuns, stRun, enRun, rowRun);

    if(numberOfRuns > 0)
    {
        firstPass(stRun, enRun, rowRun, numberOfRuns, runLabels, equivalences, offset);
        replaceSameLabel(runLabels, equivalences);
        FindObstacle(stRun, enRun, rowRun, numberOfRuns, runLabels, obsNum, obsPoses, cRobotPos);
        cout<<"Num of Obstalces: "<<obsNum<<endl;
    }
}
dgFloat32 dgWorldDynamicUpdate::CalculateJointForceJacobi1(const dgJointInfo* const jointInfo, const dgBodyInfo* const bodyArray, dgJacobian* const internalForces, dgJacobianMatrixElement* const matrixRow, dgFloat32 restAcceleration) const
{
	dgVector accNorm(dgVector::m_zero);
	const dgInt32 m0 = jointInfo->m_m0;
	const dgInt32 m1 = jointInfo->m_m1;

	dgVector linearM0(internalForces[m0].m_linear);
	dgVector angularM0(internalForces[m0].m_angular);
	dgVector linearM1(internalForces[m1].m_linear);
	dgVector angularM1(internalForces[m1].m_angular);
	const dgVector scale0(jointInfo->m_scale0);
	const dgVector scale1(jointInfo->m_scale1);

	const dgInt32 index = jointInfo->m_pairStart;
	const dgInt32 rowsCount = jointInfo->m_pairCount;

	dgFloat32 cacheForce[DG_CONSTRAINT_MAX_ROWS + 4];
	cacheForce[0] = dgFloat32(1.0f);
	cacheForce[1] = dgFloat32(1.0f);
	cacheForce[2] = dgFloat32(1.0f);
	cacheForce[3] = dgFloat32(1.0f);
	dgFloat32* const normalForce = &cacheForce[4];

	dgVector maxAccel(1.0e10f);
	dgFloat32 prevError = dgFloat32(1.0e20f);
	dgVector firstPass(dgVector::m_one);
	for (dgInt32 j = 0; (j < 5) && (maxAccel.GetScalar() > restAcceleration) && (prevError - maxAccel.GetScalar()) > dgFloat32(1.0e-2f); j++) {
		prevError = maxAccel.GetScalar();
		maxAccel = dgVector::m_zero;
		for (dgInt32 i = 0; i < rowsCount; i++) {
			dgJacobianMatrixElement* const row = &matrixRow[index + i];

			dgAssert(row->m_Jt.m_jacobianM0.m_linear.m_w == dgFloat32(0.0f));
			dgAssert(row->m_Jt.m_jacobianM0.m_angular.m_w == dgFloat32(0.0f));
			dgAssert(row->m_Jt.m_jacobianM1.m_linear.m_w == dgFloat32(0.0f));
			dgAssert(row->m_Jt.m_jacobianM1.m_angular.m_w == dgFloat32(0.0f));

			dgVector diag(row->m_JMinv.m_jacobianM0.m_linear * linearM0 + row->m_JMinv.m_jacobianM0.m_angular * angularM0 +
						  row->m_JMinv.m_jacobianM1.m_linear * linearM1 + row->m_JMinv.m_jacobianM1.m_angular * angularM1);

			dgVector accel(row->m_coordenateAccel - row->m_force * row->m_diagDamp - (diag.AddHorizontal()).GetScalar());
			dgVector force(row->m_force + row->m_invJMinvJt * accel.GetScalar());

			const dgInt32 frictionIndex = row->m_normalForceIndex;
			dgAssert(((frictionIndex < 0) && (normalForce[frictionIndex] == dgFloat32(1.0f))) || ((frictionIndex >= 0) && (normalForce[frictionIndex] >= dgFloat32(0.0f))));
			const dgFloat32 frictionNormal = normalForce[frictionIndex];
			dgVector lowerFrictionForce(frictionNormal * row->m_lowerBoundFrictionCoefficent);
			dgVector upperFrictionForce(frictionNormal * row->m_upperBoundFrictionCoefficent);

			accel = accel.AndNot((force > upperFrictionForce) | (force < lowerFrictionForce));
			dgVector accelAbs(accel.Abs());
			maxAccel = maxAccel.GetMax(accelAbs);
			accNorm = accNorm.GetMax(accelAbs * firstPass);
			dgAssert(maxAccel.m_x >= dgAbsf(accel.m_x));

			dgFloat32 f = (force.GetMax(lowerFrictionForce).GetMin(upperFrictionForce)).GetScalar();
			dgVector deltaForce(f - row->m_force);

			row->m_force = f;
			normalForce[i] = f;
			dgVector deltaforce0(scale0 * deltaForce);
			dgVector deltaforce1(scale1 * deltaForce);
			linearM0 += row->m_Jt.m_jacobianM0.m_linear * deltaforce0;
			angularM0 += row->m_Jt.m_jacobianM0.m_angular * deltaforce0;
			linearM1 += row->m_Jt.m_jacobianM1.m_linear * deltaforce1;
			angularM1 += row->m_Jt.m_jacobianM1.m_angular * deltaforce1;
		}
		firstPass = dgVector::m_zero;
	}

	for (dgInt32 i = 0; i < rowsCount; i++) {
		dgJacobianMatrixElement* const row = &matrixRow[index + i];
		row->m_maxImpact = dgMax(dgAbsf(row->m_force), row->m_maxImpact);
	}

	return accNorm.GetScalar();
}
Example #13
0
void OBJLoader::load(	ID3D11Device*	g_device,
						const char*		filename, 
						ID3D11Buffer**				vertex_buffer, 
						ID3D11Buffer**				index_buffer, 
						UINT&						n_vertices, 
						UINT&						n_indices, 
						UINT&						n_subsets,
						Subset**						subsets,
						vector<Material>&			vecMaterials,
						ID3D11ShaderResourceView**	srv,
						XMFLOAT4**					matDiffPtr,
						XMFLOAT4**					matSpecPtr,
						XMFLOAT4**					matRefrPtr,
						DWORD**						attributesPtr,
						XMFLOAT4**					aabboxPtr,
						UINT*						aabboxCount)
{

	this->g_device = g_device;
	g_device->AddRef();

	path_media = "../PMApp/";

	// make sure the folder path is set
	if (path_media == "")
		OutputDebugStringA("Warning: folder path not set!");

	std::ifstream file(path_media + filename);
	if (!file)
	{
		std::string message("OBJLoader file error: ");
		message = message.append(filename);
		MessageBoxA(0, message.c_str(), 0, 0);
	}
	
	firstPass(file);


	positions  = new XMFLOAT3[position_count];
	normals    = new XMFLOAT3[normal_count];
	uvs        = new XMFLOAT2[uv_count];
	
	vertices   = new Vertex[face_count*3];
	indices    = new DWORD[face_count*3];
	attributes = new DWORD[face_count];

	tri_tangents = new XMFLOAT3[face_count]; // one tangent for each triangle

	if (aabboxPtr != 0) { // AABBOX min/max vectors
		*aabboxPtr = new XMFLOAT4[(objects_count+1)*2];  // reserve +1 min/max pair for the global (root) aabbox
		memset(*aabboxPtr, 0, sizeof(XMFLOAT3) * (objects_count+1)*2);
		*aabboxCount = objects_count + 1;
	}
	XMFLOAT4* aabbArray = *aabboxPtr;

	glbIndicesPtr = indices;
	glbAttributesPtr = attributes;


	materialPass();
	secondPass(file, *aabboxPtr);
	file.close();
	computeVertexTangent();


	// Also return materials array and attributes array
	if (matDiffPtr != 0) {	// Diffuse
		*matDiffPtr = new XMFLOAT4[material_count];
		for (int i=0; i<material_count; i++) {
			(*matDiffPtr)[i] = materials[i].vDiffuse;
		}
	}
	
	if (matSpecPtr != 0) {	// Specular
		*matSpecPtr = new XMFLOAT4[material_count];
		for (int i=0; i<material_count; i++) {
			(*matSpecPtr)[i] = materials[i].vSpecular;
		}
	}

	if (matRefrPtr != 0) { // Refraction
		*matRefrPtr = new XMFLOAT4[material_count];
		for (int i=0; i<material_count; i++) {
			(*matRefrPtr)[i] = materials[i].vRefraction;
		}
	}

	

	//---------
	n_subsets = material_count;
	*subsets = new Subset[material_count];
	(*subsets)[0].startIndex = 0;


	for (int i=0; i<material_count; i++) {
		if (materials[i].pTextureNormalPRV10)
			materials[i].pTextureNormalPRV10->AddRef();
		if (materials[i].pTextureRV10)
			materials[i].pTextureRV10->AddRef();
		if (materials[i].pTextureSpecularPRV10)
			materials[i].pTextureSpecularPRV10->AddRef();
	}

	// put found materials in Mesh materials vector
	for (int i=0; i<material_count; i++) {
		vecMaterials.push_back(materials[i]);
	}

	int f = face_count;

	if (filename == "orig_bbox.obj") {
		for (UINT i=0; i<face_count-1; i++) {
			printf("%d:  %d , %d %d %d \n", i, attributes[i], indices[i*3+0], indices[i*3+1], indices[i*3+2]);
		}
	}
	printf("------------");

	// Sort indices based on material index in order to support multiple materials 
	DWORD val0, val1;
	UINT subsetId = 0;

	std::vector<XMFLOAT4> vertexIds;

	
	XMFLOAT4 v;

	for (UINT i=1; i<=objects_count; i++) {
			
		int start = (int)aabbArray[(i*2)+0].w;
		int end   = (int)aabbArray[(i*2)+1].w;

		v.x = (float)attributes[start];
		v.y = (float)indices[start * 3 + 0];
		v.z = (float)indices[start * 3 + 1];
		v.w = (float)indices[start * 3 + 2];
		vertexIds.push_back(v);

		//-----------
		v.x = (float)attributes[end];
		v.y = (float)indices[end * 3 + 0];
		v.z = (float)indices[end * 3 + 1];
		v.w = (float)indices[end * 3 + 2];
		vertexIds.push_back(v);
	}
	
	for (UINT i=0; i<face_count-1; i++) {
		// compare
		val0 = attributes[i];
		int less = i;
		DWORD lessVal = val0;
		for (UINT j = i + 1; j<face_count; j++) {
			val1 = attributes[j];

			if (val1 < lessVal) {
				less = j;
				lessVal = val1;
			}
		}
		
		
		// Change aabb pointers accordingly
		for (UINT k = 0; k<objects_count; k++) {
			for (int l=0; l<2; l++) 
			{
				if ((int)aabbArray[(k*2)+l].w == i)
					aabbArray[(k*2)+l].w = (float)less;
				else if ((int)aabbArray[(k*2)+l].w == less)
					aabbArray[(k*2)+l].w = (float)i;
			}
		}


		// Swap
		DWORD t0, t1, t2;
		t0 = indices[less*3+0];
		t1 = indices[less*3+1];
		t2 = indices[less*3+2];
		int t = attributes[less];

		for (UINT q=less; q>i; q--) {
			indices[q*3+0] = indices[(q-1)*3+0];
			indices[q*3+1] = indices[(q-1)*3+1];
			indices[q*3+2] = indices[(q-1)*3+2];
			attributes[q] = attributes[q-1];
		}

		indices[i*3+0] = t0;
		indices[i*3+1] = t1;
		indices[i*3+2] = t2;
		attributes[i] = t;

		// Mark start, end of subsets
		if (i == 0) continue;
		// Update subset structure 
		if (attributes[i-1] != attributes[i]) {
			subsetId++;
			(*subsets)[subsetId-1].size = i - (*subsets)[subsetId-1].startIndex;
			if (subsetId <= n_subsets-1)
				(*subsets)[subsetId].startIndex = i;
		}
		
	}

	// edge case 
	if (n_subsets > 1)
		(*subsets)[n_subsets-1].size = face_count - ((*subsets)[n_subsets-2].startIndex + (*subsets)[n_subsets-2].size);
	else
		(*subsets)[0].size = face_count;
	

	if (attributesPtr != 0) { // Attributes
		*attributesPtr = new DWORD[face_count];
		memcpy(*attributesPtr, attributes, face_count * sizeof(DWORD));

	}

	printf("\n\n");
	int array_id = 2;
	for (UINT i=0; i<objects_count*2; i++) 
	{
		for (UINT j=0; j<face_count; j++) 
		{
			if (attributes[j] == (int)vertexIds[i].x && 
				indices[j*3+0] == (int)vertexIds[i].y && 
				indices[j*3+1] == (int)vertexIds[i].z &&
				indices[j*3+2] == (int)vertexIds[i].w)
			{
				int id = 2 + (int)(i/2) + i%2;
				aabbArray[array_id].w = (float)j;
				array_id++;
			}
		}
	}


	if (filename == "orig_bbox.obj") {
		for (UINT i=0; i<face_count-1; i++) {
			printf("%d:  %d , %d %d %d \n", i, attributes[i], indices[i*3+0], indices[i*3+1], indices[i*3+2]);
		}
	}

	//-----------------------------------------------------------------

	// Create Vertex Buffer
	D3D11_BUFFER_DESC vb_desc;
	vb_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	if (srv != NULL)
		vb_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;

	vb_desc.ByteWidth = sizeof(Vertex) * vertex_count;
	vb_desc.CPUAccessFlags = 0;
	vb_desc.MiscFlags = 0;
	vb_desc.StructureByteStride = 0;
	vb_desc.Usage = D3D11_USAGE_DEFAULT;

	D3D11_SUBRESOURCE_DATA vb_data;
	vb_data.pSysMem = vertices;
	vb_data.SysMemPitch = vb_data.SysMemSlicePitch = 0;

	HRESULT hr = g_device->CreateBuffer(&vb_desc, &vb_data, vertex_buffer);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating Vertex Buffer", 0, 0);

	if (srv != NULL) {
		D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
		ZeroMemory(&srv_desc, sizeof(srv_desc));	
		g_device->CreateShaderResourceView(*vertex_buffer, &srv_desc, srv);
	}

	// Create Index Buffer
	D3D11_BUFFER_DESC ib_desc;
	ib_desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	ib_desc.ByteWidth = sizeof(DWORD) * face_count * 3;
	ib_desc.CPUAccessFlags = 0;
	ib_desc.MiscFlags = ib_desc.StructureByteStride = 0;
	ib_desc.Usage = D3D11_USAGE_DEFAULT;

	D3D11_SUBRESOURCE_DATA id_data;
	id_data.pSysMem = indices;
	id_data.SysMemPitch = id_data.SysMemSlicePitch = 0;

	hr = g_device->CreateBuffer(&ib_desc, &id_data, index_buffer);
	if (FAILED(hr))
		MessageBoxA(0, "Error creating Vertex Buffer", 0, 0);


	n_vertices = vertex_count;
	n_indices  = face_count * 3;

	
}