~hp/d2tk

14c56cc6b6881c65b1a10692ffcb64276bf6bacd — Hanspeter Portner 4 years ago f2eee8a
Squashed 'nanovg/' changes from 1fd049e..75dbf61

75dbf61 omk: add support for ARGB image surfaces.

git-subtree-dir: nanovg
git-subtree-split: 75dbf615b2b7b3436ef43dc2c8bf5616fd3df3fb
3 files changed, 20 insertions(+), 0 deletions(-)

M src/nanovg.c
M src/nanovg.h
M src/nanovg_gl.h
M src/nanovg.c => src/nanovg.c +5 -0
@@ 829,6 829,11 @@ int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsi
	return ctx->params.renderCreateTexture(ctx->params.userPtr, NVG_TEXTURE_RGBA, w, h, imageFlags, data);
}

int nvgCreateImageARGB(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data)
{
	return ctx->params.renderCreateTexture(ctx->params.userPtr, NVG_TEXTURE_ARGB, w, h, imageFlags, data);
}

void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data)
{
	int w, h;

M src/nanovg.h => src/nanovg.h +5 -0
@@ 379,6 379,10 @@ int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int 
// Returns handle to the image.
int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);

// Creates image from specified image data.
// Returns handle to the image.
int nvgCreateImageARGB(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);

// Updates image data specified by image handle.
void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);



@@ 618,6 622,7 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa
enum NVGtexture {
	NVG_TEXTURE_ALPHA = 0x01,
	NVG_TEXTURE_RGBA = 0x02,
	NVG_TEXTURE_ARGB = 0x03,
};

struct NVGscissor {

M src/nanovg_gl.h => src/nanovg_gl.h +10 -0
@@ 753,6 753,8 @@ static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int im

	if (type == NVG_TEXTURE_RGBA)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
	else if (type == NVG_TEXTURE_ARGB)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, data);
	else
#if defined(NANOVG_GLES2) || defined (NANOVG_GL2)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);


@@ 837,6 839,8 @@ static int glnvg__renderUpdateTexture(void* uptr, int image, int x, int y, int w
	// No support for all of skip, need to update a whole row at a time.
	if (tex->type == NVG_TEXTURE_RGBA)
		data += y*tex->width*4;
	else if (tex->type == NVG_TEXTURE_ARGB)
		data += y*tex->width*4;
	else
		data += y*tex->width;
	x = 0;


@@ 845,6 849,8 @@ static int glnvg__renderUpdateTexture(void* uptr, int image, int x, int y, int w

	if (tex->type == NVG_TEXTURE_RGBA)
		glTexSubImage2D(GL_TEXTURE_2D, 0, x,y, w,h, GL_RGBA, GL_UNSIGNED_BYTE, data);
	else if (tex->type == NVG_TEXTURE_ARGB)
		glTexSubImage2D(GL_TEXTURE_2D, 0, x,y, w,h, GL_BGRA, GL_UNSIGNED_BYTE, data);
	else
#if defined(NANOVG_GLES2) || defined(NANOVG_GL2)
		glTexSubImage2D(GL_TEXTURE_2D, 0, x,y, w,h, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);


@@ 948,11 954,15 @@ static int glnvg__convertPaint(GLNVGcontext* gl, GLNVGfragUniforms* frag, NVGpai
		#if NANOVG_GL_USE_UNIFORMBUFFER
		if (tex->type == NVG_TEXTURE_RGBA)
			frag->texType = (tex->flags & NVG_IMAGE_PREMULTIPLIED) ? 0 : 1;
		else if (tex->type == NVG_TEXTURE_ARGB)
			frag->texType = (tex->flags & NVG_IMAGE_PREMULTIPLIED) ? 0 : 1;
		else
			frag->texType = 2;
		#else
		if (tex->type == NVG_TEXTURE_RGBA)
			frag->texType = (tex->flags & NVG_IMAGE_PREMULTIPLIED) ? 0.0f : 1.0f;
		else if (tex->type == NVG_TEXTURE_ARGB)
			frag->texType = (tex->flags & NVG_IMAGE_PREMULTIPLIED) ? 0.0f : 1.0f;
		else
			frag->texType = 2.0f;
		#endif