Esempio n. 1
0
// andrewmac:
int nvgCreateImageBGFX(struct NVGcontext* ctx, int w, int h, int imageFlags, bgfx::TextureHandle texture)
{
   struct NVGparams* params = nvgInternalParams(ctx);
   struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
   struct GLNVGtexture* tex = glnvg__allocTexture(gl);

   if (tex == NULL)
   {
      return 0;
   }

   tex->width = w;
   tex->height = h;
   tex->type = NVG_TEXTURE_RGBA;
   tex->flags = imageFlags;
   tex->id = texture;
   return tex->id.idx;
}
Esempio n. 2
0
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags)
{
	BX_UNUSED(_imageFlags);
	bgfx::TextureHandle textures[] =
	{
		bgfx::createTexture2D(_width, _height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT),
		bgfx::createTexture2D(_width, _height, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT | BGFX_TEXTURE_RT_WRITE_ONLY)
	};
	bgfx::FrameBufferHandle fbh = bgfx::createFrameBuffer(
		  BX_COUNTOF(textures)
		, textures
		, true
		);

	if (!bgfx::isValid(fbh) )
	{
		return NULL;
	}

	struct NVGparams* params = nvgInternalParams(_ctx);
	struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
	struct GLNVGtexture* tex = glnvg__allocTexture(gl);

	if (NULL == tex)
	{
		bgfx::destroy(fbh);
		return NULL;
	}

	tex->width  = _width;
	tex->height = _height;
	tex->type   = NVG_TEXTURE_RGBA;
	tex->flags  = _imageFlags | NVG_IMAGE_PREMULTIPLIED;
	tex->id     = bgfx::getTexture(fbh);

	NVGLUframebuffer* framebuffer = BX_NEW(gl->allocator, NVGLUframebuffer);
	framebuffer->ctx    = _ctx;
	framebuffer->image  = tex->id.idx;
	framebuffer->handle = fbh;

	return framebuffer;
}
Esempio n. 3
0
static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data)
{
    GLNVGcontext* gl = (GLNVGcontext*)uptr;
    GLNVGtexture* tex = glnvg__allocTexture(gl);

    if (tex == NULL) return 0;

    glGenTextures(1, &tex->tex);
    tex->width = w;
    tex->height = h;
    tex->type = type;

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->width);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);

    if (type == NVG_TEXTURE_RGBA)
        glTextureImage2DEXT(tex->tex, GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
    else
        glTextureImage2DEXT(tex->tex, GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, data);

    if (imageFlags & NVG_IMAGE_GENERATE_MIPMAPS) {
        glTextureParameteriEXT(tex->tex, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    } else {
        glTextureParameteriEXT(tex->tex, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }
    glTextureParameteriEXT(tex->tex, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);

    // The new way to build mipmaps on GLES and GL3
    if (imageFlags & NVG_IMAGE_GENERATE_MIPMAPS) {
        glGenerateTextureMipmapEXT(tex->tex, GL_TEXTURE_2D);
    }

    return tex->id;
}
Esempio n. 4
0
static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data)
{
    GLNVGcontext* gl = (GLNVGcontext*)uptr;
    GLNVGtexture* tex = glnvg__allocTexture(gl);

    if (tex == NULL) return 0;

    const bool formatRGBA8 = type == NVG_TEXTURE_RGBA;
    const bool useMipmaps = (imageFlags & NVG_IMAGE_GENERATE_MIPMAPS) != 0;
    glCreateTextures(GL_TEXTURE_2D, 1, &tex->tex);
    const uint32_t mipCount = useMipmaps ? bit_fls(core::max<uint32_t>(w, h)) : 1;
    glTextureStorage2D(tex->tex, mipCount, formatRGBA8 ? GL_RGBA8 : GL_R8, w, h);
    tex->width = w;
    tex->height = h;
    tex->type = type;


    if (data)
    {
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->width);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        glTextureSubImage2D(tex->tex, 0, 0, 0, w, h, formatRGBA8 ? GL_RGBA : GL_RED, GL_UNSIGNED_BYTE, data);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
        glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        // The new way to build mipmaps on GLES and GL3
        if (useMipmaps) {
            glGenerateTextureMipmap(tex->tex);
        }
    }

    glTextureParameteri(tex->tex, GL_TEXTURE_MIN_FILTER, useMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
    glTextureParameteri(tex->tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    return tex->id;
}