Cleanup.
This commit is contained in:
parent
f3ee8855fa
commit
f88c44a835
@ -131,7 +131,7 @@ namespace
|
||||
|
||||
struct GLNVGcontext
|
||||
{
|
||||
bx::AllocatorI* m_allocator;
|
||||
bx::AllocatorI* allocator;
|
||||
|
||||
bgfx::ProgramHandle prog;
|
||||
bgfx::UniformHandle u_scissorMat;
|
||||
@ -151,7 +151,7 @@ namespace
|
||||
bgfx::TextureHandle texMissing;
|
||||
|
||||
bgfx::TransientVertexBuffer tvb;
|
||||
bgfx::ViewId m_viewId;
|
||||
bgfx::ViewId viewId;
|
||||
|
||||
struct GLNVGtexture* textures;
|
||||
float view[2];
|
||||
@ -197,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)
|
||||
@ -559,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)
|
||||
@ -607,7 +607,7 @@ namespace
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -631,7 +631,7 @@ namespace
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -646,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)
|
||||
@ -663,7 +663,7 @@ namespace
|
||||
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)
|
||||
@ -676,7 +676,7 @@ namespace
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -696,7 +696,7 @@ namespace
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -709,7 +709,7 @@ namespace
|
||||
bgfx::setState(gl->state);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -827,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) );
|
||||
@ -840,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;
|
||||
@ -857,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;
|
||||
@ -873,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;
|
||||
@ -1078,17 +1078,17 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
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(int32_t edgeaa, uint16_t _viewId, bx::AllocatorI* _allocator)
|
||||
NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator)
|
||||
{
|
||||
if (NULL == _allocator)
|
||||
{
|
||||
@ -1118,12 +1118,12 @@ NVGcontext* nvgCreate(int32_t edgeaa, uint16_t _viewId, bx::AllocatorI* _allocat
|
||||
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 = _viewId;
|
||||
gl->allocator = _allocator;
|
||||
gl->edgeAntiAlias = _edgeaa;
|
||||
gl->viewId = _viewId;
|
||||
|
||||
ctx = nvgCreateInternal(¶ms);
|
||||
if (ctx == NULL) goto error;
|
||||
@ -1140,37 +1140,37 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NVGcontext* nvgCreate(int32_t edgeaa, uint16_t _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);
|
||||
}
|
||||
|
||||
void nvgSetViewId(struct NVGcontext* ctx, uint16_t _viewId)
|
||||
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;
|
||||
gl->m_viewId = _viewId;
|
||||
gl->viewId = _viewId;
|
||||
}
|
||||
|
||||
uint16_t nvgGetViewId(struct NVGcontext* ctx)
|
||||
uint16_t nvgGetViewId(struct NVGcontext* _ctx)
|
||||
{
|
||||
struct NVGparams* params = nvgInternalParams(ctx);
|
||||
struct NVGparams* params = nvgInternalParams(_ctx);
|
||||
struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
|
||||
return gl->m_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, uint16_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);
|
||||
|
||||
@ -1182,7 +1182,7 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, int height,
|
||||
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)
|
||||
{
|
||||
BX_UNUSED(_imageFlags);
|
||||
bgfx::TextureHandle textures[] =
|
||||
@ -1217,7 +1217,7 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int _width, int _heig
|
||||
tex->flags = _imageFlags | NVG_IMAGE_PREMULTIPLIED;
|
||||
tex->id = bgfx::getTexture(fbh);
|
||||
|
||||
NVGLUframebuffer* framebuffer = BX_NEW(gl->m_allocator, NVGLUframebuffer);
|
||||
NVGLUframebuffer* framebuffer = BX_NEW(gl->allocator, NVGLUframebuffer);
|
||||
framebuffer->ctx = _ctx;
|
||||
framebuffer->image = tex->id.idx;
|
||||
framebuffer->handle = fbh;
|
||||
@ -1225,15 +1225,15 @@ NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int _width, int _heig
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
void nvgluBindFramebuffer(NVGLUframebuffer* framebuffer)
|
||||
void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer)
|
||||
{
|
||||
static NVGcontext* s_prevCtx = NULL;
|
||||
static bgfx::ViewId s_prevViewId;
|
||||
if (framebuffer != NULL)
|
||||
if (_framebuffer != NULL)
|
||||
{
|
||||
s_prevCtx = framebuffer->ctx;
|
||||
s_prevViewId = nvgGetViewId(framebuffer->ctx);
|
||||
nvgSetViewId(framebuffer->ctx, framebuffer->viewId);
|
||||
s_prevCtx = _framebuffer->ctx;
|
||||
s_prevViewId = nvgGetViewId(_framebuffer->ctx);
|
||||
nvgSetViewId(_framebuffer->ctx, _framebuffer->viewId);
|
||||
}
|
||||
else if (s_prevCtx != NULL)
|
||||
{
|
||||
@ -1241,27 +1241,27 @@ void nvgluBindFramebuffer(NVGLUframebuffer* framebuffer)
|
||||
}
|
||||
}
|
||||
|
||||
void nvgluDeleteFramebuffer(NVGLUframebuffer* framebuffer)
|
||||
void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer)
|
||||
{
|
||||
if (framebuffer == NULL)
|
||||
if (_framebuffer == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (bgfx::isValid(framebuffer->handle))
|
||||
if (bgfx::isValid(_framebuffer->handle))
|
||||
{
|
||||
bgfx::destroy(framebuffer->handle);
|
||||
bgfx::destroy(_framebuffer->handle);
|
||||
}
|
||||
|
||||
struct NVGparams* params = nvgInternalParams(framebuffer->ctx);
|
||||
struct NVGparams* params = nvgInternalParams(_framebuffer->ctx);
|
||||
struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
|
||||
glnvg__deleteTexture(gl, framebuffer->image);
|
||||
BX_DELETE(gl->m_allocator, framebuffer);
|
||||
glnvg__deleteTexture(gl, _framebuffer->image);
|
||||
BX_DELETE(gl->allocator, _framebuffer);
|
||||
}
|
||||
|
||||
void nvgluSetViewFramebuffer(uint16_t viewId, NVGLUframebuffer* framebuffer)
|
||||
void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer)
|
||||
{
|
||||
framebuffer->viewId = viewId;
|
||||
bgfx::setViewFrameBuffer(viewId, framebuffer->handle);
|
||||
bgfx::setViewMode(viewId, bgfx::ViewMode::Sequential);
|
||||
_framebuffer->viewId = _viewId;
|
||||
bgfx::setViewFrameBuffer(_viewId, _framebuffer->handle);
|
||||
bgfx::setViewMode(_viewId, bgfx::ViewMode::Sequential);
|
||||
}
|
||||
|
@ -6,35 +6,34 @@
|
||||
#ifndef NANOVG_BGFX_H_HEADER_GUARD
|
||||
#define NANOVG_BGFX_H_HEADER_GUARD
|
||||
|
||||
#include "bgfx/bgfx.h"
|
||||
#include <bgfx/bgfx.h>
|
||||
|
||||
namespace bx { struct AllocatorI; }
|
||||
|
||||
struct NVGcontext;
|
||||
|
||||
struct NVGLUframebuffer {
|
||||
struct NVGLUframebuffer
|
||||
{
|
||||
NVGcontext* ctx;
|
||||
bgfx::FrameBufferHandle handle;
|
||||
int image;
|
||||
uint8_t viewId;
|
||||
bgfx::ViewId viewId;
|
||||
};
|
||||
|
||||
typedef struct NVGLUframebuffer NVGLUframebuffer;
|
||||
///
|
||||
NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId, bx::AllocatorI* _allocator);
|
||||
|
||||
///
|
||||
NVGcontext* nvgCreate(int32_t edgeaa, uint16_t _viewId, bx::AllocatorI* _allocator);
|
||||
NVGcontext* nvgCreate(int32_t _edgeaa, bgfx::ViewId _viewId);
|
||||
|
||||
///
|
||||
NVGcontext* nvgCreate(int32_t edgeaa, uint16_t _viewId);
|
||||
void nvgDelete(struct NVGcontext* _ctx);
|
||||
|
||||
///
|
||||
void nvgDelete(struct NVGcontext* ctx);
|
||||
void nvgSetViewId(struct NVGcontext* _ctx, bgfx::ViewId _viewId);
|
||||
|
||||
///
|
||||
void nvgSetViewId(struct NVGcontext* ctx, uint16_t _viewId);
|
||||
|
||||
///
|
||||
uint16_t nvgGetViewId(struct NVGcontext* ctx);
|
||||
uint16_t nvgGetViewId(struct NVGcontext* _ctx);
|
||||
|
||||
// Helper functions to create bgfx framebuffer to render to.
|
||||
// Example:
|
||||
@ -57,18 +56,18 @@ uint16_t nvgGetViewId(struct NVGcontext* ctx);
|
||||
// nvgEndFrame(ctx);
|
||||
|
||||
///
|
||||
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, int height, int imageFlags, uint16_t viewId);
|
||||
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags, bgfx::ViewId _viewId);
|
||||
|
||||
///
|
||||
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int width, int height, int imageFlags);
|
||||
NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* _ctx, int32_t _width, int32_t _height, int32_t _imageFlags);
|
||||
|
||||
///
|
||||
void nvgluBindFramebuffer(NVGLUframebuffer* framebuffer);
|
||||
void nvgluBindFramebuffer(NVGLUframebuffer* _framebuffer);
|
||||
|
||||
///
|
||||
void nvgluDeleteFramebuffer(NVGLUframebuffer* framebuffer);
|
||||
void nvgluDeleteFramebuffer(NVGLUframebuffer* _framebuffer);
|
||||
|
||||
///
|
||||
void nvgluSetViewFramebuffer(uint16_t viewId, NVGLUframebuffer* framebuffer);
|
||||
void nvgluSetViewFramebuffer(bgfx::ViewId _viewId, NVGLUframebuffer* _framebuffer);
|
||||
|
||||
#endif // NANOVG_BGFX_H_HEADER_GUARD
|
||||
|
Loading…
Reference in New Issue
Block a user