コード例 #1
0
void LLRenderTarget::flush(bool fetch_depth)
{
    gGL.flush();
    if (!mFBO)
    {
        gGL.getTexUnit(0)->bind(this);
        glCopyTexSubImage2D(LLTexUnit::getInternalType(mUsage), 0, 0, 0, 0, 0, mResX, mResY);

        if (fetch_depth)
        {
            if (!mDepth)
            {
                allocateDepth();
            }

            gGL.getTexUnit(0)->bind(this);
            glCopyTexImage2D(LLTexUnit::getInternalType(mUsage), 0, GL_DEPTH24_STENCIL8, 0, 0, mResX, mResY, 0);
        }

        gGL.getTexUnit(0)->disable();
    }
    else
    {
        stop_glerror();
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        stop_glerror();
    }
}
コード例 #2
0
 void GLES2TextureBuffer::copyFromFramebuffer(size_t zoffset)
 {
     glBindTexture(mTarget, mTextureID);
     GL_CHECK_ERROR;
     glCopyTexSubImage2D(mFaceTarget, mLevel, 0, 0, 0, 0, mWidth, mHeight);
     GL_CHECK_ERROR;
 }
コード例 #3
0
ファイル: Texture.cpp プロジェクト: mewbak/SFML
void Texture::update(const Window& window, unsigned int x, unsigned int y)
{
    assert(x + window.getSize().x <= m_size.x);
    assert(y + window.getSize().y <= m_size.y);

    if (m_texture && window.setActive(true))
    {
        TransientContextLock lock;

        // Make sure that the current texture binding will be preserved
        priv::TextureSaver save;

        // Copy pixels from the back-buffer to the texture
        glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
        glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.getSize().x, window.getSize().y));
        glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
        m_hasMipmap = false;
        m_pixelsFlipped = true;
        m_cacheId = getUniqueId();

        // Force an OpenGL flush, so that the texture will appear updated
        // in all contexts immediately (solves problems in multi-threaded apps)
        glCheck(glFlush());
    }
}
コード例 #4
0
void
GLTextureRenderer::end_draw()
{
  assert_gl();

  if (m_framebuffer)
  {
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
  }
  else
  {
    assert_gl();
    glBindTexture(GL_TEXTURE_2D, static_cast<GLTexture&>(*m_texture).get_handle());
    glCopyTexSubImage2D(GL_TEXTURE_2D,
                        0, // level
                        0, 0, // offset
                        0, 0, // x, y
                        m_texture->get_image_width(),
                        m_texture->get_image_height());
  }

  assert_gl();

  assert(m_rendering);
  m_rendering = false;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: terryfeverpitch/GLSL
void SHADOW_MAP_PASS()   // NON-FBO Version
{
	glClear(GL_DEPTH_BUFFER_BIT);  // no output to colorbuffer

	glViewport(0, 0, shadowMapSize, shadowMapSize);
	glMatrixMode(GL_PROJECTION); glPushMatrix();   glLoadIdentity();// save current projection
	MULT_LIGHT_PROJECTION();  // light projection

	glMatrixMode(GL_MODELVIEW);	glPushMatrix();  glLoadIdentity(); // viewer: save current modelview (containing Viewing of camera)
	MULT_LIGHT_MODELVIEW();   // light view

	// disable texturing in the first pass (if any)
	// disable lighting too

	glPushAttrib (GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT);
		//Disable color writes, and use flat shading for speed
		glColorMask(0, 0, 0, 0);  // color buffer bit
		glShadeModel(GL_FLAT);    // lighting bit
		glDisable (GL_LIGHTING);
		glDisable (GL_TEXTURE_2D);

		glPolygonOffset (8.0, 4.0); // IMPORTANT: to remove moire pattern (from z-fighting)
		glEnable (GL_POLYGON_OFFSET_FILL);
		
		glUseProgram(0);
		DrawScene(); // Draw the scene (fixed function)
	glPopAttrib();

	glMatrixMode(GL_PROJECTION); glPopMatrix();  // restore current projection
	glMatrixMode(GL_MODELVIEW); glPopMatrix();  // restore Modelview to Vcamera

	//Read the depth buffer into the shadow map texture
	glActiveTexture (GL_TEXTURE3);
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);
}
コード例 #6
0
ファイル: rendershadows.cpp プロジェクト: paud/d2x-xl
void CreateShadowTexture (void)
{
	GLint	i;

if (!bHaveShadowBuf) {
	memset (&shadowBuf, 0, sizeof (shadowBuf));
	shadowBuf.SetWidth (STB_SIZE_X);
	shadowBuf.SetHeight (STB_SIZE_Y);
	shadowBuf.SetFlags ((char) BM_FLAG_TGA);
	shadowBuf.SetBuffer (shadowTexBuf);
	shadowBuf.SetTranspType (-1);
	shadowBuf.PrepareTexture (0, 0, NULL);
	bHaveShadowBuf = 1;
	}
#if 1
//glStencilFunc (GL_EQUAL, 0, ~0);
//RenderShadowQuad (1);
#	if 0
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, CCanvas::Current ()->Height () - 128, 128, 128, 0);
#	else
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, 0,
						CCanvas::Current ()->Width (), 
						CCanvas::Current ()->Height (), 0);
#	endif
#else
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, 0, 128, 128);
#endif
i = glGetError ();
}
コード例 #7
0
ファイル: SpoutGLDXinterop.cpp プロジェクト: rossanag/Spout2
// COPY THE SHARED TEXTURE TO AN OUTPUT TEXTURE
bool spoutGLDXinterop::ReadTexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, GLuint HostFBO)
{

	if(m_hInteropDevice == NULL || m_hInteropObject == NULL) {
		return false;
	}

	if(width != (unsigned int)m_TextureInfo.width || height != (unsigned int)m_TextureInfo.height) {
		return false;
	}

	/*
	// Basic code for debugging
	if(wglDXLockObjectsNV(m_hInteropDevice, 1, &m_hInteropObject)) {
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_glTexture, 0);
		glBindTexture(TextureTarget, TextureID);
		glCopyTexSubImage2D(TextureTarget, 0, 0, 0, 0, 0, width, height);
		glBindTexture(TextureTarget, 0);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
		wglDXUnlockObjectsNV(m_hInteropDevice, 1, &m_hInteropObject);
		return true;
	}
	return false;
	*/

	// Wait for access to the texture
	if(spoutdx.CheckAccess(m_hAccessMutex, g_pSharedTexture)) {

		// lock dx object
		if(LockInteropObject(m_hInteropDevice, &m_hInteropObject) == S_OK) {

			// Bind our local fbo
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); 

			// Attach the shared texture to the color buffer in our frame buffer
			// needs GL_TEXTURE_2D as a target for our shared texture
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_glTexture, 0);
			if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT) {
				// bind output texture (destination)
				glBindTexture(TextureTarget, TextureID);
				// copy from framebuffer (fbo) to the bound texture
				glCopyTexSubImage2D(TextureTarget, 0, 0, 0, 0, 0, width, height);
				// unbind the texture
				glBindTexture(TextureTarget, 0);
			}

			// restore the previous fbo - default is 0
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, HostFBO);

			// unlock dx object
			UnlockInteropObject(m_hInteropDevice, &m_hInteropObject);
		}
	}
	spoutdx.AllowAccess(m_hAccessMutex, g_pSharedTexture); // Allow access to the texture

	return true;

} // end ReadTexture
コード例 #8
0
	void GL1FrameBufferProvider::sync_texture()
	{
		if (pbuffer_changed && (!pbuffer.is_null()) && !selected_surface.is_null())
		{
			set_active();

			Size surface_size = selected_texture_provider->get_surface_size();

			GLint old_viewport[4], old_matrix_mode;
			GLfloat old_matrix_projection[16], old_matrix_modelview[16];
			glGetIntegerv(GL_VIEWPORT, old_viewport);
			glGetIntegerv(GL_MATRIX_MODE, &old_matrix_mode);
			glGetFloatv(GL_PROJECTION_MATRIX, old_matrix_projection);
			glGetFloatv(GL_MODELVIEW_MATRIX, old_matrix_modelview);
			GLboolean blending = glIsEnabled(GL_BLEND);
			glDisable(GL_BLEND);

			glViewport(0, 0, surface_size.width, surface_size.height);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glMultMatrixf(Mat4f::ortho_2d(0.0f, (float)surface_size.width, 0.0f, (float)surface_size.height, handed_right, clip_negative_positive_w));
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			if (glActiveTexture != nullptr)
				glActiveTexture(GL_TEXTURE0);

#ifndef __ANDROID__
			glPixelZoom(1.0f, 1.0f);
#endif

			// Copy pbuffer to texture:
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, selected_texture_provider->get_handle());
			glCopyTexSubImage2D(
				GL_TEXTURE_2D,
				0,
				0, 0,
				0, 0,
				surface_size.width, surface_size.height);

			glDisable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, 0);

			if (blending)
				glEnable(GL_BLEND);
			glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
			glMatrixMode(GL_PROJECTION);
			glLoadMatrixf(old_matrix_projection);
			glMatrixMode(GL_MODELVIEW);
			glLoadMatrixf(old_matrix_modelview);
			glMatrixMode(old_matrix_mode);

#ifdef __APPLE__
			glFlush();
#endif
		}
		pbuffer_changed = false;
	}
コード例 #9
0
ファイル: Texture.cpp プロジェクト: naohisas/KVS
void Texture::copySubImage2D( GLint x, GLint y, GLsizei width, GLsizei height, GLint xoffset, GLint yoffset )
{
    KVS_ASSERT( m_target == GL_TEXTURE_2D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    KVS_GL_CALL( glCopyTexSubImage2D( m_target, level, xoffset, yoffset, x, y, width, height ) );
}
コード例 #10
0
ファイル: gearbox.c プロジェクト: astrofimov/vgallium
static void
draw(void)
{
   float ar;

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0, 0.0, -40.0);

   glDisable(GL_SCISSOR_TEST);
   glClear(GL_DEPTH_BUFFER_BIT);
   glEnable(GL_SCISSOR_TEST);

   /* draw gears */
   glViewport(0, 0, TexWidth, TexHeight);
   glScissor(0, 0, TexWidth, TexHeight);
   glClearColor(0.5, 0.5, 0.8, 0.0);
   glClearColor(1, 1, 1, 0);
   glClear(GL_COLOR_BUFFER_BIT);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 60.0);
   glMatrixMode(GL_MODELVIEW);

   DrawGears();

   glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TexWidth, TexHeight);
   
   /* draw textured cube */
   glViewport(TexWidth, 0, WinWidth - TexWidth, WinHeight);
   glScissor(TexWidth, 0, WinWidth - TexWidth, WinHeight);
   glClearColor(0.5, 0.5, 0.8, 0.0);
   glClear(GL_COLOR_BUFFER_BIT);

   ar = (float) (WinWidth - TexWidth) / WinHeight;
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustum(-ar, ar, -1.0, 1.0, 5.0, 60.0);
   glMatrixMode(GL_MODELVIEW);

   DrawCube();

   /* finish up */
   glutSwapBuffers();

   Frames++;
   {
      GLint t = glutGet(GLUT_ELAPSED_TIME);
      if (t - T0 >= 5000) {
         GLfloat seconds = (t - T0) / 1000.0;
         GLfloat fps = Frames / seconds;
         printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps);
         T0 = t;
         Frames = 0;
      }
   }
}
コード例 #11
0
void GOpenGLBoard::GrabFrameBuffer(const GAABox2& LogicBox, GLGrabbedRect& Shot) {

	GLDisableShaders();

	GReal left, right, bottom, top;
	Projection(left, right, bottom, top);

	if (LogicBox.Min()[G_X] > left)
		left = LogicBox.Min()[G_X];
	if (LogicBox.Max()[G_X] < right)
		right = LogicBox.Max()[G_X];
	if (LogicBox.Min()[G_Y] > bottom)
		bottom = LogicBox.Min()[G_Y];
	if (LogicBox.Max()[G_Y] < top)
		top = LogicBox.Max()[G_Y];

	GAABox2 tmpBox(GPoint2(left, bottom), GPoint2(right, top));

	GPoint<GInt32, 2> p0 = LogicalToPhysicalInt(tmpBox.Min());
	GPoint<GInt32, 2> p1 = LogicalToPhysicalInt(tmpBox.Max());
	p0[G_X] -= 1;
	p0[G_Y] -= 1;
	p1[G_X] += 1;
	p1[G_Y] += 1;
	GGenericAABox<GInt32, 2> intBox(p0, p1);

	GUInt32 width = (GUInt32)GMath::Abs(p1[G_X] - p0[G_X]);
	GUInt32 height = (GUInt32)GMath::Abs(p1[G_Y] - p0[G_Y]);

	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	UpdateGrabBuffer(width, height, Shot);

	G_ASSERT(Shot.TexName > 0);
	G_ASSERT(Shot.TexWidth > 0 && Shot.TexHeight > 0);
	G_ASSERT(Shot.TexWidth >= width && Shot.TexHeight >= height);

	SELECT_AND_DISABLE_TUNIT(1)
	SELECT_AND_DISABLE_TUNIT(0)
	glEnable(Shot.Target);
	glBindTexture(Shot.Target, Shot.TexName);
	glCopyTexSubImage2D(Shot.Target, 0, 0, 0, (GLint)intBox.Min()[G_X], (GLint)intBox.Min()[G_Y], (GLsizei)width, (GLsizei)height);

	Shot.Width = width;
	Shot.Height = height;
	Shot.IsEmpty = G_FALSE;

	Shot.gNotExpandedLogicBox = tmpBox;

	GPoint2 q0 = PhysicalToLogical(p0);
	GPoint2 q1 = PhysicalToLogical(p1);
	Shot.gExpandedLogicBox.SetMinMax(q0, q1);

	SELECT_AND_DISABLE_TUNIT(0)
	glPixelStorei(GL_PACK_ALIGNMENT, 4);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
}
コード例 #12
0
void LLRenderTarget::copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1,
						S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter)
{
	GLboolean write_depth = mask & GL_DEPTH_BUFFER_BIT ? TRUE : FALSE;

	LLGLDepthTest depth(write_depth, write_depth);

	gGL.flush();
	if (!source.mFBO || !mFBO)
	{
		llwarns << "Cannot copy framebuffer contents for non FBO render targets." << llendl;
		return;
	}

	if (mSampleBuffer)
	{
		mSampleBuffer->copyContents(source, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
	}
	else
	{
		if (mask == GL_DEPTH_BUFFER_BIT && !mStencil && source.mStencil != mStencil)
		{
			stop_glerror();
		
			glBindFramebuffer(GL_FRAMEBUFFER, source.mFBO);
			check_framebuffer_status();
			gGL.getTexUnit(0)->bind(this, true);
			stop_glerror();
			glCopyTexSubImage2D(LLTexUnit::getInternalType(mUsage), 0, srcX0, srcY0, dstX0, dstY0, dstX1, dstY1);
			stop_glerror();
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
			stop_glerror();
		}
		else
		{
			glBindFramebuffer(GL_READ_FRAMEBUFFER, source.mFBO);
			stop_glerror();
			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFBO);
			stop_glerror();
			check_framebuffer_status();
			stop_glerror();
			if(gGLManager.mIsATI && mask & GL_STENCIL_BUFFER_BIT)
			{
				mask &= ~GL_STENCIL_BUFFER_BIT;
				glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, GL_STENCIL_BUFFER_BIT, filter);
			}
			if(mask)
				glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
			stop_glerror();
			glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
			stop_glerror();
			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
			stop_glerror();
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
			stop_glerror();
		}
	}
}
コード例 #13
0
ファイル: FBO.cpp プロジェクト: A600/xbmc
/** Unlocks the pbuffer */
void RenderTarget::unlock() {

#ifdef USE_FBO
  if(this->useFBO)
    {
      glBindTexture( GL_TEXTURE_2D, this->textureID[1] );
      glCopyTexSubImage2D( GL_TEXTURE_2D,
                         0, 0, 0, 0, 0, 
                         this->texsize, this->texsize );
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
      return;
    }
#endif
    /** Fallback texture path */
    glBindTexture( GL_TEXTURE_2D, this->textureID[0] );
    
	glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, this->texsize, this->texsize );
  }
コード例 #14
0
ファイル: reflection.cpp プロジェクト: jmigual/graphics
bool Reflection::paintGL()
{
    // Pass 1. Draw scene reversed and store it to the texture
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    m_pProgram->bind();
    m_pProgram->setUniformValue("factor", (float)-1.0);
    m_pProgram->setUniformValue("texture", false);
    m_pProgram->setUniformValue("colorMap", 0);
    m_pProgram->setUniformValue("SIZE", QVector2D(glwidget()->width(), glwidget()->height()));
    
    Box b = scene()->boundingBox();
    m_pProgram->setUniformValue("radius", b.radius());
    m_pProgram->setUniformValue("boundingMin", b.min());
    m_pProgram->setUniformValue("boundingMax", b.max());
    
    m_pProgram->setUniformValue("modelViewProjectionMatrix",
                                camera()->projectionMatrix() *
                                camera()->modelviewMatrix());
    m_pProgram->setUniformValue("modelViewMatrix", camera()->modelviewMatrix());
    m_pProgram->setUniformValue("normalMatrix", camera()->modelviewMatrix().normalMatrix());

    // Ligth specs
    m_pProgram->setUniformValue("lightAmbient", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("lightDiffuse", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("lightSpecular", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("lightPosition", QVector4D(100., 100., 100., 1.));

    m_pProgram->setUniformValue("matAmbient", QVector4D(.5, .4, .0, 1.));
    m_pProgram->setUniformValue("matDiffuse", QVector4D(.5, .4, .0, 1.));
    m_pProgram->setUniformValue("matSpecular", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("matShininess", (float) 30.);

    drawPlugin()->drawScene();

    // Get texture
    glBindTexture(GL_TEXTURE_2D, m_textureId);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, glwidget()->width(), glwidget()->height());
    glGenerateMipmap(GL_TEXTURE_2D);

    // Pass 2 Draw Scene normal
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    m_pProgram->setUniformValue("factor", (float)1.0);

    
    drawPlugin()->drawScene();

    // Pass 3 Draw quad using texture
    m_pProgram->setUniformValue("texture", true);
    glBindVertexArray(m_VAO_rect);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glBindVertexArray(0);

    m_pProgram->release();
    glBindTexture(GL_TEXTURE_2D, 0);

    return true;
}
コード例 #15
0
void RenderTextureImplDefault::updateTexture(unsigned int textureId)
{
    // Make sure that the current texture binding will be preserved
    priv::TextureSaver save;

    // Copy the rendered pixels to the texture
    glCheck(glBindTexture(GL_TEXTURE_2D, textureId));
    glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height));
}
コード例 #16
0
ファイル: Texture.cpp プロジェクト: mutexre/Base
void GL::Texture::copySubImage2D(TextureTarget target, GLint level,
                                 GLint xOffset, GLint yOffset,
                                 GLint x, GLint y,
                                 GLsizei width, GLsizei height)
{
    glCopyTexSubImage2D(GLenum(target), level,
                        xOffset, yOffset,
                        x, y,
                        width, height);
}
コード例 #17
0
ファイル: Render.cpp プロジェクト: imclab/demoscene
void CRender::copyToTexture(unsigned int offsetx, unsigned int offsety, unsigned int x, unsigned int y, unsigned int width, unsigned int height) {
	glCopyTexSubImage2D(GL_TEXTURE_2D,// target
						0, //level mipmaps
						offsetx, //xoffset
						offsety, // yoffset
						x, // x
						y, //y
						width, // width
						height); //height 
}
コード例 #18
0
    // Read framebuffer to 'pixelsOut' via glCopyTexSubImage2D and GL_TEXTURE_2D.
    void TestCopyTexSubImage2D(int x, int y, int, PixelRect *pixelsOut)
    {
        // Init texture with given pixels.
        GLTexture destTexture;
        pixelsOut->toTexture2D(GL_TEXTURE_2D, destTexture.get());

        // Read framebuffer -> texture -> 'pixelsOut'
        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, x, y, kReadWidth, kReadHeight);
        readTexture2D(GL_TEXTURE_2D, destTexture.get(), kReadWidth, kReadHeight, pixelsOut);
    }
コード例 #19
0
void LLPostProcess::copyFrameBuffer()
{
	mRenderTarget[!!mRenderTarget[0].getFBO()].bindTexture(0,0);
	glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,0,0,mScreenWidth, mScreenHeight);

	if(mDepthTexture)
	{
		for(std::list<LLPointer<LLPostProcessShader> >::iterator it=mShaders.begin();it!=mShaders.end();++it)
		{
			if((*it)->isEnabled() && (*it)->getDepthChannel()>=0)
			{
				gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_RECT_TEXTURE, mDepthTexture);
				glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,0,0,mScreenWidth, mScreenHeight);
				break;
			}
		}
	}

}
コード例 #20
0
void Texture::copyCurrentBuffer(int newTarget)
{
  if(!id)
    return;

  newTarget = (newTarget == -1) ? target : newTarget;
  activate();
  glCopyTexSubImage2D(newTarget, 0, 0, 0, 0, 0, width, height);
  deactivate();
}
コード例 #21
0
		void PSGLRenderManager::EndRenderToTexture(Image* texture)
		{
			// copy the frame buffer pixels to a texture
			glBindTexture(GL_TEXTURE_2D, texture->_id);
			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,texture->_width, texture->_height);
			glBindTexture(GL_TEXTURE_2D, 0);

			// GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
			//glPopAttrib();
		}
コード例 #22
0
void TransferQueue::blitTileFromQueue(GLuint fboID, BaseTileTexture* destTex,
                                      GLuint srcTexId, GLenum srcTexTarget,
                                      int index)
{
#if GPU_UPLOAD_WITHOUT_DRAW
    glBindFramebuffer(GL_FRAMEBUFFER, fboID);
    glFramebufferTexture2D(GL_FRAMEBUFFER,
                           GL_COLOR_ATTACHMENT0,
                           GL_TEXTURE_2D,
                           srcTexId,
                           0);
    glBindTexture(GL_TEXTURE_2D, destTex->m_ownTextureId);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
                        destTex->getSize().width(),
                        destTex->getSize().height());
#else
    // Then set up the FBO and copy the SurfTex content in.
    glBindFramebuffer(GL_FRAMEBUFFER, fboID);
    glFramebufferTexture2D(GL_FRAMEBUFFER,
                           GL_COLOR_ATTACHMENT0,
                           GL_TEXTURE_2D,
                           destTex->m_ownTextureId,
                           0);
    setGLStateForCopy(destTex->getSize().width(),
                      destTex->getSize().height());
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) {
        XLOG("Error: glCheckFramebufferStatus failed");
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        return;
    }

    // Use empty rect to set up the special matrix to draw.
    SkRect rect  = SkRect::MakeEmpty();
    TilesManager::instance()->shader()->drawQuad(rect, srcTexId, 1.0,
                       srcTexTarget, GL_NEAREST);

    // To workaround a sync issue on some platforms, we should insert the sync
    // here while in the current FBO.
    // This will essentially kick off the GPU command buffer, and the Tex Gen
    // thread will then have to wait for this buffer to finish before writing
    // into the same memory.
    EGLDisplay dpy = eglGetCurrentDisplay();
    if (m_currentDisplay != dpy)
        m_currentDisplay = dpy;
    if (m_currentDisplay != EGL_NO_DISPLAY) {
        if (m_transferQueue[index].m_syncKHR != EGL_NO_SYNC_KHR)
            eglDestroySyncKHR(m_currentDisplay, m_transferQueue[index].m_syncKHR);
        m_transferQueue[index].m_syncKHR = eglCreateSyncKHR(m_currentDisplay,
                                                            EGL_SYNC_FENCE_KHR,
                                                            0);
    }
    GLUtils::checkEglError("CreateSyncKHR");
#endif
}
コード例 #23
0
ファイル: GLBufferAdapter.cpp プロジェクト: artcom/y60
    void
    BufferToTexture::performAction(GLSourceBuffer theSourceBuffer)
    {
        if (theSourceBuffer == FRAME_BUFFER) {
            glReadBuffer(GL_BACK);
        }

        unsigned myWidth = getWidth();
        unsigned myHeight = getHeight();
        GLuint myTextureID = _myTexture->getTextureId();
        AC_DEBUG << "BufferToTexture::performAction '" << _myTexture->get<NameTag>() << "' id=" << _myTexture->get<IdTag>() << " offset=" << _myOffset << " " << myWidth << "x" << myHeight << " texId=" << myTextureID;
        if (_myCopyToImage) {

            ImagePtr myImage = _myTexture->getImage();
            if (!myImage) {
                AC_WARNING << "Texture '" << _myTexture->get<NameTag>() << "' id=" << _myTexture->get<IdTag>() << " has no image associated";
            } else {
                AC_DEBUG << "BufferToTexture::performAction copy to image '" << myImage->get<NameTag>() << "' id=" << myImage->get<IdTag>();

                // copy framebuffer to Image raster
                PixelEncodingInfo myPixelEncodingInfo = getDefaultGLTextureParams(myImage->getRasterEncoding());
                myPixelEncodingInfo.internalformat = asGLTextureInternalFormat(_myTexture->getInternalEncoding());

                glReadPixels(_myOffset[0],_myOffset[1], myWidth,myHeight,
                        myPixelEncodingInfo.externalformat, myPixelEncodingInfo.pixeltype,
                        myImage->getRasterPtr()->pixels().begin());
                CHECK_OGL_ERROR;

                //_myTexture->preload();
            }
        } else if (myTextureID > 0) {
            GLenum myTextureTarget = asGLTextureTarget(_myTexture->getType());
            if (myTextureTarget == GL_TEXTURE_2D) {
                AC_DEBUG << "BufferToTexture::performAction copy to texture";

                // copy framebuffer to texture
                glBindTexture(GL_TEXTURE_2D, myTextureID);
                glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, _myOffset[0],_myOffset[1], myWidth,myHeight);
                CHECK_OGL_ERROR;

                // generate mipmap levels
                if (hasCap("GL_GENERATE_MIPMAP") && _myTexture->get<TextureMipmapTag>()) {
                    AC_TRACE << "BufferToTexture::performAction: generating mipmap levels";
                    glGenerateMipmapEXT(GL_TEXTURE_2D);
                    CHECK_OGL_ERROR;
                }

                glBindTexture(GL_TEXTURE_2D, 0);
            } else {
                AC_WARNING << "Copy to texture only supported for 'texture_2d'";
            }
        } else {
            AC_DEBUG << "BufferToTexture::performAction texture '" << _myTexture->get<NameTag>() << "' is not valid";
        }
    }
コード例 #24
0
ファイル: copytexsubimage.c プロジェクト: blaztinn/piglit
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	float red[4] = {1.0, 0.0, 0.0, 0.0};
	float green[4] = {0.0, 1.0, 0.0, 0.0};
	GLuint q, texture;

	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Draw bottom half of window to green. */
	glColor4fv(green);
	piglit_draw_rect(-1, -1, 2, 1);
	glColor4f(1, 1, 1, 1);

	/* Set up a red texture. */
	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
			GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

	fill_tex(0, piglit_width*2, piglit_height / 2, red);

	glGenQueries(1, &q);

	/* Generate query fail. */
	glBeginQuery(GL_SAMPLES_PASSED, q);
	glEndQuery(GL_SAMPLES_PASSED);

	/* This should not be affected by conditional rendering. */
	glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV);
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, piglit_width, 0, 0, 0, piglit_width, piglit_height / 2);
	glEndConditionalRenderNV();

	/* Draw the right half of the texture. */
	glEnable(GL_TEXTURE_2D);
	piglit_draw_rect_tex(-1, 0, 2, 1,
			     0.5, 0, 1, 1);
	glDisable(GL_TEXTURE_2D);

	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
				      green);

	glutSwapBuffers();

	glDeleteQueries(1, &q);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
コード例 #25
0
ファイル: tex2vgimage.c プロジェクト: eviom/mesademos
static void draw(EGLmanager *eglman)
{
    VGfloat black[]   = {0.f, 0.f, 0.f, 1.f};

    // Render 3D scene by GL
    eglBindAPI(EGL_OPENGL_ES_API);
    eglMakeCurrent(eglman->dpy, eglman->pbuf_surface, eglman->pbuf_surface, eglman->es_ctx);

    // Modify GL texture source
    glClearColor(1.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);
    glClearColor(0.0, 1.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);
    glClearColor(0.0, 0.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);

    // Make current to VG content
    eglBindAPI(EGL_OPENVG_API);
    eglMakeCurrent(eglman->dpy, eglman->win_surface, eglman->win_surface, eglman->vg_ctx);

    // Draw VGImage target
    vgSetfv(VG_CLEAR_COLOR, 4, black);
    vgClear(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
    vgLoadIdentity();
    vgTranslate(WINDOW_WIDTH/2.0f, WINDOW_HEIGHT/2.0f);
    vgScale((VGfloat)WINDOW_WIDTH/(VGfloat)TEXTURE_WIDTH * 0.8f, (VGfloat)WINDOW_HEIGHT/(VGfloat)TEXTURE_HEIGHT * 0.8f);
    vgTranslate(-TEXTURE_WIDTH/2.0f, -TEXTURE_HEIGHT/2.0f);
    vgDrawImage(eglman->vg_image);

    // Swap buffer
    eglSwapBuffers(eglman->dpy, eglman->win_surface);

    return;
}
コード例 #26
0
void RenderImageImplDefault::UpdateTexture(unsigned int textureId)
{
    GLint previous;
    GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous));

    // Copy the rendered pixels to the image
    GLCheck(glBindTexture(GL_TEXTURE_2D, textureId));
    GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));

    GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
}
コード例 #27
0
ファイル: gl_bloom.c プロジェクト: AAS/ezquake-source
// =================
// R_Bloom_DownsampleView
// =================
void R_Bloom_DownsampleView( void )
{
	glDisable( GL_BLEND );
	glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

	// Stepped downsample.
	if( r_screendownsamplingtexture_size )
	{
		int     midsample_width = r_screendownsamplingtexture_size * sampleText_tcw;
		int     midsample_height = r_screendownsamplingtexture_size * sampleText_tch;

		// Copy the screen and draw resized.
		GL_Bind(r_bloomscreentexture);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, glheight - (curView_y + curView_height), curView_width, curView_height);
		R_Bloom_Quad( 0,  glheight - midsample_height, midsample_width, midsample_height, screenText_tcw, screenText_tch  );

		// Now copy into Downsampling (mid-sized) texture.
		GL_Bind(r_bloomdownsamplingtexture);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, midsample_width, midsample_height);

		// Now draw again in bloom size.
		glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
		R_Bloom_Quad( 0,  glheight - sample_height, sample_width, sample_height, sampleText_tcw, sampleText_tch );

		// Now blend the big screen texture into the bloom generation space (hoping it adds some blur).
		glEnable( GL_BLEND );
		glBlendFunc(GL_ONE, GL_ONE);
		glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
		GL_Bind(r_bloomscreentexture);
		R_Bloom_Quad( 0,  glheight - sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
		glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
		glDisable( GL_BLEND );
	} 
	else
	{    
		// Downsample simple.
		GL_Bind(r_bloomscreentexture);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, glheight - (curView_y + curView_height), curView_width, curView_height);
		R_Bloom_Quad( 0, glheight - sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
	}
}
コード例 #28
0
// Capture input i into o.
// i is presumed to be the current screen buffer
// zoom is 0.0 ...
void capture(TEXTURE * o, TEXTURE * i, float zx, float zy) {
    glBindTexture(GL_TEXTURE_2D,o->bind);
    glCopyTexSubImage2D(GL_TEXTURE_2D,0,
			i->w*0.5*(1.0-zx),
			i->h*0.5*(1.0-zy),
			i->w*0.5*(1.0-zx),
			i->h*0.5*(1.0-zy),
			zx*i->w,zy*i->h
		       );


}
コード例 #29
0
	void OGL2DTexture::copyFromFramebuffer(const ion_uint32 x,const ion_uint32 y)
	{
		glbind();

		if (!m_pDataSubmitted[currentLevel()]) {
			glCopyTexImage2D(GL_TEXTURE_2D,(GLint)currentLevel(),m_Internalformat,x,y,
				m_LevelWidth,m_LevelHeight,0);
			m_pDataSubmitted[currentLevel()]=true;
		} else {
			glCopyTexSubImage2D(GL_TEXTURE_2D,(GLint)currentLevel(),0,0,x,y,m_LevelWidth,m_LevelHeight);
		}
	}
コード例 #30
0
void GLXPBuffer::deselect(void)
{
	if (!(m_pOldDisplay && m_glxOldDrawable && m_glxOldContext))
		return;
	glBindTexture(GL_TEXTURE_2D, shadowTex);
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, shadowMapSize-2, shadowMapSize-2);
	if (!glXMakeCurrent(m_pOldDisplay, m_glxOldDrawable, m_glxOldContext))
		return;
	m_pOldDisplay = 0;
	m_glxOldDrawable = 0;
	m_glxOldContext = 0;
}