Ejemplo n.º 1
0
Resize::Resize(int srcWidth,
               int srcHeight,
               int destWidth,
               int destHeight)
: imageTexture(destWidth,
               destHeight,
               GL_RGBA,
               GL_RGB,
               GL_UNSIGNED_BYTE,
               false,
               true),
  vertexTexture(destWidth,
                destHeight,
                GL_RGBA32F,
                GL_LUMINANCE,
                GL_FLOAT,
                false,
                true),
  timeTexture(destWidth,
              destHeight,
              GL_LUMINANCE16UI_EXT,
              GL_LUMINANCE_INTEGER_EXT,
              GL_UNSIGNED_SHORT,
              false,
              true),
  imageProgram(loadProgramFromFile("empty.vert", "resize.frag", "quad.geom")),
  imageRenderBuffer(destWidth, destHeight),
  vertexProgram(loadProgramFromFile("empty.vert", "resize.frag", "quad.geom")),
  vertexRenderBuffer(destWidth, destHeight),
  timeProgram(loadProgramFromFile("empty.vert", "resize.frag", "quad.geom")),
  timeRenderBuffer(destWidth, destHeight)
{
   imageFrameBuffer.AttachColour(*imageTexture.texture);
   imageFrameBuffer.AttachDepth(imageRenderBuffer);

   vertexFrameBuffer.AttachColour(*vertexTexture.texture);
   vertexFrameBuffer.AttachDepth(vertexRenderBuffer);

   timeFrameBuffer.AttachColour(*timeTexture.texture);
   timeFrameBuffer.AttachDepth(timeRenderBuffer);
}
Ejemplo n.º 2
0
bool Assembler::assemble(string path){
	Assembler* ptr = this;
	setRootDirectory(parser.filePathToParentDirectory(path));
	setProgramName(parser.filePathToFileName(path));
	bool invalidateAssembly = false;
	try{
		loadProgramFromFile(programName);
		
		splitLabels();
		replaceEqv();
		extractMacroDefinitions();
		replaceMacros();
		pseudoInstructionPad();
		
		alignRawProgram();
		pseudoInstructionReplace();
		replaceLabels();

		writeAlignedRawProgramToDisk(rootDirectory + programName + alignedProgramNamePostfix);
		mapAlignedProgramToVirtualMemory();

		builtObjectFileName = rootDirectory + programName + objectNamePostfix;
		virtualMemory.serialize(builtObjectFileName);
	}catch(AssemblerException &e){
		string message = e.toString();
		cout << '\n' << message << '\n';
		invalidateAssembly = true;
	}catch(InvalidTokenException &e){
		cout << "ERROR [Assembler::assemble(string fileName)]: HANDLE INVALID TOKEN EXCEPTION IN ASSEMBLER!!!:\t" + e.toString();
		getchar();
	}
	if(recoverableExceptions.size() != 0 || invalidateAssembly){
		for(int i=0; i<recoverableExceptions.size(); i++){
			cout << recoverableExceptions[i].toString() << '\n';
		}
		return false;
	}
	return true;
}
Ejemplo n.º 3
0
void Assembler::loadProgramFromFile(string fileName, ProgramLine* programLine){
	string programFileDir = rootDirectory + fileName;
	fstream file = fstream(programFileDir);
	if(!file.is_open()){
		//EXCEPTION
		string error = "I'm sorry Dave, I'm afraid I can't open that file";
		string offendingToken = rootDirectory + fileName;
		throw AssemblerException(*programLine, error, offendingToken);
		return;
	}
	string tmpProgramLine;
	uint32_t lineNumber = 0;
	while(getline(file, tmpProgramLine)){
		tmpProgramLine = parser.sanitizeProgramLine(tmpProgramLine);
		
		string token = parser.toLower(parser.extractFirstToken(tmpProgramLine));
		if(token == ".include"){
			parser.extractAndRemoveFirstToken(tmpProgramLine, token);
			string nestedFileName = parser.trim(tmpProgramLine);
			nestedFileName = parser.removeNestedQuotes(nestedFileName);
			nestedFileName = parser.trim(nestedFileName);
			ProgramLine* programLinePtr = (program.size() == 0)? NULL : &program[program.size() - 1];
			loadProgramFromFile(nestedFileName, programLinePtr);
			continue;
		}

		if(tmpProgramLine != ""){
			ProgramLine programLine;
			programLine.fileName = rootDirectory + fileName;
			programLine.lineNumber = lineNumber;
			programLine.text = tmpProgramLine;
			program.push_back(programLine);
		}
		
		lineNumber++;
	}
}
Ejemplo n.º 4
0
GlobalModel::GlobalModel()
 : target(0),
   renderSource(1),
   bufferSize(MAX_VERTICES * Vertex::SIZE),
   count(0),
   initProgram(loadProgramFromFile("init_unstable.vert")),
   drawProgram(loadProgramFromFile("draw_feedback.vert", "draw_feedback.frag")),
   drawSurfelProgram(loadProgramFromFile("draw_global_surface.vert", "draw_global_surface.frag", "draw_global_surface.geom")),
   dataProgram(loadProgramFromFile("data.vert", "data.frag", "data.geom")),
   updateProgram(loadProgramFromFile("update.vert")),
   unstableProgram(loadProgramGeomFromFile("copy_unstable.vert", "copy_unstable.geom")),
   renderBuffer(TEXTURE_DIMENSION, TEXTURE_DIMENSION),
   updateMapVertsConfs(TEXTURE_DIMENSION, TEXTURE_DIMENSION, GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
   updateMapColorsTime(TEXTURE_DIMENSION, TEXTURE_DIMENSION, GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
   updateMapNormsRadii(TEXTURE_DIMENSION, TEXTURE_DIMENSION, GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
   deformationNodes(NODE_TEXTURE_DIMENSION, 1, GL_LUMINANCE32F_ARB, GL_LUMINANCE, GL_FLOAT)
{
    vbos = new std::pair<GLuint, GLuint>[2];

    float * vertices = new float[bufferSize];

    memset(&vertices[0], 0, bufferSize);

    glGenTransformFeedbacks(1, &vbos[0].second);
    glGenBuffers(1, &vbos[0].first);
    glBindBuffer(GL_ARRAY_BUFFER, vbos[0].first);
    glBufferData(GL_ARRAY_BUFFER, bufferSize, &vertices[0], GL_STREAM_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glGenTransformFeedbacks(1, &vbos[1].second);
    glGenBuffers(1, &vbos[1].first);
    glBindBuffer(GL_ARRAY_BUFFER, vbos[1].first);
    glBufferData(GL_ARRAY_BUFFER, bufferSize, &vertices[0], GL_STREAM_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    delete [] vertices;

    vertices = new float[Resolution::getInstance().numPixels() * Vertex::SIZE];

    memset(&vertices[0], 0, Resolution::getInstance().numPixels() * Vertex::SIZE);

    glGenTransformFeedbacks(1, &newUnstableFid);
    glGenBuffers(1, &newUnstableVbo);
    glBindBuffer(GL_ARRAY_BUFFER, newUnstableVbo);
    glBufferData(GL_ARRAY_BUFFER, Resolution::getInstance().numPixels() * Vertex::SIZE, &vertices[0], GL_STREAM_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    delete [] vertices;

    std::vector<Eigen::Vector2f> uv;

    for(int i = 0; i < Resolution::getInstance().width(); i++)
    {
        for(int j = 0; j < Resolution::getInstance().height(); j++)
        {
            uv.push_back(Eigen::Vector2f(((float)i / (float)Resolution::getInstance().width()) + 1.0 / (2 * (float)Resolution::getInstance().width()),
                                   ((float)j / (float)Resolution::getInstance().height()) + 1.0 / (2 * (float)Resolution::getInstance().height())));
        }
    }

    uvSize = uv.size();

    glGenBuffers(1, &uvo);
    glBindBuffer(GL_ARRAY_BUFFER, uvo);
    glBufferData(GL_ARRAY_BUFFER, uvSize * sizeof(Eigen::Vector2f), &uv[0], GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    frameBuffer.AttachColour(*updateMapVertsConfs.texture);
    frameBuffer.AttachColour(*updateMapColorsTime.texture);
    frameBuffer.AttachColour(*updateMapNormsRadii.texture);
    frameBuffer.AttachDepth(renderBuffer);

    updateProgram->Bind();

    int locUpdate[3] =
    {
        glGetVaryingLocationNV(updateProgram->programId(), "vPosition0"),
        glGetVaryingLocationNV(updateProgram->programId(), "vColor0"),
        glGetVaryingLocationNV(updateProgram->programId(), "vNormRad0"),
    };

    glTransformFeedbackVaryingsNV(updateProgram->programId(), 3, locUpdate, GL_INTERLEAVED_ATTRIBS);

    updateProgram->Unbind();

    dataProgram->Bind();

    int dataUpdate[3] =
    {
        glGetVaryingLocationNV(dataProgram->programId(), "vPosition0"),
        glGetVaryingLocationNV(dataProgram->programId(), "vColor0"),
        glGetVaryingLocationNV(dataProgram->programId(), "vNormRad0"),
    };

    glTransformFeedbackVaryingsNV(dataProgram->programId(), 3, dataUpdate, GL_INTERLEAVED_ATTRIBS);

    dataProgram->Unbind();

    unstableProgram->Bind();

    int unstableUpdate[3] =
    {
        glGetVaryingLocationNV(unstableProgram->programId(), "vPosition0"),
        glGetVaryingLocationNV(unstableProgram->programId(), "vColor0"),
        glGetVaryingLocationNV(unstableProgram->programId(), "vNormRad0"),
    };

    glTransformFeedbackVaryingsNV(unstableProgram->programId(), 3, unstableUpdate, GL_INTERLEAVED_ATTRIBS);

    unstableProgram->Unbind();

    initProgram->Bind();

    int locInit[3] =
    {
        glGetVaryingLocationNV(initProgram->programId(), "vPosition0"),
        glGetVaryingLocationNV(initProgram->programId(), "vColor0"),
        glGetVaryingLocationNV(initProgram->programId(), "vNormRad0"),
    };

    glTransformFeedbackVaryingsNV(initProgram->programId(), 3, locInit, GL_INTERLEAVED_ATTRIBS);

    glGenQueries(1, &countQuery);

    //Empty both transform feedbacks
    glEnable(GL_RASTERIZER_DISCARD);

    glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, vbos[0].second);

    glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbos[0].first);

    glBeginTransformFeedback(GL_POINTS);

    glDrawArrays(GL_POINTS, 0, 0);

    glEndTransformFeedback();

    glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

    glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, vbos[1].second);

    glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbos[1].first);

    glBeginTransformFeedback(GL_POINTS);

    glDrawArrays(GL_POINTS, 0, 0);

    glEndTransformFeedback();

    glDisable(GL_RASTERIZER_DISCARD);

    glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

    initProgram->Unbind();
}
Ejemplo n.º 5
0
int processor()
{
    pid_t pid;
    int result;
    //Creating the two pipes: toMemory and toProcessor.
    result = pipe(toMemory);
	if (result == -1)
		exit(1);
    result = pipe(toProcessor);
	if (result == -1)     
		exit(1);
    //Creating a child process
    pid = fork();
    
    switch(pid)
    {
        case -1:
        printf("The fork call was not completed. Check system configuration\n");
        exit(1);
        break;
        
                
        /*******************************************THIS IS THE MEMORY CODE**********************************/      
        case 0:
        result = -1;
        struct data obj;
        int memory[1000];
        //Load the program from the file
        result = loadProgramFromFile(memory, 1000);
        if (result == -1){     
            printf("\nError while reading the program from the file. Exiting Program.\n");
            fflush(stdout);
            exit(1);
        }
        read(toMemory[0], &obj , sizeof(obj));
		
        while(obj.controlCharacter!=' ')
        {
            switch(obj.controlCharacter)
            {
                //Read Operation. Data is written into data bus and sent to the parent/processor
                case 'r':
                obj.data = memory[obj.address];
                //to write the data into Data Bus
                write(toProcessor[1], &obj, sizeof(obj));                
                break;
                
                //Write Operation. Data from the data bus is written into the address from the Data Bus.
                case 'w':
                memory[obj.address] = obj.data;
                break;
                
                //Exit signal is sent to child process/memory. 
                case 'e':
                _exit(0);
                break;
                
                //Control Signal could not be identified. Erroneous control signal.
                default:
                printf("\n\nControl Signal could not be indentified\n\n");
                fflush(stdout);
                break;
            }
            read(toMemory[0], &obj, sizeof(obj));
        }
        _exit(0);
        break;
        
              
        /**********************************THIS IS THE PROCESSOR CODE******************************/
        default:
        
		result = -1;
        //Registers
		int PC, IR, SP, AC, X, Y, TEMP;
        char eop = '0';
        
        //Initialise the CPU registers
        initCPU(&PC,&SP,&IR,&AC,&X,&Y,&TEMP);
                
        while(eop == '0')
        {
            //Get the Instruction from the memory process by pipe and store it in IR
            IR = readDataFromMemory(PC);
            PC++;
            
                //printf("\nAC=%d ", AC);
                //printf("PC=%d ", PC-1);
            	//printf("IR=%d ", IR);
                //printf("SP=%d ", SP);
            	//printf("X=%d ", X);
                //printf("Y=%d\n", Y);
            
            
            //Code that will interpret instructions and execute them
            switch(IR)
            {        
                case 0:
                //No Operation instruction
                break;
                
                case 1:
                AC = readDataFromMemory(PC);
                PC++;
                break;
                
                case 2:
                TEMP = readDataFromMemory(PC);
                PC++;
                AC = readDataFromMemory(TEMP);
                break;
                
                case 3:
                TEMP = readDataFromMemory(PC);
                PC++;
                writeDataIntoMemory(TEMP,AC);                
                break;
                
                case 4:
                AC = AC + X;
                break;
                
                case 5:
                AC = AC + Y;
                break;
                
                case 6:
                AC = AC - X;
                break;
                
                case 7:
                AC = AC - Y;
                break;
                
                case 8:
                TEMP = readDataFromMemory(PC);
                PC++;
                fflush(stdout);
                char c;
                switch(TEMP)
                {
                    case 1:
                    scanf("%d",&AC);
                    break;
                    case 2:
                    scanf("%c",&c);
                    AC = c;
                    break;
                    default:
                    exitParent("Invalid operand for Get Port instruction");
                }
				break;
                
				//Put port instruction
                case 9:
                TEMP = readDataFromMemory(PC);
                PC++;
                switch(TEMP)
                {
                    case 1:
                    printf("%d",AC);
                    break;
                    
                    case 2:
                    printf("%c",AC);
                    break;
                    
                    default:
                    exitParent("Invalid operand for Put Port instruction.");
                }
                fflush(stdout);
                break;
                
                case 10:
                X=AC;
                break;
                
                case 11:
                Y=AC;
                break;
                
                case 12:
                AC=X;
                break;
                
                case 13:
                AC=Y;
                break;

                //Jump
                case 14:
                PC = readDataFromMemory(PC);
                break;
                
				//Jump if AC=0
                case 15:
                if(AC == 0)
                	PC = readDataFromMemory(PC);
                else
                    PC++;
                break;
                
				//Jump if AC!=0
                case 16:
                if(AC != 0)
                	PC = readDataFromMemory(PC);
                else
                    PC++;
                break;

                //Call subroutine
                case 17:
                TEMP=readDataFromMemory(PC);
                PC++;
                writeDataIntoMemory(SP,PC);
                PC = TEMP;
                SP = SP - 1;
                break;
                
				//Return
                case 18:
                SP = SP + 1;
                PC=readDataFromMemory(SP);
                break;
                
				//Increment X
                case 19:
                X = X + 1;
                break;
                //Decrement X
                case 20:
                X = X - 1;
                break;
                
                case 30:
                exitParent("");
                break;
                
                default:
                fflush(stdout);
                exitParent("Invalid Instruction encountered");
            }
        }
    }
    
    return 0;
}
Ejemplo n.º 6
0
IndexMap::IndexMap()
: indexProgram(loadProgramFromFile("index_map.vert", "index_map.frag")),
  indexRenderBuffer(Resolution::getInstance().width() * IndexMap::FACTOR, Resolution::getInstance().height() * IndexMap::FACTOR),
  indexTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
               Resolution::getInstance().height() * IndexMap::FACTOR,
               GL_LUMINANCE32UI_EXT,
               GL_LUMINANCE_INTEGER_EXT,
               GL_UNSIGNED_INT),
  vertConfTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
                  Resolution::getInstance().height() * IndexMap::FACTOR,
                  GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
  colorTimeTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
                   Resolution::getInstance().height() * IndexMap::FACTOR,
                   GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
  normalRadTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
                   Resolution::getInstance().height() * IndexMap::FACTOR,
                   GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
  drawDepthProgram(loadProgramFromFile("empty.vert", "visualise_textures.frag", "quad.geom")),
  drawRenderBuffer(Resolution::getInstance().width(), Resolution::getInstance().height()),
  drawTexture(Resolution::getInstance().width(),
              Resolution::getInstance().height(),
              GL_RGBA,
              GL_RGB,
              GL_UNSIGNED_BYTE,
              false),
  depthProgram(loadProgramFromFile("splat.vert", "depth_splat.frag")),
  depthRenderBuffer(Resolution::getInstance().width(), Resolution::getInstance().height()),
  depthTexture(Resolution::getInstance().width(),
               Resolution::getInstance().height(),
               GL_LUMINANCE32F_ARB,
               GL_LUMINANCE,
               GL_FLOAT,
               false,
               true),
  combinedProgram(loadProgramFromFile("splat.vert", "combo_splat.frag")),
  combinedRenderBuffer(Resolution::getInstance().width(), Resolution::getInstance().height()),
  imageTexture(Resolution::getInstance().width(),
               Resolution::getInstance().height(),
               GL_RGBA,
               GL_RGB,
               GL_UNSIGNED_BYTE,
               false,
               true),
  vertexTexture(Resolution::getInstance().width(),
                Resolution::getInstance().height(),
                GL_RGBA32F, GL_LUMINANCE, GL_FLOAT, false, true),
  normalTexture(Resolution::getInstance().width(),
                Resolution::getInstance().height(),
                GL_RGBA32F, GL_LUMINANCE, GL_FLOAT, false, true),
  timeTexture(Resolution::getInstance().width(),
              Resolution::getInstance().height(),
              GL_LUMINANCE16UI_EXT,
              GL_LUMINANCE_INTEGER_EXT,
              GL_UNSIGNED_SHORT,
              false,
              true),
  oldRenderBuffer(Resolution::getInstance().width(), Resolution::getInstance().height()),
  oldImageTexture(Resolution::getInstance().width(),
                  Resolution::getInstance().height(),
                  GL_RGBA,
                  GL_RGB,
                  GL_UNSIGNED_BYTE,
                  false,
                  true),
  oldVertexTexture(Resolution::getInstance().width(),
                   Resolution::getInstance().height(),
                   GL_RGBA32F, GL_LUMINANCE, GL_FLOAT, false, true),
  oldNormalTexture(Resolution::getInstance().width(),
                   Resolution::getInstance().height(),
                   GL_RGBA32F, GL_LUMINANCE, GL_FLOAT, false, true),
  oldTimeTexture(Resolution::getInstance().width(),
                 Resolution::getInstance().height(),
                 GL_LUMINANCE16UI_EXT,
                 GL_LUMINANCE_INTEGER_EXT,
                 GL_UNSIGNED_SHORT,
                 false,
                 true),
  infoRenderBuffer(Resolution::getInstance().width(), Resolution::getInstance().height()),
  colorInfoTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
                   Resolution::getInstance().height() * IndexMap::FACTOR,
                   GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
  vertexInfoTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
                   Resolution::getInstance().height() * IndexMap::FACTOR,
                   GL_RGBA32F, GL_LUMINANCE, GL_FLOAT),
  normalInfoTexture(Resolution::getInstance().width() * IndexMap::FACTOR,
                    Resolution::getInstance().height() * IndexMap::FACTOR,
                    GL_RGBA32F, GL_LUMINANCE, GL_FLOAT)

{
   indexFrameBuffer.AttachColour(*indexTexture.texture);
   indexFrameBuffer.AttachColour(*vertConfTexture.texture);
   indexFrameBuffer.AttachColour(*colorTimeTexture.texture);
   indexFrameBuffer.AttachColour(*normalRadTexture.texture);
   indexFrameBuffer.AttachDepth(indexRenderBuffer);

   drawFrameBuffer.AttachColour(*drawTexture.texture);
   drawFrameBuffer.AttachDepth(drawRenderBuffer);

   depthFrameBuffer.AttachColour(*depthTexture.texture);
   depthFrameBuffer.AttachDepth(depthRenderBuffer);

   combinedFrameBuffer.AttachColour(*imageTexture.texture);
   combinedFrameBuffer.AttachColour(*vertexTexture.texture);
   combinedFrameBuffer.AttachColour(*normalTexture.texture);
   combinedFrameBuffer.AttachColour(*timeTexture.texture);
   combinedFrameBuffer.AttachDepth(combinedRenderBuffer);

   oldFrameBuffer.AttachDepth(oldRenderBuffer);
   oldFrameBuffer.AttachColour(*oldImageTexture.texture);
   oldFrameBuffer.AttachColour(*oldVertexTexture.texture);
   oldFrameBuffer.AttachColour(*oldNormalTexture.texture);
   oldFrameBuffer.AttachColour(*oldTimeTexture.texture);

   infoFrameBuffer.AttachColour(*colorInfoTexture.texture);
   infoFrameBuffer.AttachColour(*vertexInfoTexture.texture);
   infoFrameBuffer.AttachColour(*normalInfoTexture.texture);
   infoFrameBuffer.AttachDepth(infoRenderBuffer);
}