summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp323
1 files changed, 193 insertions, 130 deletions
diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp
index 78d854bfac6..abf571a5965 100644
--- a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp
+++ b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp
@@ -31,7 +31,6 @@
#include <bx/bx.h>
#include <bx/allocator.h>
-#include <bx/crtimpl.h>
#include <bx/uint32_t.h>
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4244); // warning C4244: '=' : conversion from '' to '', possible loss of data
@@ -132,7 +131,7 @@ namespace
struct GLNVGcontext
{
- bx::AllocatorI* m_allocator;
+ bx::AllocatorI* allocator;
bgfx::ProgramHandle prog;
bgfx::UniformHandle u_scissorMat;
@@ -152,7 +151,7 @@ namespace
bgfx::TextureHandle texMissing;
bgfx::TransientVertexBuffer tvb;
- uint8_t m_viewId;
+ bgfx::ViewId viewId;
struct GLNVGtexture* textures;
float view[2];
@@ -185,7 +184,7 @@ namespace
for (i = 0; i < gl->ntextures; i++)
{
- if (gl->textures[i].id.idx == bgfx::invalidHandle)
+ if (gl->textures[i].id.idx == bgfx::kInvalidHandle)
{
tex = &gl->textures[i];
break;
@@ -198,7 +197,7 @@ namespace
{
int old = gl->ctextures;
gl->ctextures = (gl->ctextures == 0) ? 2 : gl->ctextures*2;
- gl->textures = (struct GLNVGtexture*)BX_REALLOC(gl->m_allocator, gl->textures, sizeof(struct GLNVGtexture)*gl->ctextures);
+ gl->textures = (struct GLNVGtexture*)BX_REALLOC(gl->allocator, gl->textures, sizeof(struct GLNVGtexture)*gl->ctextures);
bx::memSet(&gl->textures[old], 0xff, (gl->ctextures-old)*sizeof(struct GLNVGtexture) );
if (gl->textures == NULL)
@@ -237,10 +236,10 @@ namespace
if (bgfx::isValid(gl->textures[ii].id)
&& (gl->textures[ii].flags & NVG_IMAGE_NODELETE) == 0)
{
- bgfx::destroyTexture(gl->textures[ii].id);
+ bgfx::destroy(gl->textures[ii].id);
}
bx::memSet(&gl->textures[ii], 0, sizeof(gl->textures[ii]) );
- gl->textures[ii].id.idx = bgfx::invalidHandle;
+ gl->textures[ii].id.idx = bgfx::kInvalidHandle;
return 1;
}
}
@@ -280,7 +279,7 @@ namespace
}
else
{
- gl->u_halfTexel.idx = bgfx::invalidHandle;
+ gl->u_halfTexel.idx = bgfx::kInvalidHandle;
}
s_nvgDecl
@@ -295,7 +294,14 @@ namespace
return 1;
}
- static int nvgRenderCreateTexture(void* _userPtr, int _type, int _width, int _height, int _flags, const unsigned char* _rgba)
+ static int nvgRenderCreateTexture(
+ void* _userPtr
+ , int _type
+ , int _width
+ , int _height
+ , int _flags
+ , const unsigned char* _rgba
+ )
{
struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
struct GLNVGtexture* tex = glnvg__allocTexture(gl);
@@ -386,7 +392,8 @@ namespace
struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
struct GLNVGtexture* tex = glnvg__findTexture(gl, image);
- if (!bgfx::isValid(tex->id) )
+ if (NULL == tex
+ || !bgfx::isValid(tex->id) )
{
return 0;
}
@@ -399,16 +406,16 @@ namespace
static void glnvg__xformToMat3x4(float* m3, float* t)
{
- m3[0] = t[0];
- m3[1] = t[1];
- m3[2] = 0.0f;
- m3[3] = 0.0f;
- m3[4] = t[2];
- m3[5] = t[3];
- m3[6] = 0.0f;
- m3[7] = 0.0f;
- m3[8] = t[4];
- m3[9] = t[5];
+ m3[ 0] = t[0];
+ m3[ 1] = t[1];
+ m3[ 2] = 0.0f;
+ m3[ 3] = 0.0f;
+ m3[ 4] = t[2];
+ m3[ 5] = t[3];
+ m3[ 6] = 0.0f;
+ m3[ 7] = 0.0f;
+ m3[ 8] = t[4];
+ m3[ 9] = t[5];
m3[10] = 1.0f;
m3[11] = 0.0f;
}
@@ -421,8 +428,14 @@ namespace
return c;
}
- static int glnvg__convertPaint(struct GLNVGcontext* gl, struct GLNVGfragUniforms* frag, struct NVGpaint* paint,
- struct NVGscissor* scissor, float width, float fringe)
+ static int glnvg__convertPaint(
+ struct GLNVGcontext* gl
+ , struct GLNVGfragUniforms* frag
+ , struct NVGpaint* paint
+ , struct NVGscissor* scissor
+ , float width
+ , float fringe
+ )
{
struct GLNVGtexture* tex = NULL;
float invxform[6] = {};
@@ -462,10 +475,15 @@ namespace
}
nvgTransformInverse(invxform, paint->xform);
frag->type = NSVG_SHADER_FILLIMG;
+
if (tex->type == NVG_TEXTURE_RGBA)
+ {
frag->texType = (tex->flags & NVG_IMAGE_PREMULTIPLIED) ? 0.0f : 1.0f;
+ }
else
+ {
frag->texType = 2.0f;
+ }
gl->th = tex->id;
}
else
@@ -483,16 +501,16 @@ namespace
static void glnvg__mat3(float* dst, float* src)
{
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
+ dst[0] = src[ 0];
+ dst[1] = src[ 1];
+ dst[2] = src[ 2];
- dst[3] = src[4];
- dst[4] = src[5];
- dst[5] = src[6];
+ dst[3] = src[ 4];
+ dst[4] = src[ 5];
+ dst[5] = src[ 6];
- dst[6] = src[8];
- dst[7] = src[9];
+ dst[6] = src[ 8];
+ dst[7] = src[ 9];
dst[8] = src[10];
}
@@ -541,7 +559,7 @@ namespace
struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
gl->view[0] = (float)width;
gl->view[1] = (float)height;
- bgfx::setViewRect(gl->m_viewId, 0, 0, width * devicePixelRatio, height * devicePixelRatio);
+ bgfx::setViewRect(gl->viewId, 0, 0, width * devicePixelRatio, height * devicePixelRatio);
}
static void fan(uint32_t _start, uint32_t _count)
@@ -586,10 +604,10 @@ namespace
| BGFX_STENCIL_OP_FAIL_Z_KEEP
| BGFX_STENCIL_OP_PASS_Z_DECR
);
- bgfx::setVertexBuffer(&gl->tvb);
+ bgfx::setVertexBuffer(0, &gl->tvb);
bgfx::setTexture(0, gl->s_tex, gl->th);
fan(paths[i].fillOffset, paths[i].fillCount);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
}
@@ -611,15 +629,15 @@ namespace
| BGFX_STENCIL_OP_FAIL_Z_KEEP
| BGFX_STENCIL_OP_PASS_Z_KEEP
);
- bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount);
+ bgfx::setVertexBuffer(0, &gl->tvb, paths[i].strokeOffset, paths[i].strokeCount);
bgfx::setTexture(0, gl->s_tex, gl->th);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
}
// Draw fill
bgfx::setState(gl->state);
- bgfx::setVertexBuffer(&gl->tvb, call->vertexOffset, call->vertexCount);
+ bgfx::setVertexBuffer(0, &gl->tvb, call->vertexOffset, call->vertexCount);
bgfx::setTexture(0, gl->s_tex, gl->th);
bgfx::setStencil(0
| BGFX_STENCIL_TEST_NOTEQUAL
@@ -628,7 +646,7 @@ namespace
| BGFX_STENCIL_OP_FAIL_Z_ZERO
| BGFX_STENCIL_OP_PASS_Z_ZERO
);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
static void glnvg__convexFill(struct GLNVGcontext* gl, struct GLNVGcall* call)
@@ -642,10 +660,10 @@ namespace
{
if (paths[i].fillCount == 0) continue;
bgfx::setState(gl->state);
- bgfx::setVertexBuffer(&gl->tvb);
+ bgfx::setVertexBuffer(0, &gl->tvb);
bgfx::setTexture(0, gl->s_tex, gl->th);
fan(paths[i].fillOffset, paths[i].fillCount);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
if (gl->edgeAntiAlias)
@@ -656,9 +674,9 @@ namespace
bgfx::setState(gl->state
| BGFX_STATE_PT_TRISTRIP
);
- bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount);
+ bgfx::setVertexBuffer(0, &gl->tvb, paths[i].strokeOffset, paths[i].strokeCount);
bgfx::setTexture(0, gl->s_tex, gl->th);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
}
}
@@ -676,9 +694,9 @@ namespace
bgfx::setState(gl->state
| BGFX_STATE_PT_TRISTRIP
);
- bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount);
+ bgfx::setVertexBuffer(0, &gl->tvb, paths[i].strokeOffset, paths[i].strokeCount);
bgfx::setTexture(0, gl->s_tex, gl->th);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
}
@@ -689,9 +707,9 @@ namespace
nvgRenderSetUniforms(gl, call->uniformOffset, call->image);
bgfx::setState(gl->state);
- bgfx::setVertexBuffer(&gl->tvb, call->vertexOffset, call->vertexCount);
+ bgfx::setVertexBuffer(0, &gl->tvb, call->vertexOffset, call->vertexCount);
bgfx::setTexture(0, gl->s_tex, gl->th);
- bgfx::submit(gl->m_viewId, gl->prog);
+ bgfx::submit(gl->viewId, gl->prog);
}
}
@@ -809,7 +827,7 @@ namespace
if (gl->ncalls+1 > gl->ccalls)
{
gl->ccalls = gl->ccalls == 0 ? 32 : gl->ccalls * 2;
- gl->calls = (struct GLNVGcall*)BX_REALLOC(gl->m_allocator, gl->calls, sizeof(struct GLNVGcall) * gl->ccalls);
+ gl->calls = (struct GLNVGcall*)BX_REALLOC(gl->allocator, gl->calls, sizeof(struct GLNVGcall) * gl->ccalls);
}
ret = &gl->calls[gl->ncalls++];
bx::memSet(ret, 0, sizeof(struct GLNVGcall) );
@@ -822,7 +840,7 @@ namespace
if (gl->npaths + n > gl->cpaths) {
GLNVGpath* paths;
int cpaths = glnvg__maxi(gl->npaths + n, 128) + gl->cpaths / 2; // 1.5x Overallocate
- paths = (GLNVGpath*)BX_REALLOC(gl->m_allocator, gl->paths, sizeof(GLNVGpath) * cpaths);
+ paths = (GLNVGpath*)BX_REALLOC(gl->allocator, gl->paths, sizeof(GLNVGpath) * cpaths);
if (paths == NULL) return -1;
gl->paths = paths;
gl->cpaths = cpaths;
@@ -839,7 +857,7 @@ namespace
{
NVGvertex* verts;
int cverts = glnvg__maxi(gl->nverts + n, 4096) + gl->cverts/2; // 1.5x Overallocate
- verts = (NVGvertex*)BX_REALLOC(gl->m_allocator, gl->verts, sizeof(NVGvertex) * cverts);
+ verts = (NVGvertex*)BX_REALLOC(gl->allocator, gl->verts, sizeof(NVGvertex) * cverts);
if (verts == NULL) return -1;
gl->verts = verts;
gl->cverts = cverts;
@@ -855,7 +873,7 @@ namespace
if (gl->nuniforms+n > gl->cuniforms)
{
gl->cuniforms = gl->cuniforms == 0 ? glnvg__maxi(n, 32) : gl->cuniforms * 2;
- gl->uniforms = (unsigned char*)BX_REALLOC(gl->m_allocator, gl->uniforms, gl->cuniforms * structSize);
+ gl->uniforms = (unsigned char*)BX_REALLOC(gl->allocator, gl->uniforms, gl->cuniforms * structSize);
}
ret = gl->nuniforms * structSize;
gl->nuniforms += n;
@@ -870,8 +888,16 @@ namespace
vtx->v = v;
}
- static void nvgRenderFill(void* _userPtr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor,
- float fringe, const float* bounds, const NVGpath* paths, int npaths)
+ static void nvgRenderFill(
+ void* _userPtr
+ , NVGpaint* paint
+ , NVGcompositeOperationState compositeOperation
+ , NVGscissor* scissor
+ , float fringe
+ , const float* bounds
+ , const NVGpath* paths
+ , int npaths
+ )
{
struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
@@ -948,8 +974,16 @@ namespace
}
}
- static void nvgRenderStroke(void* _userPtr, struct NVGpaint* paint, NVGcompositeOperationState compositeOperation, struct NVGscissor* scissor, float fringe,
- float strokeWidth, const struct NVGpath* paths, int npaths)
+ static void nvgRenderStroke(
+ void* _userPtr
+ , struct NVGpaint* paint
+ , NVGcompositeOperationState compositeOperation
+ , struct NVGscissor* scissor
+ , float fringe
+ , float strokeWidth
+ , const struct NVGpath* paths
+ , int npaths
+ )
{
struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
@@ -1017,22 +1051,22 @@ namespace
return;
}
- bgfx::destroyProgram(gl->prog);
- bgfx::destroyTexture(gl->texMissing);
+ bgfx::destroy(gl->prog);
+ bgfx::destroy(gl->texMissing);
- bgfx::destroyUniform(gl->u_scissorMat);
- bgfx::destroyUniform(gl->u_paintMat);
- bgfx::destroyUniform(gl->u_innerCol);
- bgfx::destroyUniform(gl->u_outerCol);
- bgfx::destroyUniform(gl->u_viewSize);
- bgfx::destroyUniform(gl->u_scissorExtScale);
- bgfx::destroyUniform(gl->u_extentRadius);
- bgfx::destroyUniform(gl->u_params);
- bgfx::destroyUniform(gl->s_tex);
+ bgfx::destroy(gl->u_scissorMat);
+ bgfx::destroy(gl->u_paintMat);
+ bgfx::destroy(gl->u_innerCol);
+ bgfx::destroy(gl->u_outerCol);
+ bgfx::destroy(gl->u_viewSize);
+ bgfx::destroy(gl->u_scissorExtScale);
+ bgfx::destroy(gl->u_extentRadius);
+ bgfx::destroy(gl->u_params);
+ bgfx::destroy(gl->s_tex);
if (bgfx::isValid(gl->u_halfTexel) )
{
- bgfx::destroyUniform(gl->u_halfTexel);
+ bgfx::destroy(gl->u_halfTexel);
}
for (uint32_t ii = 0, num = gl->ntextures; ii < num; ++ii)
@@ -1040,37 +1074,36 @@ namespace
if (bgfx::isValid(gl->textures[ii].id)
&& (gl->textures[ii].flags & NVG_IMAGE_NODELETE) == 0)
{
- bgfx::destroyTexture(gl->textures[ii].id);
+ bgfx::destroy(gl->textures[ii].id);
}
}
- BX_FREE(gl->m_allocator, gl->uniforms);
- BX_FREE(gl->m_allocator, gl->verts);
- BX_FREE(gl->m_allocator, gl->paths);
- BX_FREE(gl->m_allocator, gl->calls);
- BX_FREE(gl->m_allocator, gl->textures);
- BX_FREE(gl->m_allocator, gl);
+ BX_FREE(gl->allocator, gl->uniforms);
+ BX_FREE(gl->allocator, gl->verts);
+ BX_FREE(gl->allocator, gl->paths);
+ BX_FREE(gl->allocator, gl->calls);
+ BX_FREE(gl->allocator, gl->textures);
+ BX_FREE(gl->allocator, gl);
}
} // namespace
-NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _allocator)
+NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator)
{
if (NULL == _allocator)
{
-#if BX_CONFIG_ALLOCATOR_CRT
- static bx::CrtAllocator allocator;
+ static bx::DefaultAllocator allocator;
_allocator = &allocator;
-#else
- BX_CHECK(false, "No allocator has been passed to nvgCreate(). Either specify a bx::AllocatorI instance or enable BX_CONFIG_ALLOCATOR_CRT directive.");
- return NULL;
-#endif // BX_CONFIG_ALLOCATOR_CRT
}
struct NVGparams params;
struct NVGcontext* ctx = NULL;
struct GLNVGcontext* gl = (struct GLNVGcontext*)BX_ALLOC(_allocator, sizeof(struct GLNVGcontext) );
- if (gl == NULL) goto error;
+ if (gl == NULL)
+ {
+ goto error;
+ }
+
bx::memSet(gl, 0, sizeof(struct GLNVGcontext) );
bx::memSet(&params, 0, sizeof(params) );
@@ -1085,12 +1118,12 @@ NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _alloca
params.renderStroke = nvgRenderStroke;
params.renderTriangles = nvgRenderTriangles;
params.renderDelete = nvgRenderDelete;
- params.userPtr = gl;
- params.edgeAntiAlias = edgeaa;
+ params.userPtr = gl;
+ params.edgeAntiAlias = _edgeaa;
- gl->m_allocator = _allocator;
- gl->edgeAntiAlias = edgeaa;
- gl->m_viewId = uint8_t(_viewId);
+ gl->allocator = _allocator;
+ gl->edgeAntiAlias = _edgeaa;
+ gl->viewId = _viewId;
ctx = nvgCreateInternal(&params);
if (ctx == NULL) goto error;
@@ -1107,98 +1140,128 @@ error:
return NULL;
}
-NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId) {
- return nvgCreate(edgeaa, _viewId, NULL);
+NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId) {
+ return nvgCreate(_edgeaa, _viewId, NULL);
}
-void nvgDelete(struct NVGcontext* ctx)
+void nvgDelete(struct NVGcontext* _ctx)
{
- nvgDeleteInternal(ctx);
+ nvgDeleteInternal(_ctx);
}
-uint8_t nvgViewId(struct NVGcontext* ctx)
+void nvgSetViewId(struct NVGcontext* _ctx, bgfx::ViewId _viewId)
{
- struct NVGparams* params = nvgInternalParams(ctx);
+ struct NVGparams* params = nvgInternalParams(_ctx);
struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
- return gl->m_viewId;
+ gl->viewId = _viewId;
}
-void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId)
+uint16_t nvgGetViewId(struct NVGcontext* _ctx)
{
- struct NVGparams* params = nvgInternalParams(ctx);
+ struct NVGparams* params = nvgInternalParams(_ctx);
struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
- gl->m_viewId = uint8_t(_viewId);
+ return gl->viewId;
}
-bgfx::TextureHandle nvglImageHandle(NVGcontext* ctx, int image)
+bgfx::TextureHandle nvglImageHandle(NVGcontext* _ctx, int32_t _image)
{
- GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(ctx)->userPtr;
- GLNVGtexture* tex = glnvg__findTexture(gl, image);
+ GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(_ctx)->userPtr;
+ GLNVGtexture* tex = glnvg__findTexture(gl, _image);
return tex->id;
}
-NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, int height, int imageFlags, uint8_t viewId)
+NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int32_t width, int32_t height, int32_t imageFlags, bgfx::ViewId viewId)
{
- NVGLUframebuffer* framebuffer = nvgluCreateFramebuffer(ctx, width, height, imageFlags);
+ NVGLUframebuffer* framebuffer = nvgluCreateFramebuffer(ctx, width, height, imageFlags);
+
if (framebuffer != NULL)
{
nvgluSetViewFramebuffer(viewId, framebuffer);
}
+
return framebuffer;
}
-NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, int height, int imageFlags)
+NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags)
{
- NVGLUframebuffer* framebuffer = new NVGLUframebuffer;
- framebuffer->ctx = ctx;
- framebuffer->image = nvgCreateImageRGBA(ctx, width, height, imageFlags | NVG_IMAGE_PREMULTIPLIED, NULL);
- bgfx::TextureHandle texture = nvglImageHandle(ctx, framebuffer->image);
- if (!bgfx::isValid(texture))
+ 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) )
{
- nvgluDeleteFramebuffer(framebuffer);
return NULL;
}
- framebuffer->handle = bgfx::createFrameBuffer(1, &texture, false);
- if (!bgfx::isValid(framebuffer->handle))
+
+ struct NVGparams* params = nvgInternalParams(_ctx);
+ struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
+ struct GLNVGtexture* tex = glnvg__allocTexture(gl);
+
+ if (NULL == tex)
{
- nvgluDeleteFramebuffer(framebuffer);
+ 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;
}
-void nvgluBindFramebuffer(NVGLUframebuffer* framebuffer)
+void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer)
{
static NVGcontext* s_prevCtx = NULL;
- static uint8_t s_prevViewId;
- if (framebuffer != NULL)
+ static bgfx::ViewId s_prevViewId;
+ if (_framebuffer != NULL)
{
- s_prevCtx = framebuffer->ctx;
- s_prevViewId = nvgViewId(framebuffer->ctx);
- nvgViewId(framebuffer->ctx, framebuffer->viewId);
- } else if (s_prevCtx != NULL) {
- nvgViewId(s_prevCtx, s_prevViewId);
+ s_prevCtx = _framebuffer->ctx;
+ s_prevViewId = nvgGetViewId(_framebuffer->ctx);
+ nvgSetViewId(_framebuffer->ctx, _framebuffer->viewId);
+ }
+ else if (s_prevCtx != NULL)
+ {
+ nvgSetViewId(s_prevCtx, s_prevViewId);
}
}
-void nvgluDeleteFramebuffer(NVGLUframebuffer* framebuffer)
+void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer)
{
- if (framebuffer == NULL)
- return;
- if (bgfx::isValid(framebuffer->handle))
+ if (_framebuffer == NULL)
{
- bgfx::destroyFrameBuffer(framebuffer->handle);
+ return;
}
- if (framebuffer->image > 0)
+
+ if (bgfx::isValid(_framebuffer->handle))
{
- nvgDeleteImage(framebuffer->ctx, framebuffer->image);
+ bgfx::destroy(_framebuffer->handle);
}
- delete framebuffer;
+
+ struct NVGparams* params = nvgInternalParams(_framebuffer->ctx);
+ struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
+ glnvg__deleteTexture(gl, _framebuffer->image);
+ BX_DELETE(gl->allocator, _framebuffer);
}
-void nvgluSetViewFramebuffer(uint8_t viewId, NVGLUframebuffer* framebuffer)
+void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer)
{
- framebuffer->viewId = viewId;
- bgfx::setViewFrameBuffer(viewId, framebuffer->handle);
- bgfx::setViewSeq(viewId, true);
+ _framebuffer->viewId = _viewId;
+ bgfx::setViewFrameBuffer(_viewId, _framebuffer->handle);
+ bgfx::setViewMode(_viewId, bgfx::ViewMode::Sequential);
}