Ejemplo n.º 1
0
        Texture* Texture::createEmpty(
                std::pair<size_t, size_t> dimensions,
                Texture::Format format, 
                Texture::Filter filter, Texture::Wrap wrap) {
            Texture* self = new Texture();

            ScopedBind bind(*self);

            setTextureParameters(filter, wrap);

            int width = dimensions.first;
            int height = dimensions.second;

            GLuint internalformat;

            if(!getInternalFormat(format, internalformat)) {
                Log.warn() << "unknown format parameter (" << format << "), using RGBA8";
                internalformat = GL_RGBA8;
            }

            glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0,
                GL_RGBA, GL_UNSIGNED_BYTE, 0);  

            return self;
        }
Ejemplo n.º 2
0
UInt32 RenderBuffer::handleGL(DrawEnv                 *pEnv, 
                              UInt32                   osgid, 
                              Window::GLObjectStatusE  mode,
                              UInt32                        )
{
    Window *pWindow = pEnv->getWindow();
    
    if(mode == Window::initialize || mode == Window::reinitialize ||
       mode == Window::needrefresh )
    {
        GLuint uiBufferId = 0;

        if(mode == Window::initialize)
        {
            OSGGETGLFUNCBYID_GL3_ES( glGenRenderbuffers,
                                     osgGlGenRenderbuffers,
                                    _uiFuncGenRenderbuffers,
                                     pWindow);

            osgGlGenRenderbuffers(1, &uiBufferId);

            pWindow->setGLObjectId(osgid, uiBufferId);
        }
        else
        {
            uiBufferId = pWindow->getGLObjectId(osgid);
        }

        OSGGETGLFUNCBYID_GL3_ES( glBindRenderbuffer,
                                 osgGlBindRenderbuffer,
                                _uiFuncBindRenderbuffer, 
                                 pWindow);

        OSGGETGLFUNCBYID_GL3_ES( glRenderbufferStorage,
                                 osgGlRenderbufferStorage,
                                _uiFuncRenderbufferStorage,
                                 pWindow);

        osgGlBindRenderbuffer(GL_RENDERBUFFER_EXT, uiBufferId);

        GLenum internalFormat = getInternalFormat();

        if(internalFormat == GL_NONE && getImage() != NULL)
        {
            internalFormat = getImage()->getPixelFormat();
        }

        osgGlRenderbufferStorage(GL_RENDERBUFFER_EXT,
                                 internalFormat,
                                 getWidth(), 
                                 getHeight());
    }

    return 0;
}
Ejemplo n.º 3
0
GLuint Renderbuffer::getStencilSize() const
{
    if (gl::GetStencilBits(getInternalFormat(), mRenderer->getCurrentClientVersion()) > 0)
    {
        return gl::GetStencilBits(getActualFormat(), mRenderer->getCurrentClientVersion());
    }
    else
    {
        return 0;
    }
}
Ejemplo n.º 4
0
	fm::Result CubeTexture::create(fm::Size size)
	{
		// check for empty texture
		if (!size)
			return fm::Result("CubeTextureError",fm::Result::OPFailed,"CreatingEmptyTexture","CubeTexture.create",__FILE__,__LINE__);

		// opengl wouldn't accpet too big textures
		fm::Size maxSize = getMaximumSize();
		if (size > maxSize)
			return fm::Result("CubeTextureError",fm::Result::OPFailed,"CreatingTooBigTexture","CubeTexture.create",__FILE__,__LINE__,fm::toString(size).str());

		fm::Result err;

		// setup internal data
		m_size = size;

		if (glIsTexture(getGlId()) == GL_FALSE)
		{
			GLuint glId;
			err += glCheck(glGenTextures(1,&glId));
			getGlId() = glId;
		}

		// bind the texture for uplading
		GLint boundTex;
		glCheck(glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &boundTex));
		{
			err += glCheck(glBindTexture(GL_TEXTURE_CUBE_MAP,getGlId()));

			// set TEXTURE_WRAP
			glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE);

			if (glGetError() != GL_NO_ERROR)
			{
				m_isRepeated = !m_isRepeated;
				err += glCheck(glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
				err += glCheck(glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
				err += glCheck(glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
			}

			// set TEXTURE_FILTER
			err += glCheck(glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,m_isSmooth ? GL_LINEAR : GL_NEAREST));
			err += glCheck(glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,m_isSmooth ? GL_LINEAR : GL_NEAREST));

			// upload data
			C(6)
				err += glCheck(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,getInternalFormat(),m_size,m_size,0,getFormat(),getType(),nullptr));
		}
		err += glCheck(glBindTexture(GL_TEXTURE_CUBE_MAP,boundTex));

		return err;
	}
Ejemplo n.º 5
0
void GLTexture2D::setFloat4Data( const float* afData, int xOffset, int yOffset, int width, int height )
{
	bind();
	if( width == 0 )
	{
		width = m_iWidth;
	}
	if( height == 0 )
	{
		height = m_iHeight;
	}

	glTexImage2D( GL_TEXTURE_2D, 0, getInternalFormat(), width, height, 0, GL_RGBA, GL_FLOAT, afData );
}
bool WebGLFramebuffer::isIncomplete(bool checkInternalFormat) const
{
    unsigned int count = 0;
    if (isDepthAttached()) {
        if (checkInternalFormat && getInternalFormat(m_depthAttachment.get()) != GraphicsContext3D::DEPTH_COMPONENT16)
            return true;
        count++;
    }
    if (isStencilAttached()) {
        if (checkInternalFormat && getInternalFormat(m_stencilAttachment.get()) != GraphicsContext3D::STENCIL_INDEX8)
            return true;
        count++;
    }
    if (isDepthStencilAttached()) {
        if (checkInternalFormat && getInternalFormat(m_depthStencilAttachment.get()) != GraphicsContext3D::DEPTH_STENCIL)
            return true;
        if (!isValid(m_depthStencilAttachment.get()))
            return true;
        count++;
    }
    if (count > 1)
        return true;
    return false;
}
Ejemplo n.º 7
0
void GL3Texture2D::initialize(size_t width, size_t height, TextureFormat format, void *data) {
    this->bind(0);

    _props.format = getFormat(format);
    _props.internal_format = getInternalFormat(format);
    _props.width = static_cast<GLsizei>(width);
    _props.height = static_cast<GLsizei>(height);

    glTexImage2D(GL_TEXTURE_2D, 0, _props.internal_format, _props.width, _props.height, 0, _props.format, GL_UNSIGNED_BYTE, data);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    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_WRAP_R, GL_CLAMP_TO_EDGE);

    GLState->Texture.bindTexture(0, GL_TEXTURE_2D, 0);
}
Ejemplo n.º 8
0
void GLTexture2D::setUnsignedByte4Data( const GLubyte* aubData,
									   int xOffset, int yOffset,
									   int width, int height )
{
	bind();

	if( width == 0 )
	{
		width = m_iWidth;
	}
	if( height == 0 )
	{
		height = m_iHeight;
	}

	glTexImage2D( GL_TEXTURE_2D, 0, getInternalFormat(), width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, aubData );
}
UInt32 RenderBuffer::handleGL(DrawEnv                 *pEnv, 
                              UInt32                   osgid, 
                              Window::GLObjectStatusE  mode,
                              UInt32                        )
{
    Window *pWindow = pEnv->getWindow();
    
    if(mode == Window::initialize || mode == Window::reinitialize ||
       mode == Window::needrefresh )
    {
        GLuint uiBufferId = 0;

        if(mode == Window::initialize)
        {
            OSGGETGLFUNC( OSGglGenRenderbuffersProc,
                          osgGlGenRenderbuffersProc,
                         _uiFuncGenRenderbuffers   );

            osgGlGenRenderbuffersProc(1, &uiBufferId);

            pWindow->setGLObjectId(osgid, uiBufferId);
        }
        else
        {
            uiBufferId = pWindow->getGLObjectId(osgid);
        }

        OSGGETGLFUNC( OSGglBindRenderbufferProc,
                      osgGlBindRenderbufferProc,
                     _uiFuncBindRenderbuffer   );

        OSGGETGLFUNC( OSGglRenderbufferStorageProc,
                      osgGlRenderbufferStorageProc,
                     _uiFuncRenderbufferStorage   );

        osgGlBindRenderbufferProc(GL_RENDERBUFFER_EXT, uiBufferId);

        osgGlRenderbufferStorageProc(GL_RENDERBUFFER_EXT,
                                     getInternalFormat(), 
                                     getWidth(), 
                                     getHeight());
    }

    return 0;
}
void GPUImage_UYVY422::genTextures(GLuint* id, int w, int h) {
  int tex_w = w;
  int tex_h = h;

#if defined(UYVY_USE_RGBA8_FORMAT)
  tex_w = w * 0.5;
#endif

  glGenTextures(1, id);
  glBindTexture(GL_TEXTURE_2D, *id);
  glTexImage2D(GL_TEXTURE_2D, 0,
               getInternalFormat(), tex_w, tex_h, 0, 
               getFormat(), getType(), NULL);

  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_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
Ejemplo n.º 11
0
        Texture* Texture::fromImage(
                boost::shared_ptr<Image> image,
                Texture::Format format,
                Texture::Filter filter, 
                Texture::Wrap wrap) {
            Texture* self = new Texture();

            ScopedBind bind(*self);

            setTextureParameters(filter, wrap);

            GLuint internalformat;
            GLuint sourceformat;

            if(!getInternalFormat(format, internalformat)) {
                Log.warn() << "unknown format parameter (" << format << "), using no image";
                return self;
            }

            if(image) {
                switch(image->getFormat()) {
                case Image::RGB:
                    sourceformat = GL_RGB;
                    break;
                case Image::RGBA:
                    sourceformat = GL_RGBA;
                    break;
                default:
                    Log.warn() << "unknown source format (" << image->getFormat() << "), using no image";
                    return self;
                }

                glTexImage2D(GL_TEXTURE_2D, 0, internalformat, image->getWidth(), image->getHeight(), 0,
                    sourceformat, GL_UNSIGNED_BYTE, image->getData().get());
            } else {
                Log.debug() << "NULL image, returning an empty texture";
            }

            return self;
        }
Ejemplo n.º 12
0
GLenum FramebufferAttachment::getComponentType() const
{
    return GetInternalFormatInfo(getInternalFormat()).componentType;
}
Ejemplo n.º 13
0
GLuint FramebufferAttachment::getStencilSize() const
{
    return GetInternalFormatInfo(getInternalFormat()).stencilBits;
}
Ejemplo n.º 14
0
GLuint FramebufferAttachment::getDepthSize() const
{
    return GetInternalFormatInfo(getInternalFormat()).depthBits;
}
Ejemplo n.º 15
0
GLuint FramebufferAttachment::getAlphaSize() const
{
    return GetInternalFormatInfo(getInternalFormat()).alphaBits;
}
Ejemplo n.º 16
0
GLuint FramebufferAttachment::getBlueSize() const
{
    return GetInternalFormatInfo(getInternalFormat()).blueBits;
}
Ejemplo n.º 17
0
GLenum SurfaceRenderTarget11::getActualFormat() const
{
    return d3d11::GetDXGIFormatInfo(d3d11::GetTextureFormatInfo(getInternalFormat()).texFormat).internalFormat;
}
Ejemplo n.º 18
0
GLuint FramebufferAttachment::getDepthSize() const
{
    return (GetInternalFormatInfo(getInternalFormat()).depthBits > 0) ? GetInternalFormatInfo(getActualFormat()).depthBits : 0;
}
Ejemplo n.º 19
0
GLuint FramebufferAttachment::getGreenSize() const
{
    return (GetInternalFormatInfo(getInternalFormat()).greenBits > 0) ? GetInternalFormatInfo(getActualFormat()).greenBits : 0;
}
Ejemplo n.º 20
0
DXGI_FORMAT SurfaceRenderTarget11::getDXGIFormat() const
{
    return d3d11::GetTextureFormatInfo(getInternalFormat(), mRenderer->getRenderer11DeviceCaps()).texFormat;
}
Ejemplo n.º 21
0
GLuint FramebufferAttachment::getStencilSize() const
{
    return (GetInternalFormatInfo(getInternalFormat()).stencilBits > 0) ? GetInternalFormatInfo(getActualFormat()).stencilBits : 0;
}
Ejemplo n.º 22
0
GLenum FramebufferAttachment::getColorEncoding() const
{
    return GetInternalFormatInfo(getInternalFormat()).colorEncoding;
}
Ejemplo n.º 23
0
static int initTextures(void)
{
  struct TexSquare *tsq=0;
  GLfloat texpercx, texpercy;
  int s;
  int x=0, y=0;

  // textures smaller than 64x64 might not be supported
  s=64;
  while (s<image_width)
    s*=2;
  texture_width=s;

  s=64;
  while (s<image_height)
    s*=2;
  texture_height=s;

  if (!is_yuv)
    gl_internal_format = getInternalFormat();

  /* Test the max texture size */
  do {
    GLint w;
    glTexImage2D (GL_PROXY_TEXTURE_2D, 0,
                  gl_internal_format,
                  texture_width, texture_height,
                  0, gl_bitmap_format, gl_bitmap_type, NULL);

    glGetTexLevelParameteriv
      (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);

    if (w >= texture_width)
      break;

    mp_msg (MSGT_VO, MSGL_V, "[gl_tiled] Needed texture [%dx%d] too big, trying ",
            texture_width, texture_height);

    if (texture_width > texture_height)
      texture_width /= 2;
    else
      texture_height /= 2;

    mp_msg (MSGT_VO, MSGL_V, "[%dx%d] !\n", texture_width, texture_height);

    if(texture_width < 64 || texture_height < 64) {
      mp_msg (MSGT_VO, MSGL_FATAL, "[gl_tiled] Give up .. usable texture size not available, or texture config error !\n");
      return -1;
    }
  } while (texture_width > 1 && texture_height > 1);
#ifdef TEXTURE_WIDTH
  texture_width = TEXTURE_WIDTH;
#endif
#ifdef TEXTURE_HEIGHT
  texture_height = TEXTURE_HEIGHT;
#endif

  texnumx = image_width / texture_width;
  if ((image_width % texture_width) > 0)
    texnumx++;

  texnumy = image_height / texture_height;
  if ((image_height % texture_height) > 0)
    texnumy++;

  mp_msg(MSGT_VO, MSGL_V, "[gl_tiled] Creating %dx%d textures of size %dx%d ...\n",
         texnumx, texnumy, texture_width,texture_height);

  /* Allocate the texture memory */

  texpercx = (GLfloat) texture_width / (GLfloat) image_width;
  texpercy = (GLfloat) texture_height / (GLfloat) image_height;

  free(texgrid);
  texgrid = calloc (texnumx * texnumy, sizeof (struct TexSquare));

  raw_line_len = image_width * image_bytes;

  mp_msg (MSGT_VO, MSGL_DBG2, "[gl_tiled] texture-usage %d*width=%d, %d*height=%d\n",
          (int) texnumx, (int) texture_width, (int) texnumy,
          (int) texture_height);

  tsq = texgrid;
  for (y = 0; y < texnumy; y++) {
    for (x = 0; x < texnumx; x++) {
      tsq->fx = x * texpercx;
      tsq->fy = y * texpercy;
      tsq->fw = texpercx;
      tsq->fh = texpercy;

      tsq->texobj=0;
      tsq->uvtexobjs[0] = tsq->uvtexobjs[1] = 0;

      glGenTextures (1, &(tsq->texobj));

      glBindTexture (GL_TEXTURE_2D, tsq->texobj);
      if (is_yuv) {
        glGenTextures(2, tsq->uvtexobjs);
        mpglActiveTexture(GL_TEXTURE1);
        glBindTexture (GL_TEXTURE_2D, tsq->uvtexobjs[0]);
        mpglActiveTexture(GL_TEXTURE2);
        glBindTexture (GL_TEXTURE_2D, tsq->uvtexobjs[1]);
        mpglActiveTexture(GL_TEXTURE0);
      }

      glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format,  gl_bitmap_type, GL_LINEAR,
                       texture_width, texture_height, 0);

      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
      if (is_yuv) {
        int xs, ys, depth;
        int chroma_clear_val = 128;
        mp_get_chroma_shift(image_format, &xs, &ys, &depth);
        chroma_clear_val >>= -depth & 7;
        mpglActiveTexture(GL_TEXTURE1);
        glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format,  gl_bitmap_type, GL_LINEAR,
                         texture_width >> xs, texture_height >> ys,
                         chroma_clear_val);
        mpglActiveTexture(GL_TEXTURE2);
        glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format,  gl_bitmap_type, GL_LINEAR,
                         texture_width >> xs, texture_height >> ys,
                         chroma_clear_val);
        mpglActiveTexture(GL_TEXTURE0);
      }

      tsq++;
    }  /* for all texnumx */
  }  /* for all texnumy */

  return 0;
}
Ejemplo n.º 24
0
GLuint FramebufferAttachment::getRedSize() const
{
    return GetInternalFormatInfo(getInternalFormat()).redBits;
}
Ejemplo n.º 25
0
GLuint RenderbufferInterface::getStencilSize() const
{
	return sw2es::GetStencilSize(getInternalFormat());
}
Ejemplo n.º 26
0
GLuint FramebufferAttachment::getGreenSize() const
{
    return GetInternalFormatInfo(getInternalFormat()).greenBits;
}