GLuint ObjectManager::obtainProgram( const void* key )
{
    const GLuint id = getProgram( key );
    if( id != INVALID )
        return id;
    return newProgram( key );
}
Beispiel #2
0
/* main
 *
 *	do some main stuff.
 */
int main( int argc, char ** argv )
{
	basic_program * bp;
	basic_line * bl;


	printf( "0\n" );
	/* set up our program space */
	bp = newProgram();
	if( !bp ) {
		errorReport( kErrorMalloc, 1 );
		return 0;
	}

	/* display version info */
	cmd_info( bp, NULL );

	bl = consumeString( bp, program[0] );
	bl = consumeString( bp, program[1] );
	bl = consumeString( bp, program[2] );
	bl = consumeString( bp, program[3] );
	bl = consumeString( bp, program[4] );

	/* and run the program, if we should... */
	printf( "Running program\n" );
	runProgram( bp, 0 );
	while( run_poll( bp ) );

	/* just show access of variables */
	printf( "Variable 'a' is %ld\n", getVariableNumber( bp->variables, "a" ));

	deleteProgram( bp );

	return 0;
}
Beispiel #3
0
LNZprogram* parseProgram( const char* filename, const u8* string, u64 length, const char** error ){
  LNZprogram* ans = newProgram();
  const u8* s = string;
  u64 l = length;
  do{
    u64 prsd = parseLine( ans, s, l, error );
    s += prsd;
    l -= prsd;
    if( *error != NULL ){
      u64 line = 1;
      u64 chr = 1;
      const u8* c = string;
      while( c != s ){
	if( *c == '\n' ){
	  chr = 1;
	  ++line;
	}else
	  ++chr;
	++c;
      }
	  

      u64 pep = rand() % ( sizeof( pepTalks ) / sizeof( pepTalks[ 0 ] ) );
      char* err = LNZmalloc( strlen( filename ) + strlen( *error ) + 
			     strlen( pepTalks[ pep ] ) + 256 );
      sprintf( err, "%s:%u:%u\n%s\n%s\n\n", filename, (int)line, (int)chr,
	       *error, pepTalks[ pep ] );
      *error = err;
      deleteProgram( ans );
      return NULL;
    }
  }while( l );
  return ans;
}
Beispiel #4
0
int main(){
    tas T = newProgram();
    node n1 = newNode(FORWARD, 1, 1);
    node n2 = newNode(REPEAT, 2, 2);
    incrementerHauteur();
    node n3 = newNode(RIGHT, 3, 3);  
    node n4 = newNode(REPEAT,4, 4);
    incrementerHauteur();
    node n5 = newNode(RIGHT,5, 5);
    decrementerHauteur();
    decrementerHauteur();
    node n6 = newNode(REPEAT,6, 6);
    incrementerHauteur();
    node n7 = newNode(LEFT,7, 7);
    decrementerHauteur();

    printf("Creation OK\n");
    
    addNode(T, n1);
    addNode(T, n2);
    addNode(T, n3);
    addNode(T, n4);
    addNode(T, n5);
    addNode(T, n6);
    addNode(T, n7);
    
    printf("Ajout OK\n");

    afficherProgramme(T);
    
    destroyProgram(T);
    
    return 0;
}
Beispiel #5
0
HdStGLSLProgramSharedPtr
HdStGLSLProgram::GetComputeProgram(
        TfToken const &shaderToken,
        HdStResourceRegistry *resourceRegistry)
{
    // Find the program from registry
    HdInstance<HdStGLSLProgram::ID, HdStGLSLProgramSharedPtr> programInstance;

    std::unique_lock<std::mutex> regLock = 
        resourceRegistry->RegisterGLSLProgram(
            HdStGLSLProgram::ComputeHash(shaderToken), &programInstance);

    if (programInstance.IsFirstInstance()) {
        // if not exists, create new one
        HdStGLSLProgramSharedPtr newProgram(
            new HdStGLSLProgram(HdTokens->computeShader));

        GlfGLSLFX glslfx(HdStPackageComputeShader());
        std::string version = "#version 430\n";
        if (!newProgram->CompileShader(
                GL_COMPUTE_SHADER, version + glslfx.GetSource(shaderToken))) {
            TF_CODING_ERROR("Fail to compile " + shaderToken.GetString());
            return HdStGLSLProgramSharedPtr();
        }
        if (!newProgram->Link()) {
            TF_CODING_ERROR("Fail to link " + shaderToken.GetString());
            return HdStGLSLProgramSharedPtr();
        }
        programInstance.SetValue(newProgram);
    }
    return programInstance.GetValue();
}
Beispiel #6
0
void					ParseYaml::reloadFile(void) {
	std::ifstream   	file;
	int					nbLine = 1;
	std::string			currentProgram = "";

	this->_programFeature.clear();
	file.open(this->_confFileName);
	if (!file.is_open()) {
		std::cerr << "ERROR file : " << this->_confFileName << " cant be opened." << std::endl;
		throw std::exception();
	}
	while (file.tellg() >= 0) {

		std::string			line = "";
		std::getline(file, line);
		this->_empturStr(line);
		if (line.size() > 0 && line.find(PROGRAM_DE) == 0) {
			if (line.find("]") != line.size() - 1) {
				std::cerr << "ERROR file : in line " << nbLine << " bad syntax." << std::endl;
				currentProgram = "";
			}
			else {
				currentProgram = line.substr(9, line.size() - 10);
				if (this->_programFeature.find(currentProgram) != this->_programFeature.end())
					std::cerr << "ERROR file : in line " << nbLine << " twice program name." << std::endl;
				else {
					ProgramFeature 		newProgram(currentProgram);
					this->_programFeature[currentProgram] = newProgram;
				}
				
			}
		} else if (line.size() > 0 && line == TASKMASTER_DE) {
			currentProgram = "Taskmaster";
		} else if (line.size() > 0) {
			if (currentProgram == "Taskmaster") {
				if (line.substr(0, 8) != "logfile=")
					std::cerr << "ERROR file : in line " << nbLine << " bad syntax." << std::endl;
				else
					this->_logFileName = line.substr(8, line.size());
			} else {
				if (this->_programFeature.find(currentProgram) == this->_programFeature.end()) {
					std::cerr << "No program declare to params in line " << nbLine << "." << std::endl;
				} else {
					this->_programFeature[currentProgram].setFeature(line, nbLine);
				}
			}
		}
		nbLine++;
	}
	for (m_feature::iterator it = this->_programFeature.begin(); it != this->_programFeature.end(); it++) {
		if (!it->second.isGood()) {
			std::cerr << "ERROR : [" << it->first << "] too much error to create process." << std::endl;
			this->_programFeature.erase(it);
		}
	}
	file.close();
	// this->dd();
}
Beispiel #7
0
int main(int argc,char**argv)
{
	string vss = loadShaderSrc("shaders/light.vert");
	string fss = loadShaderSrc("shaders/light.frag");

	engInit(argc,argv);

	GLuint vs = newShader(vss,GL_VERTEX_SHADER);
	GLuint fs = newShader(fss,GL_FRAGMENT_SHADER);

	GLuint prog = newProgram(vs,fs);
	glUseProgram(prog);
	glutMainLoop();
}
int main(int argc, char* argv[])
{  
   Window win(g_window_res);

  // initialize the transfer function
  Transfer_function transfer_fun;
  
  // first clear possible old values
  transfer_fun.reset();

  // the add_stop method takes:
  //  - unsigned char or float - data value     (0.0 .. 1.0) or (0..255)
  //  - vec4f         - color and alpha value   (0.0 .. 1.0) per channel
  
  
  //transfer fuer aufgabe 31 und 32
  transfer_fun.add(0.0f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(1.0f, glm::vec4(1.0, 1.0, 1.0, 1.0));
  
  // transfer fuer aufgabe 33
  /*transfer_fun.add(0.0f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(0.2f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(0.25f, glm::vec4(0.5, 0.5, 0.5, 0.1));
  transfer_fun.add(0.3f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(0.35f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(0.55f, glm::vec4(1.0, 1.0, 1.0, 0.2));
  transfer_fun.add(0.75f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(1.0f, glm::vec4(0.0, 0.0, 0.0, 0.0));*/
  
  // transfer fuer aufgabe 4
  /*transfer_fun.add(0.0f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(0.2f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(0.25f, glm::vec4(0.5, 0.5, 0.5, 1.0));
  transfer_fun.add(0.3f, glm::vec4(0.0, 0.0, 0.0, 0.0));
  transfer_fun.add(1.0f, glm::vec4(0.0, 0.0, 0.0, 0.0));*/

  ///NOTHING TODO UNTIL HERE-------------------------------------------------------------------------------
  
  //init volume loader
  Volume_loader_raw loader;
  //read volume dimensions
  glm::ivec3 vol_dimensions = loader.get_dimensions(g_file_string);

  unsigned max_dim = std::max(std::max(vol_dimensions.x,
                            vol_dimensions.y),
                            vol_dimensions.z);

  // calculating max volume bounds of volume (0.0 .. 1.0)
  glm::vec3 max_volume_bounds = glm::vec3(vol_dimensions) / glm::vec3((float)max_dim);
  
  // loading volume file data
  auto volume_data = loader.load_volume(g_file_string);
  auto channel_size = loader.get_bit_per_channel(g_file_string) / 8;
  auto channel_count = loader.get_channel_count(g_file_string);
  
  // init and upload volume texture
  glActiveTexture(GL_TEXTURE0);
  createTexture3D(vol_dimensions.x, vol_dimensions.y, vol_dimensions.z, channel_size, channel_count, (char*)&volume_data[0]);

  // init and upload transfer function texture
  glActiveTexture(GL_TEXTURE1);
  createTexture2D(255u, 1u, (char*)&transfer_fun.get_RGBA_transfer_function_buffer()[0]);

  // setting up proxy geometry
  Cube cube(glm::vec3(0.0, 0.0, 0.0), max_volume_bounds);

  // loading actual raytracing shader code (volume.vert, volume.frag)
  // edit volume.frag to define the result of our volume raycaster
  GLuint program(0);
  try {
    program = loadShaders(g_file_vertex_shader, g_file_fragment_shader);
  } catch (std::logic_error& e) {
    std::cerr << e.what() << std::endl;
  }

  // init object manipulator (turntable)
  Manipulator manipulator;

  // manage keys here
  // add new input if neccessary (ie changing sampling distance, isovalues, ...)
  while (!win.shouldClose()) {
    // exit window with escape
    if (win.isKeyPressed(GLFW_KEY_ESCAPE)) {
      win.stop();
    }

    if (win.isKeyPressed(GLFW_KEY_LEFT)) {
        g_light_pos.x -= 0.5f;
    }

    if (win.isKeyPressed(GLFW_KEY_RIGHT)) {
        g_light_pos.x += 0.5f;
    }

    if (win.isKeyPressed(GLFW_KEY_UP)) {
        g_light_pos.z -= 0.5f;
    }

    if (win.isKeyPressed(GLFW_KEY_DOWN)) {
        g_light_pos.z += 0.5f;
    }

    if (win.isKeyPressed(GLFW_KEY_MINUS)) {
        g_iso_value -= 0.002f;
        g_iso_value = std::max(g_iso_value, 0.0f);
    }
    
    if (win.isKeyPressed(GLFW_KEY_EQUAL) || win.isKeyPressed(GLFW_KEY_KP_ADD)) {
        g_iso_value += 0.002f;
        g_iso_value = std::min(g_iso_value, 1.0f);
    }

    if (win.isKeyPressed(GLFW_KEY_D)) {
        g_sampling_distance -= 0.0001f;
        g_sampling_distance = std::max(g_sampling_distance, 0.0001f);
    }

    if (win.isKeyPressed(GLFW_KEY_S)) {
        g_sampling_distance += 0.0001f;
        g_sampling_distance = std::min(g_sampling_distance, 0.2f);
    }
    //pre-classification
    if (win.isKeyPressed(GLFW_KEY_O)){
        g_switch_classification = 0;
    }
    //post-classification
    if (win.isKeyPressed(GLFW_KEY_L)) {
        g_switch_classification = 1;
    }

    // to add key inputs:
    // check win.isKeyPressed(KEY_NAME)
    // - KEY_NAME - key name      (GLFW_KEY_A ... GLFW_KEY_Z)
    
    //if (win.isKeyPressed(GLFW_KEY_X)){
    //    
    //        ... do something
    //    
    //}
    
    
    
    /// reload shader if key R ist pressed
    if (win.isKeyPressed(GLFW_KEY_R)) {
        if (g_reload_shader_pressed != true) {
            GLuint newProgram(0);
            try {
                std::cout << "Reload shaders" << std::endl;
                newProgram = loadShaders(g_file_vertex_shader, g_file_fragment_shader);
            }
            catch (std::logic_error& e) {
                std::cerr << e.what() << std::endl;
                newProgram = 0;
            }
            if (0 != newProgram) {
                glDeleteProgram(program);
                program = newProgram;
            }
            g_reload_shader_pressed = true;
        }
    } else {
        g_reload_shader_pressed = false;
    }

    /// show transfer function if T is pressed
    if (win.isKeyPressed(GLFW_KEY_T)){
        if (!g_show_transfer_function_pressed){
            g_show_transfer_function = !g_show_transfer_function;
        }
        g_show_transfer_function_pressed = true;
    } else {
        g_show_transfer_function_pressed = false;
    }

    auto size = win.windowSize();
    glViewport(0, 0, size.x, size.y);
    glClearColor(g_background_color.x, g_background_color.y, g_background_color.z, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    float fovy = 45.0f;
    float aspect = (float)size.x / (float)size.y;
    float zNear = 0.025f, zFar = 10.0f;
    glm::mat4 projection = glm::perspective(fovy, aspect, zNear, zFar);

    glm::vec3 translate = max_volume_bounds * glm::vec3(-0.5f);

    glm::vec3 eye = glm::vec3(0.0f, 0.0f, 1.5f);
    glm::vec3 target = glm::vec3(0.0f);
    glm::vec3 up(0.0f, 1.0f, 0.0f);

    auto view = glm::lookAt(eye, target, up);

    auto model_view = view
                    * manipulator.matrix(win)
                    // rotate head upright
                    * glm::rotate(0.5f*float(M_PI), glm::vec3(0.0f,1.0f,0.0f))
                    * glm::rotate(0.5f*float(M_PI), glm::vec3(1.0f,0.0f,0.0f))
                    * glm::translate(translate)
                    ;

    glm::vec4 camera_translate = glm::column(glm::inverse(model_view), 3);
    glm::vec3 camera_location = glm::vec3(camera_translate.x, camera_translate.y, camera_translate.z);

    camera_location /= glm::vec3(camera_translate.w);

    glm::vec4 light_location = glm::vec4(g_light_pos, 1.0f) * model_view;

    glUseProgram(program);

    glUniform1i(glGetUniformLocation(program, "volume_texture"), 0);
    glUniform1i(glGetUniformLocation(program, "transfer_texture"), 1);

    glUniform3fv(glGetUniformLocation(program, "camera_location"), 1,
        glm::value_ptr(camera_location));
    glUniform1f(glGetUniformLocation(program, "sampling_distance"), g_sampling_distance);
    glUniform1i(glGetUniformLocation(program, "switch_classification"), g_switch_classification);
    glUniform1f(glGetUniformLocation(program, "iso_value"), g_iso_value);
    glUniform3fv(glGetUniformLocation(program, "max_bounds"), 1,
        glm::value_ptr(max_volume_bounds));
    glUniform3iv(glGetUniformLocation(program, "volume_dimensions"), 1,
        glm::value_ptr(vol_dimensions));

    glUniform3fv(glGetUniformLocation(program, "light_position"), 1,
        //glm::value_ptr(glm::vec3(light_location.x, light_location.y, light_location.z)));
        glm::value_ptr(g_light_pos));
    glUniform3fv(glGetUniformLocation(program, "light_color"), 1,
        glm::value_ptr(g_light_color));

    glUniform3fv(glGetUniformLocation(program, "light_color"), 1,
        glm::value_ptr(g_light_color));

    glUniformMatrix4fv(glGetUniformLocation(program, "Projection"), 1, GL_FALSE,
        glm::value_ptr(projection));
    glUniformMatrix4fv(glGetUniformLocation(program, "Modelview"), 1, GL_FALSE,
        glm::value_ptr(model_view));
    cube.draw();
    glUseProgram(0);

    if (g_show_transfer_function)
        transfer_fun.update_and_draw();

    win.update();
  }

  return 0;
}
Beispiel #9
0
/**
 * Parse Tokens
 * Description: Takes a TokenList and a Command object and parses the TokenList in order
 *				to generate a command (list of programs in a pipeline);
 * Returns: true on success; false otherwise
 */
bool parseTokens( TokenList tokens, Command * command ) {

	bool success = true;

	Program *currentProgram = command->program = newProgram();
	bool begin = true;

	for (int i = 0; i < tokens.count; i++) {

		char * token = tokens.tokens[i];

		// Check if we are at the beginning of a program
		if ( begin ) {

			if ( strncmp( token, "time", max( strlen( token ), strlen( "time" ) ) ) == 0 ) {

				currentProgram->name = token;
				currentProgram->next = newProgram();
				currentProgram = currentProgram->next;
				begin = true;

				// If we have at least two tokens left and the next one is a pipe
				// then make a blank timed program
				// Note: This doesn't do anything since we don't allow
				//       piped time commands but this would help support it
				//       in the future and it currently prevents better
				//       error checking
				if ( i + 2 < tokens.count && isPipe( tokens.tokens[i+1] ) ) {

					currentProgram->name = NULL;
					currentProgram->next = newProgram();
					currentProgram = currentProgram->next;
					i++;

				}

			// The beginning of a program cannot be <, >, &, or |
			} else if ( !isRedirection( token ) && !isPipe( token ) && !isBackground( token ) ) {

				currentProgram->name = token;
				currentProgram->argv[currentProgram->argc++] = token;

				// Don't come back here again until we process a new program
				begin = false;

			} else {

				error("Program may not start with <, >, |, or &");
				success = false;
				break;

			}

		} else {

			// Process redirection
			if ( isRedirection( token ) ) {

				// Only one level of redirection allowed
				if ( currentProgram->redirect == DEFAULT ) {

					// Need to have at least one token after a redirect
					if ( i+1 < tokens.count ) {

						if ( !isRedirection(tokens.tokens[i+1]) && !isPipe(tokens.tokens[i+1]) 
							&& !isBackground(tokens.tokens[i+1]) ) {

							currentProgram->redirectResource = tokens.tokens[i+1];
							currentProgram->redirect = getRedirect( token );

							// Skip a token
							i++;

						} else {

							error("Expected file after a redirect");
							success = false;
							break;

						}


					} 

					// We can have redirections like <file or >file
					else if ( strlen( token ) > 1 ) {

						currentProgram->redirectResource = token+1;
						currentProgram->redirect = getRedirect( token );

					}
					else {

						error("Expected file after a redirect");
						success = false;
						break;

					}

				} else {

					error("Only one level of redirection allowed");
					success = false;
					break;

				}

			// Process pipe
			} else if ( isPipe( token ) ) {

				// Check if there's a token after this one
				if ( i+1 < tokens.count ) {

					currentProgram->next = newProgram();
					currentProgram = currentProgram->next;
					begin = true;

				}
				else {

					error("Expected program after pipe");
					success = false;
					break;

				}

			// Process background
			} else if ( isBackground( token ) ) {

				// & must be last token
				if ( i+1 >= tokens.count ) 
					command->background = true;
				else {

					error("& can only be placed at end of command");
					success = false;

				}

				break;
			}

			// Plain old argument
			else
				currentProgram->argv[currentProgram->argc++] = token;
		}

	}

	return success;
}