فهرست منبع

Merge branch 'master' of github.com:bkaradzic/bgfx

Branimir Karadžić 9 سال پیش
والد
کامیت
59fdc3c998

+ 1 - 1
examples/common/entry/entry_ios.mm

@@ -312,7 +312,7 @@ static	void* m_device = NULL;
 
 	[m_window makeKeyAndVisible];
 
-	//float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but ui is too small on ipad retina
+	//float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but needs to further pass the value to the `nvgBeginFrame()` call's `devicePixelRatio` parameter in `ExampleNanoVG` class' `update()` method so it can actually work properly.
 	float scaleFactor = 1.0f;
 	[m_view setContentScaleFactor: scaleFactor ];
 

+ 1 - 1
examples/common/nanovg/nanovg.cpp

@@ -339,7 +339,7 @@ void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float dev
 
 	nvg__setDevicePixelRatio(ctx, devicePixelRatio);
 
-	ctx->params.renderViewport(ctx->params.userPtr, windowWidth, windowHeight);
+	ctx->params.renderViewport(ctx->params.userPtr, windowWidth, windowHeight, devicePixelRatio);
 
 	ctx->drawCallCount = 0;
 	ctx->fillTriCount = 0;

+ 3 - 7
examples/common/nanovg/nanovg.h

@@ -19,6 +19,8 @@
 #ifndef NANOVG_H
 #define NANOVG_H
 
+#include "nanovg_bgfx.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -588,7 +590,7 @@ struct NVGparams {
 	int (*renderDeleteTexture)(void* uptr, int image);
 	int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
 	int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
-	void (*renderViewport)(void* uptr, int width, int height);
+	void (*renderViewport)(void* uptr, int width, int height, float devicePixelRatio);
 	void (*renderCancel)(void* uptr);
 	void (*renderFlush)(void* uptr);
 	void (*renderFill)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
@@ -598,12 +600,6 @@ struct NVGparams {
 };
 typedef struct NVGparams NVGparams;
 
-namespace bx { struct AllocatorI; }
-
-NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _allocator = NULL);
-void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId);
-void nvgDelete(struct NVGcontext* ctx);
-
 // Constructor and destructor, called by the render back-end.
 NVGcontext* nvgCreateInternal(NVGparams* params);
 void nvgDeleteInternal(NVGcontext* ctx);

+ 6 - 2
examples/common/nanovg/nanovg_bgfx.cpp

@@ -545,12 +545,12 @@ namespace
 		gl->th = handle;
 	}
 
-	static void nvgRenderViewport(void* _userPtr, int width, int height)
+	static void nvgRenderViewport(void* _userPtr, int width, int height, float devicePixelRatio)
 	{
 		struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
 		gl->view[0] = (float)width;
 		gl->view[1] = (float)height;
-		bgfx::setViewRect(gl->m_viewId, 0, 0, width, height);
+		bgfx::setViewRect(gl->m_viewId, 0, 0, width * devicePixelRatio, height * devicePixelRatio);
 	}
 
 	static void fan(uint32_t _start, uint32_t _count)
@@ -1088,6 +1088,10 @@ error:
 	return NULL;
 }
 
+NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId) {
+  return nvgCreate(edgeaa, _viewId, NULL);
+}
+
 void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId)
 {
 	struct NVGparams* params = nvgInternalParams(ctx);

+ 18 - 0
examples/common/nanovg/nanovg_bgfx.h

@@ -0,0 +1,18 @@
+/*
+ * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ */
+
+#ifndef NANOVG_BGFX_H_HEADER_GUARD
+#define NANOVG_BGFX_H_HEADER_GUARD
+
+namespace bx { struct AllocatorI; }
+
+struct NVGcontext;
+
+NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _allocator);
+NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId);
+void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId);
+void nvgDelete(struct NVGcontext* ctx);
+
+#endif // NANOVG_BGFX_H_HEADER_GUARD

+ 2 - 2
src/glcontext_eagl.mm

@@ -27,7 +27,7 @@ namespace bgfx { namespace gl
 		{
 			_layer.contentsScale = [UIScreen mainScreen].scale;
 
-			_layer.opaque = true;
+			_layer.opaque = [_layer.style valueForKey:@"opaque"] == nil ? true : [[_layer.style valueForKey:@"opaque"] boolValue];
 
 			_layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys
 											: [NSNumber numberWithBool:false]
@@ -158,7 +158,7 @@ namespace bgfx { namespace gl
 
 		BX_UNUSED(_width, _height);
 		CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh;
-		layer.opaque = true;
+		layer.opaque = [layer.style valueForKey:@"opaque"] == nil ? true : [[layer.style valueForKey:@"opaque"] boolValue];
 
 		layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys
 										: [NSNumber numberWithBool:false]