Esempio n. 1
0
int main() {
    EGLContextType *context = NULL;
    // X display and window
    Display * x11Display = XOpenDisplay(NULL);
    CHECK_HANDLE_RET(x11Display, NULL, "XOpenDisplay", -1);
    Window x11RootWindow = DefaultRootWindow(x11Display);

    // may remove the attrib
    XSetWindowAttributes x11WindowAttrib;
    x11WindowAttrib.event_mask = ExposureMask | KeyPressMask;

    // create with video size, simplify it
    Window x11Window = XCreateWindow(x11Display, x11RootWindow,
        0, 0, 800, 600, 0, CopyFromParent, InputOutput,
        CopyFromParent, CWEventMask, &x11WindowAttrib);
    XMapWindow(x11Display, x11Window);
    XSync(x11Display, 0);

    context = eglInit(x11Display, x11Window, 0, 0);
    // GLuint textureId = createTestTexture();
    XID pixmap = createPixmap(x11Display, x11Window);
    GLuint textureId = createTextureFromPixmap(context, pixmap);
    drawTextures(context, &textureId, 1);

    EGLBoolean running = EGL_TRUE;
    while (running) {
        XEvent x_event;
        XNextEvent(x11Display, &x_event);
        switch (x_event.type) {
        case Expose:
            glClear(GL_COLOR_BUFFER_BIT
                | GL_DEPTH_BUFFER_BIT
            );
            drawTextures(context, &textureId, 1);
            break;
        case KeyPress:
            running = EGL_FALSE;
            break;
        default:
            break;
        }
    }

    XUnmapWindow(x11Display, x11Window);
    XDestroyWindow(x11Display, x11Window);
    XCloseDisplay(x11Display);
    INFO("exit successfully");
    return 0;
}
Esempio n. 2
0
bool displayOneVideoFrameEGL(int32_t fd, int32_t index)
{
    ASSERT(eglContext && textureIds.size());
    ASSERT(index>=0 && index<textureIds.size());
    DEBUG("textureIds[%d] = 0x%x", index, textureIds[index]);
    int ret = drawTextures(eglContext, &textureIds[index], 1);

    return ret == 0;
}
void ofxParticleEmitter::draw(int x /* = 0 */, int y /* = 0 */)
{
	if ( !active ) return;
	
	glPushMatrix();
	glTranslatef( x, y, 0.0f );
	
	drawTextures();
	//drawPoints();
	
	glPopMatrix();
}
Esempio n. 4
0
bool displayOneVideoFrameEGL(int32_t fd, int32_t index)
{
    ASSERT(eglContext && textureIds.size());
    ASSERT(index>=0 && index<textureIds.size());
    DEBUG("textureIds[%d] = 0x%x", index, textureIds[index]);

    GLenum target = GL_TEXTURE_2D;
    if (IS_DMA_BUF())
        target = GL_TEXTURE_EXTERNAL_OES;
    int ret = drawTextures(eglContext, target, &textureIds[index], 1);

    return ret == 0;
}
Esempio n. 5
0
void
iil4mitkImage::display (iil4mitkWidget* widget)
{
  GLdouble planeX [] = {-1, 0, 0, regionWidth ()};
  GLdouble planeY [] = {0, -1, 0, regionHeight ()};

  if (!visible () 
    || (constraint () && (widget != constraint ())))
  {
    return;
  }

  if (_pixels)
  {
    assert (_rx + _rw <= _width);
    assert (_ry + _rh <= _height);

    GLboolean texturing = glIsEnabled (GL_TEXTURE_2D);
    GLboolean blending = glIsEnabled (GL_BLEND);

    glClipPlane (GL_CLIP_PLANE4, planeX);
    glEnable (GL_CLIP_PLANE4);
    glClipPlane (GL_CLIP_PLANE5, planeY);
    glEnable (GL_CLIP_PLANE5);

    if ((_model == INTENSITY_ALPHA) || (_model == COLOR_ALPHA) || (_model == RGB) || (_model == RGBA))
    {
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    glEnable (GL_TEXTURE_2D);
    glMatrixMode (GL_MODELVIEW);
    glPushMatrix ();
    glColor4f (red (), green (), blue (), alpha ());
    glTranslatef (x (), y (), 0.0);
    drawTextures (widget);
    glPopMatrix ();

    glDisable (GL_CLIP_PLANE4);
    glDisable (GL_CLIP_PLANE5);

    if (texturing == GL_FALSE) glDisable (GL_TEXTURE_2D);
    if (blending  == GL_FALSE) glDisable (GL_BLEND);
  }
}
void ofxParticleEmitter::draw(int x /* = 0 */, int y /* = 0 */)
{
	if ( !active ) return;
	
	glPushMatrix();
	glTranslatef( x, y, 0.0f );
	
#ifdef TARGET_OF_IPHONE
	
	drawPointsOES();
	
#else
	
	drawTextures();
	//drawPoints();
	
#endif
	
	glPopMatrix();
}
Esempio n. 7
0
void LLViewBorder::draw()
{
	if( getVisible() )
	{
		if( STYLE_LINE == mStyle )
		{
			if( 0 == mBorderWidth )
			{
				// no visible border
			}
			else
			if( 1 == mBorderWidth )
			{
				drawOnePixelLines();
			}
			else
			if( 2 == mBorderWidth )
			{
				drawTwoPixelLines();
			}
			else
			{
				llassert( FALSE );  // not implemented
			}
		}
		else
		if( STYLE_TEXTURE == mStyle )
		{
			if( mTexture )
			{
				drawTextures();
			}
		}

		// draw the children
		LLView::draw();
	}	
}
Esempio n. 8
0
void Video::Display()
{
	glClear(GL_COLOR_BUFFER_BIT);

   // texture
   glEnable(GL_TEXTURE_2D);
   drawTextures();
   glDisable(GL_TEXTURE_2D);
   
   if(showMotionVectors)
   	drawMotionVectors();
      
   if(showDDMotionVectors)
   	drawDDMotionVectors();
   
   if(showSegGrid)
	   drawSegGrid();

	// draw text
	drawText();
   
   glFlush();
   glutSwapBuffers();
}
Esempio n. 9
0
void
SegmentationRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, float zNear, float zFar, bool mode2D) {
    std::lock_guard<std::mutex> lock(mMutex);
    OpenCLDevice::pointer device = std::dynamic_pointer_cast<OpenCLDevice>(getMainDevice());


    if(mColorsModified) {
        // Transfer colors to device (this doesn't have to happen every render call..)
        std::unique_ptr<float[]> colorData(new float[3*mLabelColors.size()]);
        std::unordered_map<int, Color>::iterator it;
        for(it = mLabelColors.begin(); it != mLabelColors.end(); it++) {
            colorData[it->first*3] = it->second.getRedValue();
            colorData[it->first*3+1] = it->second.getGreenValue();
            colorData[it->first*3+2] = it->second.getBlueValue();
        }

        mColorBuffer = cl::Buffer(
                device->getContext(),
                CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
                sizeof(float)*3*mLabelColors.size(),
                colorData.get()
        );
    }

    if(mFillAreaModified) {
        // Transfer colors to device (this doesn't have to happen every render call..)
        std::unique_ptr<char[]> fillAreaData(new char[mLabelColors.size()]);
        std::unordered_map<int, Color>::iterator it;
        for(it = mLabelColors.begin(); it != mLabelColors.end(); it++) {
            if(mLabelFillArea.count(it->first) == 0) {
                // Use default value
                fillAreaData[it->first] = mFillArea;
            } else {
                fillAreaData[it->first] = mLabelFillArea[it->first];
            }
        }

        mFillAreaBuffer = cl::Buffer(
                device->getContext(),
                CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
                sizeof(char)*mLabelColors.size(),
                fillAreaData.get()
        );
    }

    mKernel = cl::Kernel(getOpenCLProgram(device), "renderToTexture");
    mKernel.setArg(2, mColorBuffer);
    mKernel.setArg(3, mFillAreaBuffer);
    mKernel.setArg(4, mBorderRadius);
    mKernel.setArg(5, mOpacity);


    for(auto it : mDataToRender) {
        Image::pointer input = std::static_pointer_cast<Image>(it.second);
        uint inputNr = it.first;

        if(input->getDimensions() != 2)
            throw Exception("SegmentationRenderer only supports 2D images. Use ImageSlicer to extract a 2D slice from a 3D image.");

        if(input->getDataType() != TYPE_UINT8)
            throw Exception("SegmentationRenderer only support images with dat type uint8.");

        // Check if a texture has already been created for this image
        if(mTexturesToRender.count(inputNr) > 0 && mImageUsed[inputNr] == input)
            continue; // If it has already been created, skip it

        // If it has not been created, create the texture

        OpenCLImageAccess::pointer access = input->getOpenCLImageAccess(ACCESS_READ, device);
        cl::Image2D *clImage = access->get2DImage();

        // Run kernel to fill the texture
        cl::CommandQueue queue = device->getCommandQueue();

        if (mTexturesToRender.count(inputNr) > 0) {
            // Delete old texture
            glDeleteTextures(1, &mTexturesToRender[inputNr]);
            mTexturesToRender.erase(inputNr);
            glDeleteVertexArrays(1, &mVAO[inputNr]);
            mVAO.erase(inputNr);
        }

        cl::Image2D image;
        cl::ImageGL imageGL;
        std::vector<cl::Memory> v;
        GLuint textureID;
        // TODO The GL-CL interop here is causing glClear to not work on AMD systems and therefore disabled
        /*
        if(DeviceManager::isGLInteropEnabled()) {
            // Create OpenGL texture
            glGenTextures(1, &textureID);
            glBindTexture(GL_TEXTURE_2D, textureID);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, input->getWidth(), input->getHeight(), 0, GL_RGBA, GL_FLOAT, 0);

            // Create CL-GL image
            imageGL = cl::ImageGL(
                    device->getContext(),
                    CL_MEM_READ_WRITE,
                    GL_TEXTURE_2D,
                    0,
                    textureID
            );
            glBindTexture(GL_TEXTURE_2D, 0);
            glFinish();
            mKernel.setArg(1, imageGL);
            v.push_back(imageGL);
            queue.enqueueAcquireGLObjects(&v);
        } else {
         */
        image = cl::Image2D(
                device->getContext(),
                CL_MEM_READ_WRITE,
                cl::ImageFormat(CL_RGBA, CL_FLOAT),
                input->getWidth(), input->getHeight()
        );
        mKernel.setArg(1, image);
        //}


        mKernel.setArg(0, *clImage);
        queue.enqueueNDRangeKernel(
                mKernel,
                cl::NullRange,
                cl::NDRange(input->getWidth(), input->getHeight()),
                cl::NullRange
        );

        /*if(DeviceManager::isGLInteropEnabled()) {
            queue.enqueueReleaseGLObjects(&v);
        } else {*/
        // Copy data from CL image to CPU
        auto data = make_uninitialized_unique<float[]>(input->getWidth() * input->getHeight() * 4);
        queue.enqueueReadImage(
                image,
                CL_TRUE,
                createOrigoRegion(),
                createRegion(input->getWidth(), input->getHeight(), 1),
                0, 0,
                data.get()
        );
        // Copy data from CPU to GL texture
        glGenTextures(1, &textureID);
        glBindTexture(GL_TEXTURE_2D, textureID);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, input->getWidth(), input->getHeight(), 0, GL_RGBA, GL_FLOAT, data.get());
        glBindTexture(GL_TEXTURE_2D, 0);
        glFinish();
        //}

        mTexturesToRender[inputNr] = textureID;
        mImageUsed[inputNr] = input;
        queue.finish();
    }

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    drawTextures(perspectiveMatrix, viewingMatrix, mode2D);
    glDisable(GL_BLEND);
}