Fixed NanoVG.
This commit is contained in:
parent
610055fbb0
commit
9128c4f374
@ -29,6 +29,8 @@
|
||||
|
||||
#include <bx/string.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bimg/decode.h>
|
||||
|
||||
#include "entry/entry.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "nanovg/nanovg.h"
|
||||
@ -939,13 +941,48 @@ struct DemoData
|
||||
int images[12];
|
||||
};
|
||||
|
||||
int createImage(struct NVGcontext* _ctx, const char* _filePath, int _imageFlags)
|
||||
{
|
||||
uint32_t size;
|
||||
void* data = load(_filePath, &size);
|
||||
if (NULL == data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bimg::ImageContainer* imageContainer = bimg::imageParse(
|
||||
entry::getAllocator()
|
||||
, data
|
||||
, size
|
||||
, bimg::TextureFormat::RGBA8
|
||||
);
|
||||
unload(data);
|
||||
|
||||
if (NULL == imageContainer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int texId = nvgCreateImageRGBA(
|
||||
_ctx
|
||||
, imageContainer->m_width
|
||||
, imageContainer->m_height
|
||||
, _imageFlags
|
||||
, (const uint8_t*)imageContainer->m_data
|
||||
);
|
||||
|
||||
bimg::imageFree(imageContainer);
|
||||
|
||||
return texId;
|
||||
}
|
||||
|
||||
int loadDemoData(struct NVGcontext* vg, struct DemoData* data)
|
||||
{
|
||||
for (uint32_t ii = 0; ii < 12; ++ii)
|
||||
{
|
||||
char file[128];
|
||||
bx::snprintf(file, 128, "images/image%d.jpg", ii+1);
|
||||
data->images[ii] = nvgCreateImage(vg, file, 0);
|
||||
data->images[ii] = createImage(vg, file, 0);
|
||||
if (data->images[ii] == 0)
|
||||
{
|
||||
printf("Could not load %s.\n", file);
|
||||
@ -1234,7 +1271,7 @@ class ExampleNanoVG : public entry::AppI
|
||||
loadDemoData(m_nvg, &m_data);
|
||||
|
||||
bndSetFont(nvgCreateFont(m_nvg, "droidsans", "font/droidsans.ttf") );
|
||||
bndSetIconImage(nvgCreateImage(m_nvg, "images/blender_icons16.png", 0) );
|
||||
bndSetIconImage(createImage(m_nvg, "images/blender_icons16.png", 0) );
|
||||
|
||||
m_timeOffset = bx::getHPCounter();
|
||||
}
|
||||
|
@ -23,10 +23,6 @@
|
||||
|
||||
#include "nanovg.h"
|
||||
|
||||
#ifndef NANOVG_HAS_STB_IMAGE
|
||||
# define NANOVG_HAS_STB_IMAGE 0
|
||||
#endif // NANOVG_HAS_STB_IMAGE
|
||||
|
||||
#include <bx/macros.h>
|
||||
|
||||
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4701) // error C4701: potentially uninitialized local variable 'cint' used
|
||||
@ -41,28 +37,6 @@ BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wunused-result");
|
||||
#include "fontstash.h"
|
||||
BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
|
||||
#if NANOVG_HAS_STB_IMAGE
|
||||
#define LODEPNG_NO_COMPILE_ENCODER
|
||||
#define LODEPNG_NO_COMPILE_DISK
|
||||
#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
|
||||
#define LODEPNG_NO_COMPILE_ERROR_TEXT
|
||||
#define LODEPNG_NO_COMPILE_ALLOCATORS
|
||||
#define LODEPNG_NO_COMPILE_CPP
|
||||
#include <lodepng/lodepng.h>
|
||||
|
||||
BX_PRAGMA_DIAGNOSTIC_PUSH();
|
||||
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wmissing-field-initializers");
|
||||
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wshadow");
|
||||
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wint-to-pointer-cast")
|
||||
#if BX_COMPILER_GCC >= 60000
|
||||
BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wmisleading-indentation");
|
||||
BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wshift-negative-value");
|
||||
#endif // BX_COMPILER_GCC >= 60000_
|
||||
|
||||
#include <stb/stb_image.c>
|
||||
BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
#endif // NANOVG_HAS_STB_IMAGE
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4100) // unreferenced formal parameter
|
||||
#pragma warning(disable: 4127) // conditional expression is constant
|
||||
@ -816,45 +790,6 @@ void nvgFillPaint(NVGcontext* ctx, NVGpaint paint)
|
||||
nvgTransformMultiply(state->fill.xform, state->xform);
|
||||
}
|
||||
|
||||
int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags)
|
||||
{
|
||||
#if NANOVG_HAS_STB_IMAGE
|
||||
int w, h, n, image;
|
||||
unsigned char* img;
|
||||
stbi_set_unpremultiply_on_load(1);
|
||||
stbi_convert_iphone_png_to_rgb(1);
|
||||
img = stbi_load(filename, &w, &h, &n, 4);
|
||||
if (img == NULL) {
|
||||
// printf("Failed to load %s - %s\n", filename, stbi_failure_reason());
|
||||
return 0;
|
||||
}
|
||||
image = nvgCreateImageRGBA(ctx, w, h, imageFlags, img);
|
||||
stbi_image_free(img);
|
||||
return image;
|
||||
#else
|
||||
BX_UNUSED(ctx, filename, imageFlags);
|
||||
return 0;
|
||||
#endif // NANOVG_HAS_STB_IMAGE
|
||||
}
|
||||
|
||||
int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata)
|
||||
{
|
||||
#if NANOVG_HAS_STB_IMAGE
|
||||
int w, h, n, image;
|
||||
unsigned char* img = stbi_load_from_memory(data, ndata, &w, &h, &n, 4);
|
||||
if (img == NULL) {
|
||||
// printf("Failed to load %s - %s\n", filename, stbi_failure_reason());
|
||||
return 0;
|
||||
}
|
||||
image = nvgCreateImageRGBA(ctx, w, h, imageFlags, img);
|
||||
stbi_image_free(img);
|
||||
return image;
|
||||
#else
|
||||
BX_UNUSED(ctx, imageFlags, data, ndata);
|
||||
return 0;
|
||||
#endif // NANOVG_HAS_STB_IMAGE
|
||||
}
|
||||
|
||||
int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data)
|
||||
{
|
||||
return ctx->params.renderCreateTexture(ctx->params.userPtr, NVG_TEXTURE_RGBA, w, h, imageFlags, data);
|
||||
|
@ -386,7 +386,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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user