void NativeTextureGLES::init(int w, int h, TextureFormat tf, bool rt)
    {
        release();


        size_t id = createTexture();

        if (rt)
        {
            if (!HAVE_NPOT_RT())
            {
                w = nextPOT(w);
                h = nextPOT(h);
            }
        }

        glPixel p = SurfaceFormat2GL(tf);
        glTexImage2D(GL_TEXTURE_2D, 0, p.format, w, h, 0, p.format, p.type, 0);

        if (rt)
        {
            int prevFBO = 0;
            glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFBO);

            glBindTexture(GL_TEXTURE_2D, 0);

            unsigned int fbo = 0;
            oxglGenFramebuffers(1, &fbo);
            oxglBindFramebuffer(GL_FRAMEBUFFER, fbo);
            oxglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, (GLuint)id, 0);

            //printf("created fbo: %d\n", fbo);

            unsigned int status = oxglCheckFramebufferStatus(GL_FRAMEBUFFER);
            //log::message("fbo status %d\n", status);
            //GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES
            if (status != GL_FRAMEBUFFER_COMPLETE)
            {
                log::error("status != GL_FRAMEBUFFER_COMPLETE_OES");
            }

            glViewport(0, 0, w, h);
            glClearColor(0, 0, 0, 0);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            oxglBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
            //log::message("fbo bind\n");

            glBindTexture(GL_TEXTURE_2D, 0);

            _fbo = fbo;
        }

        _id = id;
        _width = w;
        _height = h;
        _format = tf;
        CHECKGL();
    }
Esempio n. 2
0
    void MovieSprite::initPlayer()
    {
        if (_initialized)
            return;

        _initialized = true;

        _initPlayer();

        Point sz = _bufferSize;
        sz = Point(nextPOT(sz.x), nextPOT(sz.y));

        Point uvSize = _bufferSize / 2;
        uvSize = Point(nextPOT(uvSize.x), nextPOT(uvSize.y));
        //uvSize = sz;
        _mtUV.init(uvSize.x, uvSize.y, TF_A8L8);
        _mtUV.fill_zero();
        _textureUV = IVideoDriver::instance->createTexture();
        _textureUV->init(uvSize.x, uvSize.y, _mtUV.getFormat(), false);

        _mtYA.init(sz.x, sz.y, _hasAlphaChannel ? TF_A8L8 : TF_L8);
        _mtYA.fill_zero();
        _textureYA = IVideoDriver::instance->createTexture();
        _textureYA->init(sz.x, sz.y, _mtYA.getFormat(), false);

        if (_hasAlphaChannel)
            setBlendMode(blend_premultiplied_alpha);
        else
            setBlendMode(blend_disabled);

        Diffuse d;
        d.base = _textureYA;
        d.alpha = _textureUV;
        d.premultiplied = true;

        AnimationFrame frame;
        RectF mr = _movieRect.cast<RectF>();

        Vector2 szf = sz.cast<Vector2>();
        RectF tcYA = RectF(mr.pos.div(szf), mr.size.div(szf));
        frame.init(0, d, tcYA, mr, mr.size);

        _yaScale = Vector2(uvSize.x / szf.x, uvSize.y / szf.y);
        _yaScale = Vector2(0.5f, 0.5f);
        _yaScale = Vector2(1, 1);
        Vector2 s = getSize();
        setAnimFrame(frame);
        setSize(s);
    }
Esempio n. 3
0
bool getPageImageTexture(LVDocView * docview, int width, int height, int bpp, PageImageTextureInfo & ti) {
	ti.textureId = 0;
	ti.dx = width;
	ti.dy = height;
	ti.tdx = nextPOT(width);
	ti.tdy = nextPOT(height);
	LVColorDrawBuf buf(ti.tdx, ti.tdy, 32);
	if (bpp >= 16) {
		docview->Draw(buf, false);
	} else {
		LVGrayDrawBuf grayBuf(width, height, bpp);
		docview->Draw(grayBuf);
		grayBuf.DrawTo(&buf, 0, 0, 0, NULL);
	}
	ti.textureId = crCreateTextureRGBA(ti.tdx, ti.tdy, (lUInt32*)buf.GetScanLine(0));
	return ti.textureId != 0;
}
Esempio n. 4
0
    void ResAnim::init(MemoryTexture* original, int columns, int rows, float scaleFactor)
    {
        _scaleFactor = scaleFactor;
        if (!original)
            return;

        spNativeTexture texture = IVideoDriver::instance->createTexture();
        int w2 = nextPOT(original->getWidth());
        int h2 = nextPOT(original->getHeight());
        if (w2 != original->getWidth() || h2 != original->getHeight())
        {
            texture->init(w2, h2, original->getFormat());
            texture->updateRegion(0, 0, original->lock());
        }
        else
        {
            texture->init(original->lock(), false);
        }

        texture->apply();

        init(texture, original->getSize(), columns, rows, scaleFactor);
    }
	void apply_atlas(atlas_data &ad)
	{
		if (!ad.texture)
			return;
		

		MemoryTexture mt;
		const Rect &bounds = ad.atlas.getBounds();
		int w = nextPOT(bounds.getWidth());
		int h = nextPOT(bounds.getHeight());
		mt.init(ad.mt.lock().getRect(Rect(0, 0, w, h)));
		
		ImageData image_data = mt.lock();	
		ad.texture->init(image_data, false);
		ad.mt.unlock();

		ad.texture->apply();

		/*
		char str[255];
		sprintf(str, "%d.png", ad.texture.get());
		saveImage(image_data, str, "png");
		*/
	}
Esempio n. 6
0
bool AVAlphaTexture::Create(int alphaSize)
{
    alphaSize = nextPOT(alphaSize);

    if( FAILED( D3DXCreateTexture( m_pd3dDevice, alphaSize, alphaSize, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pAlphaTexture)))
        return false;

    D3DLOCKED_RECT alphaTex_Locked;
    ZeroMemory( &alphaTex_Locked, sizeof(alphaTex_Locked) );

    if( FAILED( m_pAlphaTexture->LockRect(0, &alphaTex_Locked, NULL, 0) ))
        return false;

    BYTE *defBits = (BYTE*)alphaTex_Locked.pBits;

    int i = 0;

    for(int y=0; y<alphaSize; y++)
    {
        for(int x=0; x<alphaSize; x++)
        {
            defBits[i++] = 0x00; //A
            defBits[i++] = 0x00; //B
            defBits[i++] = 0x00; //G
            defBits[i++] = 0x00; //R
            //그냥 루프 돌려도 상관은 없는데, 나중에 못알아볼거 같다
        }
    }

    if( FAILED( m_pAlphaTexture->UnlockRect(0)) )
        return false;

    m_alphaSize = alphaSize;

    return true;
}