Exemplo n.º 1
0
//--------------------------------------------------------------
void testApp::update(){
    
    if (bUsePBO) {
        //pbo.writeToTexture(texture);

        pbo.allocate(2048, 2048, GL_RGBA32I);
        //unsigned int* gpuMemory = (unsigned int*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, 2048*2048*4, GL_MAP_WRITE_BIT|GL_MAP_UNSYNCHRONIZED_BIT);
        unsigned int* gpuMemory = (unsigned int*)pbo.map(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
        if (gpuMemory) {
            updatePixels(gpuMemory);
            //glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
            pbo.unmap();
        }
        else {
            GLenum error = glGetError();
            if (error != GL_NO_ERROR) ofLogError("update()", ofToString(gluErrorString(error)));
        }
        

        //glEnable(GL_TEXTURE_RECTANGLE);
        glBindTexture(GL_TEXTURE_RECTANGLE, tex);
        pbo.bind();
        glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE);
        //glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
        unsigned long long start = ofGetElapsedTimeMicros();
        glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, 2048, 2048, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
        time = (ofGetElapsedTimeMicros() - start) * 0.1 + time * 0.9;
        pbo.unbind();
        glBindTexture(GL_TEXTURE_RECTANGLE, 0);
        //glDisable(GL_TEXTURE_RECTANGLE);
        glFlush();

    }
    else {
        updatePixels(cpuMemory);
        
        unsigned long long start = ofGetElapsedTimeMicros();
        glEnable(GL_TEXTURE_RECTANGLE);
        glBindTexture(GL_TEXTURE_RECTANGLE, tex);
        glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, 2048, 2048, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, cpuMemory);
        //glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 2048, 2048, 0, GL_RGBA, GL_UNSIGNED_BYTE, cpuMemory);
        GLenum error = glGetError();
        if (error != GL_NO_ERROR) ofLogError("update()", ofToString(gluErrorString(error)));
        glBindTexture(GL_TEXTURE_RECTANGLE, 0);
        glDisable(GL_TEXTURE_RECTANGLE);
        //glDisable(GL_TEXTURE0);
        glFlush();
        
        time = (ofGetElapsedTimeMicros() - start) * 0.1 + time * 0.9;
    }
    
}
Exemplo n.º 2
0
int main() {
	init();
	SerialHandler serialHandler(PORT, BAUD_RATE);
	while(true) {
		updatePixels();
		int sumR = 0, sumG = 0, sumB = 0;
		const int x1 = 0, y1 = 0, x2 = SCR_W, y2 = SCR_H, SAMPLES = 5;
		for(int x = x1; x < x2; x += SAMPLES) {
			for(int y = y1; y < y2; y += SAMPLES) {
				Color color = getPixel(x, y);
				sumR += color.r; sumG += color.g; sumB += color.b;
			}
		}
		int totalPixels = ((x2 - x1) * (y2 - y1)) / (SAMPLES * SAMPLES);
		sumR /= totalPixels; sumG /= totalPixels; sumB /= totalPixels;
		int h = 0, s = 0, v = 0;
		RGBtoHSV(sumR, sumG, sumB, &h, &s, &v);
        v = (v * s) / 255;
		s = 255;
		HSVtoRGB(&sumR, &sumG, &sumB, h, s, v);
		serialHandler.writeSerial(sumR, sumG, sumB);
		delay(10);
	}
	deinit();
	return 0;
}
Exemplo n.º 3
0
 text_rsrc::text_rsrc( float p,
                       std::string f,
                       std::string s ) : gui_resource( 0, 0 )
 {
     tex_offset[ 0 ] = 0;
     tex_offset[ 1 ] = 0;
     
     string = s;
     font = f;
     point_size = p;
     
     color[ 0 ] = 1.0f;
     color[ 1 ] = 1.0f;
     color[ 2 ] = 1.0f;
     color[ 3 ] = 1.0f;
     
     max_dimensions[ 0 ] = -1;
     max_dimensions[ 1 ] = -1;
     // max_dimensions[ 0 ] = 24;
     // max_dimensions[ 1 ] = 24;
     
     ellipsize = NONE;
     hinting_enabled = false;
     antialiasing_enabled = true;
     
     pixel_space = NULL;
     gl_tex = 0x00;
     
     update_tex = true;
     updatePixels();
 }
Exemplo n.º 4
0
 void text_rsrc::setAntialiasing( bool a )
 {
     scoped_lock< mutex > slock( text_mutex );
     
     antialiasing_enabled = a;
     
     update_tex = true;
     updatePixels();
 }
Exemplo n.º 5
0
 void text_rsrc::setHinting( bool h )
 {
     scoped_lock< mutex > slock( text_mutex );
     
     hinting_enabled = h;
     
     update_tex = true;
     updatePixels();
 }
Exemplo n.º 6
0
void ofxOMXPlayer::saveImage(string imagePath)//default imagePath=""
{
	if(imagePath == "")
	{
		imagePath = ofGetTimestampString()+".png";
	}
	updatePixels();
	ofSaveImage(GlobalEGLContainer::getInstance().pixels, ofGetTimestampString()+".png");
	
}
Exemplo n.º 7
0
void draw() {

  loadPixels();
  
  // Maximum number of iterations for each point on the complex plane
  int maxiterations = 100;

  // x goes from xmin to xmax
  double xmax = xmin + w;
  // y goes from ymin to ymax
  double ymax = ymin + h;
  
  // Calculate amount we increment x,y for each pixel
  double dx = (xmax - xmin) / (sketchWidth);
  double dy = (ymax - ymin) / (sketchHeight);

  // Start y
  double y = ymin;
  for(int j = 0; j < sketchHeight; j++) {
    // Start x
    double x = xmin;
    for(int i = 0;  i < sketchWidth; i++) {
      
      // Now we test, as we iterate z = z^2 + cm does z tend towards infinity?
      double a = x;
      double b = y;
      int n = 0;
      while (n < maxiterations) {
        double aa = a * a;
        double bb = b * b;
        double twoab = 2.0 * a * b;
        a = aa - bb + x;
        b = twoab + y;
        // Infinty in our finite world is simple, let's just consider it 16
        if(aa + bb > 16.0f) {
          break;  // Bail
        }
        n++;
      }
      
      // We color each pixel based on how long it takes to get to infinity
      // If we never got there, let's pick the color black
      if (n == maxiterations) setPixel(i, j, color(0, 0, 0));
      else {
        int cl = n*16 % 255;
        setPixel(i, j, color(cl, cl, cl));  // Gosh, we could make fancy colors here if we wanted
      }
      x += dx;
    }
    y += dy;
  }
  updatePixels();
  
  noLoop();
}
void ofxVirtualCamera::update() {
	kinect.update();
	if(kinect.isFrameNew()) {
		newFrame = true;
		
		updateSurface();
		updateMesh();
		renderCamera();
		updatePixels();
	}
}
Exemplo n.º 9
0
 void text_rsrc::setString( std::string s )
 {
     scoped_lock< mutex > slock( text_mutex );
     
     string = s;
     
     // TODO: While setString() will almost always be called from the main
     // thread (element creation, changing due to events), there may be cases
     // where it is not.  Fix this if it becomes a problem.
     
     update_tex = true;
     updatePixels();
 }
Exemplo n.º 10
0
JNIEXPORT void JNICALL
Java_com_iiordanov_aSPICE_SpiceCommunicator_UpdateBitmap (JNIEnv* env, jobject obj, jobject bitmap, gint x, gint y, gint width, gint height) {
	void* pixels;
    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(global_display);

	if (AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0) {
		__android_log_write(6, "android-io", "AndroidBitmap_lockPixels() failed!");
		return;
	}
	//__android_log_write(6, "android-io", "Copying new data into pixels.");
	updatePixels (pixels, d->data, x, y, width, height, d->width, d->height, 4);
	AndroidBitmap_unlockPixels(env, bitmap);
}
Exemplo n.º 11
0
void ofxDepthImageSequence::setFrame(int frame){
    if(!sequenceLoaded){
        ofLogError("ofxDepthImageSequence::selectFrame() -- sequence not loaded");
        return;
    }
    
    if(frame < 0 || frame >= images.size()){
        ofLogError("ofxDepthImageSequence::selectFrame() -- frame out of range");
        return;
    }
    
    currentFrame = frame;
	updatePixels();
}
Exemplo n.º 12
0
 void text_rsrc::setPointSize( float p )
 {
     scoped_lock< mutex > slock( text_mutex );
     
     if( p <= 0 )
         throw exception( "text_rsrc::setPointSize(): Point size <= 0" );
     
     point_size = p;
     
     // TODO: While setString() will almost always be called from the main
     // thread (element creation, changing due to events), there may be cases
     // where it is not.  Fix this if it becomes a problem.
     
     update_tex = true;
     updatePixels();
 }
Exemplo n.º 13
0
void ofxThreadedVideo::updateVideo(int videoID){

    if(videoID != VIDEO_NONE){

        // set loop type
        if(newLoopType[videoID] != -1){
            videos[videoID].setLoopState((ofLoopType)newLoopType[videoID]);
            newLoopType[videoID] = -1;
        }

        // set speed
        if(newSpeed[videoID] != videos[videoID].getSpeed()){
            videos[videoID].setSpeed(newSpeed[videoID]);
        }

        // do pause, or...
        if (bPaused[videoID] && !videos[videoID].isPaused()){
            videos[videoID].setPaused(true);
        }

        // ...do unpause
        if (!bPaused[videoID] && videos[videoID].isPaused()){
            videos[videoID].setPaused(false);
        }

        // do non blocking seek to position
        if(newPosition[videoID] != -1.0f){
            if(!bPaused[videoID]) videos[videoID].setPaused(true);
            videos[videoID].setPosition(newPosition[videoID]);
        }

        // do non blocking seek to frame
        if(newFrame[videoID] != -1){
            CLAMP(newFrame[videoID], 0, videos[videoID].getTotalNumFrames());
            videos[videoID].setFrame(newFrame[videoID]);
        }

        // update current video
        updatePixels(videoID);

        // unpause if doing a non blocking seek to position
        if(newPosition[videoID] != -1.0f && !bPaused[videoID]) videos[videoID].setPaused(false);

        newPosition[videoID] = -1.0f;
        newFrame[videoID] = -1;
    }
}
Exemplo n.º 14
0
void CommandInterpreter::interpret( String const & topic, String const & message )
{
    String valuePath, valueName;
    strOp::splitFromEnd( topic, valuePath, valueName, '/' );
    if( valuePath.equals( "Netz39/Service/Clock/Wallclock/Simple" ) )
    {
        if( valueName.equals( "Second" ) )
        {
            m_second = message.toInt();
        }
        else if( valueName.equals( "Minute" ) )
        {
            m_minute = message.toInt();
        }
        else if( valueName.equals( "Hour" ) )
        {
            m_hour = message.toInt();
        }
    }
    else if( valuePath.equals( "Netz39/Things/Logouhr/Background" ) )
    {
        messageToHSVColor( valueName, message, m_backgroundColorOuter );
        //m_backgroundColorOuter.v = static_cast<int>( min( max( m_backgroundColorOuter.v, 1 ), 4 ) ) * 255 / 4;
        m_backgroundColorInner = m_backgroundColorOuter;
    }
    else if( valuePath.equals( "Netz39/Things/Logouhr/HourHand" ) )
    {
        messageToHSVColor( valueName, message, m_hourColor );
    }
    else if( valuePath.equals( "Netz39/Things/Logouhr/MinuteHand" ) )
    {
        messageToHSVColor( valueName, message, m_minuteColor );
    }
    else if( valuePath.equals( "Netz39/Things/Logouhr/SecondHand" ) )
    {
        messageToHSVColor( valueName, message, m_secondColor );
    }
    else if( valuePath.equals( "Netz39/Things/Logouhr" ) )
    {
        if( valueName.equals( "Mode" ) )
        {
            setMode( message );
        }
    }

    updatePixels();
}
Exemplo n.º 15
0
    PImage& PImage::operator= (const PImage& p) {
        this->width = p.width;
        this->height = p.height;
        this->type = p.type;
        this->textureID = 0;
        this->texturebuffer = new GLubyte[width*height*4];
        //this->texturebuffer = p.texturebuffer;

        for(int i=0; i<width*height*4; i++) {
            this->texturebuffer[i] = p.texturebuffer[i];
        }
        glGenTextures(1, &textureID);
        glBindTexture(GL_TEXTURE_2D, textureID);
        updatePixels();
        this->pixels.setBuffer(texturebuffer);

        return (*this);
    }
Exemplo n.º 16
0
 void text_rsrc::setMaxDimensions( int w, int h, ellipsis_mode e )
 {
     scoped_lock< mutex > slock( text_mutex );
     
     if( w < 0 )
     {
         if( w < -1 )
             throw exception( "text_rsrc::setMaxWidth(): Width < -1" );
         
         max_dimensions[ 0 ] = -1;
         ellipsize = NONE;
     }
     else
     {
         max_dimensions[ 0 ] = w;
         ellipsize = e;
     }
     
     max_dimensions[ 1 ] = h;
     
     update_tex = true;
     updatePixels();
 }
Exemplo n.º 17
0
void renderScene(Shader& shader)
{
	static int shift = 0;
	static int index = 0;				// 用于从默认FBO读取到PBO
	int nextIndex = 0;                  // 用于从PBO更新像素 绘制到默认FBO
	shift = ++shift % 200;
	glReadBuffer(GL_FRONT); // 设置读取的FBO
	if (pboUsed)
	{
		index = (index + 1) % 2;
		nextIndex = (index + 1) % 2;
		// 开始FBO到PBO复制操作 pack操作
		t1.start();
		glBindBuffer(GL_PIXEL_PACK_BUFFER, PBOIds[index]);
		// OpenGL执行异步的DMA传输 这个命令会立即放回 此时CPU可以执行其他任务
		glReadPixels(0, 0, SINGLE_SCREEN_WIDTH, SINGLE_SCREEN_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, 0);

		// 计算读取数据所需时间
		t1.stop();
		readTime = t1.getElapsedTimeInMilliSec();


		// 开始修改nextIndex指向的PBO的数据
		t1.start();

		glBindBuffer(GL_PIXEL_PACK_BUFFER, PBOIds[nextIndex]);
		glBufferData(GL_PIXEL_PACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
		// 从PBO映射到用户内存空间 然后修改PBO中数据
		GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
		if (ptr)
		{
			// 更新映射后的内存数据
			updatePixels(ptr, SINGLE_SCREEN_WIDTH, SINGLE_SCREEN_HEIGHT, shift, colorBuffer);
			glUnmapBuffer(GL_PIXEL_PACK_BUFFER); // 释放映射的client memory
		}

		// 计算更新PBO数据所需时间
		t1.stop();
		processTime = t1.getElapsedTimeInMilliSec();
		// 注意 不要误写为glBindBuf(GL_PIXEL_UNPACK_BUFFER, 0);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
	}
	else
	{
		// 不使用PBO的方式 读取到client memory并修改
		t1.start();
		glReadPixels(0, 0, SINGLE_SCREEN_WIDTH, SINGLE_SCREEN_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, colorBuffer);
		t1.stop();
		readTime = t1.getElapsedTimeInMilliSec();

		// 修改内存数据
		t1.start();
		updatePixels(colorBuffer, SINGLE_SCREEN_WIDTH, SINGLE_SCREEN_HEIGHT, shift, colorBuffer);
		t1.stop();
		processTime = t1.getElapsedTimeInMilliSec();
	}
	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	drawLeftSidePixel(shader);
	drawRightSidePixel(shader);
}
Exemplo n.º 18
0
bool ofxDepthImageSequence::loadSequence(string newSequenceDirectory){
    

	ofDirectory sequenceList(newSequenceDirectory);
	if(!sequenceList.exists()){
		ofLogError("ofxDepthImageSequence -- sequence directory " + newSequenceDirectory + " does not exist!");
		return false;
	}
    
	if(sequenceLoaded){
		images.clear();
		sequenceLoaded = false;
	}


	sequenceList.allowExt("png");
	int numFiles = sequenceList.listDir();
	if(numFiles == 0){
		ofLogError("ofxTLDepthImageSequence -- sequence directory " + newSequenceDirectory + " is empty!");
		return false;
	}
	

	bool checkedForTimestamp = false;
	unsigned long firstFrameTimeOffset = 0;
	for(int i = 0; i < numFiles; i++){
        //backwards compat...
		if(sequenceList.getName(i).find("poster") != string::npos){
			ofLogWarning("discarding poster frame " + sequenceList.getPath(i) );
			continue;
		}
		
		if(!checkedForTimestamp){
			framesHaveTimestamps = sequenceList.getName(i).find("millis") != string::npos;
			checkedForTimestamp = true;
			ofLogVerbose("Frames have timestamps? " + string((framesHaveTimestamps ? "yes!" : "no :(")) );
		}
		
		
		images.push_back( DepthImage() );
		DepthImage& img = images[images.size()-1];
		img.path = sequenceList.getPath(i);
		
		if(framesHaveTimestamps){
			vector<string> split = ofSplitString(sequenceList.getName(i), "_", true, true);
			for(int l = 0; l < split.size(); l++){
				if(split[l] == "millis"){
					img.timestamp = ofToInt(split[l+1]);
					if(i == 0){
						firstFrameTimeOffset = img.timestamp;
					}
					img.timestamp -= firstFrameTimeOffset;
				}
			}
		}

		images.push_back( img );
	}
	
	//currentFrame = -1;
    if(framesHaveTimestamps){
	    durationInMillis = images[images.size()-1].timestamp;
    }

	ofLogVerbose("sequence is loaded " + ofToString( images.size() ));
    sequenceDirectory = newSequenceDirectory;
    sequenceLoaded = true;
	setFrame(0);
    updatePixels();
//	startThread();
	return true;
}
Exemplo n.º 19
0
void renderScene(Shader& shader)
{
	
	static int index = 0;				// 用于从PBO拷贝像素到纹理对象
	int nextIndex = 0;                  // 指向下一个PBO 用于更新PBO中像素
	glActiveTexture(GL_TEXTURE0);
	if (pboMode > 0)
	{
		if (pboMode == 1)
		{
			// 只有一个时 使用0号PBO
			index = nextIndex = 0;
		}
		else if (pboMode == 2)
		{
			index = (index + 1) % 2;
			nextIndex = (index + 1) % 2;
		}

		// 开始PBO到texture object的数据复制 unpack操作
		t1.start();

		// 绑定纹理 和PBO
		glBindTexture(GL_TEXTURE_2D, textureId);
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, PBOIds[index]);

		// 从PBO复制到texture object 使用偏移量 而不是指针
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, IMAGE_WIDTH,
			IMAGE_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, 0);

		// 计算复制数据所需时间
		t1.stop();
		copyTime = t1.getElapsedTimeInMilliSec();


		// 开始修改nextIndex指向的PBO的数据
		t1.start();

		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, PBOIds[nextIndex]);
		glBufferData(GL_PIXEL_UNPACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
		// 从PBO映射到用户内存空间 然后修改PBO中数据
		GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
		if (ptr)
		{
			// 更新映射后的内存数据
			updatePixels(ptr, DATA_SIZE);
			glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // 释放映射的用户内存空间
		}

		// 计算修改PBO数据所需时间
		t1.stop();
		updateTime = t1.getElapsedTimeInMilliSec();

		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
	}
	else
	{
		// 不使用PBO的方式 从用户内存复制到texture object
		t1.start();

		glBindTexture(GL_TEXTURE_2D, textureId);
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 
			IMAGE_WIDTH, IMAGE_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, (GLvoid*)imageData);

		t1.stop();
		copyTime = t1.getElapsedTimeInMilliSec();

		// 修改内存数据
		t1.start();
		updatePixels(imageData, DATA_SIZE);
		t1.stop();
		updateTime = t1.getElapsedTimeInMilliSec();
	}
	glUniform1i(glGetUniformLocation(shader.programId, "randomText"), 0);
	
	glBindVertexArray(quadVAOId);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glBindVertexArray(0);
}
Exemplo n.º 20
0
void sgTexture::unlockPixels()
{
	updatePixels();
	delete[] texdata;
	texdata = NULL;
}