Exemplo n.º 1
0
    void NativeTextureGLES::updateRegion(int x, int y, const ImageData& data_)
    {
        ImageData data = data_;
        assert(_width >= data.w - x);
        assert(_height >= data.h - y);
        glBindTexture(GL_TEXTURE_2D, (GLuint) _id);

        glPixel glp = SurfaceFormat2GL(_format);
        //saveImage(data, "test1.png");


        MemoryTexture mt;
        if (_format != data.format)
        {
            mt.init(data.w, data.h, _format);
            mt.fill_zero();
            mt.updateRegion(0, 0, data);
            data = mt.lock();
        }

        glTexSubImage2D(GL_TEXTURE_2D, 0,
                        x, y, data.w, data.h,
                        glp.format, glp.type, data.data);
        CHECKGL();
    }
    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();
    }
	void NativeTextureGLES::updateRegion(int x, int y, const ImageData &data)
	{
		assert(_width >= data.w - x);
		assert(_height>= data.h - y);
		glBindTexture(GL_TEXTURE_2D, _id);

		glPixel glp = SurfaceFormat2GL(_format);
		//saveImage(data, "test1.png");

		glTexSubImage2D(GL_TEXTURE_2D, 0, 
			x, y, data.w, data.h, 
			glp.format, glp.type, data.data);
	}
    void NativeTextureGLES::init(const ImageData& src, bool sysMemCopy)
    {
        size_t id = createTexture();

        glPixel p = SurfaceFormat2GL(src.format);
        if (p.compressed)
            oxglCompressedTexImage2D(GL_TEXTURE_2D, 0, p.format, src.w, src.h, 0, src.h * src.pitch, src.data);
        else
        {
            glTexImage2D(GL_TEXTURE_2D, 0, p.format, src.w, src.h, 0, p.format, p.type, src.data);
        }

        OX_ASSERT(sysMemCopy == false);

        init((nativeTextureHandle)id, src.w, src.h, src.format);
        CHECKGL();
    }
Exemplo n.º 5
0
    void NativeTextureGLES::unlock()
    {
        if (!_lockFlags)
            return;

        if (_lockFlags & lock_write)
        {
            glBindTexture(GL_TEXTURE_2D, (GLuint) _id);
            GLenum er = glGetError();

            ImageData src = ImageData(_width, _height, (int)(_data.size() / _height), _format, &_data.front());
            ImageData locked = src.getRect(_lockRect);

            //glPixelStorei (GL_UNPACK_ALIGNMENT,  1);//byte align
            er = glGetError();

            //todo add EXT_unpack_subimage support

            MemoryTexture mt;
            mt.init(_lockRect.getWidth(), _lockRect.getHeight(), _format);
            ImageData q = mt.lock();
            operations::copy(locked, q);
            mt.unlock();

            glPixel glp = SurfaceFormat2GL(_format);



            glTexSubImage2D(GL_TEXTURE_2D, 0,
                            _lockRect.getX(), _lockRect.getY(), _lockRect.getWidth(), _lockRect.getHeight(),
                            glp.format, glp.type, locked.data);

            er = glGetError();

            _lockFlags = 0;
        }

        CHECKGL();
    }