Daniele Bartolini 10 лет назад
Родитель
Сommit
5808ffbfd9

+ 1 - 1
src/main/main_android.cpp

@@ -17,7 +17,7 @@
 #include <jni.h>
 #include <android/sensor.h>
 #include <android_native_app_glue.h>
-#include <bgfxplatform.h>
+#include <bgfx/bgfxplatform.h>
 
 extern "C"
 {

+ 2 - 2
src/main/main_linux.cpp

@@ -15,13 +15,13 @@
 #include "bundle_compiler.h"
 #include "console_server.h"
 #include "device.h"
+#include <stdlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
 #include <X11/XKBlib.h>
 #include <X11/extensions/Xrandr.h>
-#include <bgfxplatform.h>
-#include <bgfx.h>
+#include <bgfx/bgfxplatform.h>
 
 namespace crown
 {

+ 1 - 1
src/main/main_windows.cpp

@@ -13,7 +13,7 @@
 #include "console_server.h"
 #include "bundle_compiler.h"
 #include "device.h"
-#include <bgfxplatform.h>
+#include <bgfx/bgfxplatform.h>
 #include <winsock2.h>
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN

+ 31 - 34
src/renderers/debug_line.cpp

@@ -9,7 +9,7 @@
 #include "vector3.h"
 #include "matrix4x4.h"
 #include <string.h> // memcpy
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {
@@ -17,39 +17,39 @@ namespace crown
 namespace debug_line
 {
 #if CROWN_PLATFORM_LINUX || CROWN_PLATFORM_ANDROID
-	static const uint8_t vs_h[335] =
+	static const uint8_t vs_h[325] =
 	{
-		0x56, 0x53, 0x48, 0x03, 0x1c, 0xf0, 0xa8, 0xc9, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH........u_mod
-		0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x09, 0x01, 0x00, 0x00, 0x01, 0x00, // elViewProj......
-		0x2a, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x6d, 0x65, // *...attribute me
-		0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, // diump vec4 a_col
-		0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x6d, // or0;.attribute m
-		0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, // ediump vec3 a_po
-		0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, // sition;.varying
-		0x6d, 0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, // mediump vec4 v_c
-		0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6d, // olor0;.uniform m
-		0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, // ediump mat4 u_mo
-		0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // delViewProj;.voi
-		0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x6d, 0x65, // d main ().{.  me
-		0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // diump vec4 tmpva
-		0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, // r_1;.  tmpvar_1.
-		0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // w = 1.0;.  tmpva
-		0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, // r_1.xyz = a_posi
-		0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, // tion;.  gl_Posit
-		0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, // ion = (u_modelVi
-		0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // ewProj * tmpvar_
-		0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, // 1);.  v_color0 =
-		0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00,       //  a_color0;.}...
+		0x56, 0x53, 0x48, 0x04, 0xa4, 0x8b, 0xef, 0x49, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH....I...u_mod
+		0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, // elViewProj......
+		0x20, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, //  ...attribute hi
+		0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // ghp vec4 a_color
+		0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, // 0;.attribute hig
+		0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // hp vec3 a_positi
+		0x6f, 0x6e, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, // on;.varying high
+		0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, // p vec4 v_color0;
+		0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x6d, // .uniform highp m
+		0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, // at4 u_modelViewP
+		0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, // roj;.void main (
+		0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, // ).{.  highp vec4
+		0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, //  tmpvar_1;.  tmp
+		0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, // var_1.w = 1.0;.
+		0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, //  tmpvar_1.xyz =
+		0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, // a_position;.  gl
+		0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, // _Position = (u_m
+		0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, // odelViewProj * t
+		0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, // mpvar_1);.  v_co
+		0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, // lor0 = a_color0;
+		0x0a, 0x7d, 0x0a, 0x0a, 0x00,                                                                   // .}...
 	};
 
-	static const uint8_t fs_h[91] =
+	static const uint8_t fs_h[89] =
 	{
-		0x46, 0x53, 0x48, 0x03, 0x1c, 0xf0, 0xa8, 0xc9, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x76, 0x61, // FSH.......L...va
-		0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x76, 0x65, // rying mediump ve
-		0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // c4 v_color0;.voi
-		0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, // d main ().{.  gl
-		0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x5f, 0x63, // _FragColor = v_c
-		0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00,                               // olor0;.}...
+		0x46, 0x53, 0x48, 0x04, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x76, 0x61, // FSH....I..J...va
+		0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, // rying highp vec4
+		0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, //  v_color0;.void
+		0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, // main ().{.  gl_F
+		0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, // ragColor = v_col
+		0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00,                                           // or0;.}...
 	};
 #elif CROWN_PLATFORM_WINDOWS
 	static const uint8_t vs_h[419] =
@@ -255,17 +255,14 @@ void DebugLine::submit()
 
 	bgfx::TransientVertexBuffer tvb;
 	bgfx::allocTransientVertexBuffer(&tvb, _num * 2, debug_line::s_decl);
-
 	memcpy(tvb.data, _lines, sizeof(Line) * _num);
 
 	bgfx::setState(BGFX_STATE_PT_LINES
 		| BGFX_STATE_RGB_WRITE
 		| (_depth_test ? (BGFX_STATE_DEPTH_TEST_LESS | BGFX_STATE_DEPTH_WRITE) : 0)
 		| BGFX_STATE_CULL_CW);
-
-	bgfx::setProgram(debug_line::s_prog);
 	bgfx::setVertexBuffer(&tvb, 0, _num * 2);
-	bgfx::submit(0);
+	bgfx::submit(0, debug_line::s_prog);
 }
 
 } // namespace crown

+ 3 - 8
src/renderers/gui.cpp

@@ -11,7 +11,7 @@
 #include "vector2.h"
 #include "vector3.h"
 #include "matrix4x4.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {
@@ -145,13 +145,12 @@ void Gui::draw_rectangle(const Vector3& pos, const Vector2& size, const Color4&
 	inds[4] = 2;
 	inds[5] = 3;
 
-	material_manager::get()->lookup_material(m_material)->bind();
 	bgfx::setViewTransform(1, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(m_projection));
 	bgfx::setViewRect(1, 0, 0, m_width, m_height);
 	bgfx::setState(BGFX_STATE_DEFAULT);
 	bgfx::setVertexBuffer(&tvb);
 	bgfx::setIndexBuffer(&tib);
-	bgfx::submit(1, (int32_t) pos.z);
+	material_manager::get()->lookup_material(m_material)->bind();
 }
 
 void Gui::draw_image(const char* material, const Vector3& pos, const Vector2& size, const Color4& color)
@@ -195,16 +194,12 @@ void Gui::draw_image_uv(const char* material, const Vector3& pos, const Vector2&
 	inds[4] = 2;
 	inds[5] = 3;
 
-/*	ResourceId res_id("material", material);
-	Material* mat = material_manager::get()->lookup_material(res_id.name);
-	mat->bind();*/
-
 	bgfx::setViewTransform(1, to_float_ptr(MATRIX4X4_IDENTITY), to_float_ptr(m_projection));
 	bgfx::setViewRect(1, 0, 0, m_width, m_height);
 	bgfx::setState(BGFX_STATE_DEFAULT);
 	bgfx::setVertexBuffer(&tvb);
 	bgfx::setIndexBuffer(&tib);
-	bgfx::submit(1, (int32_t) pos.z);
+	material_manager::get()->lookup_material(m_material)->bind();
 }
 
 void Gui::draw_text(const char* str, const char* font, uint32_t font_size, const Vector3& pos, const Color4& color)

+ 1 - 1
src/renderers/gui.h

@@ -9,7 +9,7 @@
 #include "color4.h"
 #include "render_world_types.h"
 #include "material.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 4 - 4
src/renderers/material.cpp

@@ -12,7 +12,7 @@
 #include "material_manager.h"
 #include "shader.h"
 #include <string.h> // memcpy
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {
@@ -36,9 +36,6 @@ void Material::destroy() const
 
 void Material::bind() const
 {
-	Shader* shader = (Shader*) device()->resource_manager()->get(SHADER_TYPE, material_resource::shader(resource));
-	bgfx::setProgram(shader->program);
-
 	// Set samplers
 	for (uint32_t i = 0; i < num_textures(resource); i++)
 	{
@@ -64,6 +61,9 @@ void Material::bind() const
 		buh.idx = uh->uniform_handle;
 		bgfx::setUniform(buh, (char*) uh + sizeof(uh->uniform_handle));
 	}
+
+	Shader* shader = (Shader*) device()->resource_manager()->get(SHADER_TYPE, material_resource::shader(resource));
+	bgfx::submit(0, shader->program);
 }
 
 void Material::set_float(const char* name, float val)

+ 1 - 1
src/renderers/material.h

@@ -7,7 +7,7 @@
 
 #include "math_types.h"
 #include "resource_types.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 1 - 1
src/renderers/material_manager.h

@@ -11,7 +11,7 @@
 #include "resource_manager.h"
 #include "resource_types.h"
 #include "id_table.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 2 - 2
src/renderers/render_world.cpp

@@ -14,7 +14,7 @@
 #include "gui.h"
 #include "mesh_resource.h"
 #include "scene_graph.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {
@@ -80,7 +80,7 @@ void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uin
 
 	// This dummy draw call is here to make sure that view 0 is cleared
 	// if no other draw calls are submitted to view 0.
-	bgfx::submit(0);
+	bgfx::touch(0);
 
 	// Draw all sprites
 	for (uint32_t s = 0; s < id_array::size(m_sprite); s++)

+ 1 - 1
src/renderers/shader.h

@@ -11,7 +11,7 @@
 #include "memory_types.h"
 #include "compiler_types.h"
 #include "string_id.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 3 - 4
src/renderers/sprite.cpp

@@ -45,9 +45,6 @@ void Sprite::set_depth(int32_t z)
 
 void Sprite::render()
 {
-	if (m_material.id != INVALID_ID)
-		material_manager::get()->lookup_material(m_material)->bind();
-
 	bgfx::setState(BGFX_STATE_RGB_WRITE
 		| BGFX_STATE_ALPHA_WRITE
 		| BGFX_STATE_DEPTH_TEST_LEQUAL
@@ -59,7 +56,9 @@ void Sprite::render()
 	bgfx::setIndexBuffer(m_resource->ib, m_frame * 6, 6);
 	TransformInstance ti = m_scene_graph.get(_unit_id);
 	bgfx::setTransform(to_float_ptr(m_scene_graph.world_pose(ti)));
-	bgfx::submit(0, _depth);
+
+	if (m_material.id != INVALID_ID)
+		material_manager::get()->lookup_material(m_material)->bind();
 }
 
 } // namespace crown

+ 1 - 1
src/renderers/sprite.h

@@ -12,7 +12,7 @@
 #include "sprite_resource.h"
 #include "material.h"
 #include "world_types.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 3 - 3
src/resource/material_resource.cpp

@@ -13,7 +13,7 @@
 #include "resource_manager.h"
 #include "vector.h"
 #include "compile_options.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {
@@ -219,14 +219,14 @@ namespace material_resource
 		{
 			TextureData* td = get_texture_data(mr, i);
 			TextureHandle* th = get_texture_handle(mr, i, base);
-			th->sampler_handle = bgfx::createUniform(get_texture_name(mr, td), bgfx::UniformType::Uniform1iv).idx;
+			th->sampler_handle = bgfx::createUniform(get_texture_name(mr, td), bgfx::UniformType::Int1).idx;
 		}
 
 		for (uint32_t i = 0; i < num_uniforms(mr); i++)
 		{
 			UniformData* ud = get_uniform_data(mr, i);
 			UniformHandle* uh = get_uniform_handle(mr, i, base);
-			uh->uniform_handle = bgfx::createUniform(get_uniform_name(mr, ud), bgfx::UniformType::Uniform4fv).idx;
+			uh->uniform_handle = bgfx::createUniform(get_uniform_name(mr, ud), bgfx::UniformType::Vec4).idx;
 		}
 	}
 

+ 1 - 1
src/resource/mesh_resource.h

@@ -9,7 +9,7 @@
 #include "resource_types.h"
 #include "filesystem_types.h"
 #include "compiler_types.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 1 - 1
src/resource/sprite_resource.h

@@ -11,7 +11,7 @@
 #include "filesystem_types.h"
 #include "compiler_types.h"
 #include "string_id.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 1 - 1
src/resource/texture_resource.h

@@ -10,7 +10,7 @@
 #include "filesystem_types.h"
 #include "memory_types.h"
 #include "compiler_types.h"
-#include <bgfx.h>
+#include <bgfx/bgfx.h>
 
 namespace crown
 {

+ 1 - 1
third/bgfx

@@ -1 +1 @@
-Subproject commit b2da0cce93b7b8be781adae132ebf0876d1d6b88
+Subproject commit 488ebe2e1e49230e6ad5c8449ab36de8ff2f0075

+ 1 - 1
third/bx

@@ -1 +1 @@
-Subproject commit db24c20381e3d08525aad48e4d6447981c1a673f
+Subproject commit 4c58d0ac0ebaa289afe88995d7e08c92d67b99d4