Procházet zdrojové kódy

Merge branch 'master' of cane:bkaradzic/bgfx

Branimir Karadžić před 10 roky
rodič
revize
8155b139f6

+ 16 - 4
examples/common/entry/input.cpp

@@ -89,10 +89,10 @@ struct Keyboard
 		return state;
 		return state;
 	}
 	}
 
 
-	static void decodeKeyState(uint32_t _state, uint8_t& _modifiers, bool& _down)
+	static bool decodeKeyState(uint32_t _state, uint8_t& _modifiers)
 	{
 	{
 		_modifiers = (_state>>16)&0xff;
 		_modifiers = (_state>>16)&0xff;
-		_down = 0 != ( (_state>>8)&0xff);
+		return 0 != ( (_state>> 8)&0xff);
 	}
 	}
 
 
 	void setKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
 	void setKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
@@ -101,6 +101,14 @@ struct Keyboard
 		m_once[_key] = false;
 		m_once[_key] = false;
 	}
 	}
 
 
+	bool getKeyState(entry::Key::Enum _key, uint8_t* _modifiers)
+	{
+		uint8_t modifiers;
+		_modifiers = NULL == _modifiers ? &modifiers : _modifiers;
+
+		return decodeKeyState(m_key[_key], *_modifiers);
+	}
+
 	void pushChar(uint8_t _len, const uint8_t _char[4])
 	void pushChar(uint8_t _len, const uint8_t _char[4])
 	{
 	{
 		for (uint32_t len = m_ring.reserve(4)
 		for (uint32_t len = m_ring.reserve(4)
@@ -196,8 +204,7 @@ struct Input
 		for (const InputBinding* binding = _bindings; binding->m_key != entry::Key::None; ++binding)
 		for (const InputBinding* binding = _bindings; binding->m_key != entry::Key::None; ++binding)
 		{
 		{
 			uint8_t modifiers;
 			uint8_t modifiers;
-			bool down;
-			Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers, down);
+			bool down =	Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers);
 
 
 			if (binding->m_flags == 1)
 			if (binding->m_flags == 1)
 			{
 			{
@@ -302,6 +309,11 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
 	s_input->m_keyboard.setKeyState(_key, _modifiers, _down);
 	s_input->m_keyboard.setKeyState(_key, _modifiers, _down);
 }
 }
 
 
+bool inputGetKeyState(entry::Key::Enum _key, uint8_t* _modifiers)
+{
+	return s_input->m_keyboard.getKeyState(_key, _modifiers);
+}
+
 void inputChar(uint8_t _len, const uint8_t _char[4])
 void inputChar(uint8_t _len, const uint8_t _char[4])
 {
 {
 	s_input->m_keyboard.pushChar(_len, _char);
 	s_input->m_keyboard.pushChar(_len, _char);

+ 3 - 0
examples/common/entry/input.h

@@ -39,6 +39,9 @@ void inputProcess();
 ///
 ///
 void inputSetKeyState(entry::Key::Enum  _key, uint8_t _modifiers, bool _down);
 void inputSetKeyState(entry::Key::Enum  _key, uint8_t _modifiers, bool _down);
 
 
+///
+bool inputGetKeyState(entry::Key::Enum _key, uint8_t* _modifiers = NULL);
+
 /// Adds single UTF-8 encoded character into input buffer.
 /// Adds single UTF-8 encoded character into input buffer.
 void inputChar(uint8_t _len, const uint8_t _char[4]);
 void inputChar(uint8_t _len, const uint8_t _char[4]);
 
 

+ 30 - 0
examples/common/imgui/ocornut_imgui.cpp

@@ -61,6 +61,11 @@ struct OcornutImguiContext
 			uint32_t vtx_offset = 0;
 			uint32_t vtx_offset = 0;
 			for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
 			for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
 			{
 			{
+				if (0 == pcmd->vtx_count)
+				{
+					continue;
+				}
+
 				bgfx::setState(0
 				bgfx::setState(0
 					| BGFX_STATE_RGB_WRITE
 					| BGFX_STATE_RGB_WRITE
 					| BGFX_STATE_ALPHA_WRITE
 					| BGFX_STATE_ALPHA_WRITE
@@ -105,6 +110,11 @@ struct OcornutImguiContext
 		io.IniFilename = NULL;
 		io.IniFilename = NULL;
 //		io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? -0.5f : 0.0f;
 //		io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? -0.5f : 0.0f;
 
 
+		for (uint32_t ii = 0; ii < ImGuiKey_COUNT; ++ii)
+		{
+			io.KeyMap[ii] = ImGuiKey_(ii);
+		}
+
 		const bgfx::Memory* vsmem;
 		const bgfx::Memory* vsmem;
 		const bgfx::Memory* fsmem;
 		const bgfx::Memory* fsmem;
 
 
@@ -182,6 +192,26 @@ struct OcornutImguiContext
 		io.MousePos = ImVec2((float)_mx, (float)_my);
 		io.MousePos = ImVec2((float)_mx, (float)_my);
 		io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
 		io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
 
 
+#if 0
+		io.KeysDown[ImGuiKey_Tab]        = inputGetKeyState(entry::Key::Tab);
+		io.KeysDown[ImGuiKey_LeftArrow]  = inputGetKeyState(entry::Key::Left);
+		io.KeysDown[ImGuiKey_RightArrow] = inputGetKeyState(entry::Key::Right);
+		io.KeysDown[ImGuiKey_UpArrow]    = inputGetKeyState(entry::Key::Up);
+		io.KeysDown[ImGuiKey_DownArrow]  = inputGetKeyState(entry::Key::Down);
+		io.KeysDown[ImGuiKey_Home]       = inputGetKeyState(entry::Key::Home);
+		io.KeysDown[ImGuiKey_End]        = inputGetKeyState(entry::Key::End);
+		io.KeysDown[ImGuiKey_Delete]     = inputGetKeyState(entry::Key::Delete);
+		io.KeysDown[ImGuiKey_Backspace]  = inputGetKeyState(entry::Key::Backspace);
+		io.KeysDown[ImGuiKey_Enter]      = inputGetKeyState(entry::Key::Return);
+		io.KeysDown[ImGuiKey_Escape]     = inputGetKeyState(entry::Key::Esc);
+		io.KeysDown[ImGuiKey_A]          = inputGetKeyState(entry::Key::KeyA);
+		io.KeysDown[ImGuiKey_C]          = inputGetKeyState(entry::Key::KeyC);
+		io.KeysDown[ImGuiKey_V]          = inputGetKeyState(entry::Key::KeyV);
+		io.KeysDown[ImGuiKey_X]          = inputGetKeyState(entry::Key::KeyX);
+		io.KeysDown[ImGuiKey_Y]          = inputGetKeyState(entry::Key::KeyY);
+		io.KeysDown[ImGuiKey_Z]          = inputGetKeyState(entry::Key::KeyZ);
+#endif // 0
+
 		ImGui::NewFrame();
 		ImGui::NewFrame();
 
 
 		//ImGui::ShowTestWindow(); //Debug only.
 		//ImGui::ShowTestWindow(); //Debug only.

+ 10 - 6
tools/geometryc/geometryc.cpp

@@ -510,8 +510,8 @@ int main(int _argc, const char* _argv[])
 				for (uint32_t edge = 0, numEdges = argc-1; edge < numEdges; ++edge)
 				for (uint32_t edge = 0, numEdges = argc-1; edge < numEdges; ++edge)
 				{
 				{
 					Index3 index;
 					Index3 index;
-					index.m_texcoord = 0;
-					index.m_normal = 0;
+					index.m_texcoord = -1;
+					index.m_normal = -1;
 					index.m_vertexIndex = -1;
 					index.m_vertexIndex = -1;
 
 
 					char* vertex = argv[edge+1];
 					char* vertex = argv[edge+1];
@@ -528,8 +528,12 @@ int main(int _argc, const char* _argv[])
 							index.m_normal = (nn < 0) ? nn+numNormals : nn-1;
 							index.m_normal = (nn < 0) ? nn+numNormals : nn-1;
 						}
 						}
 
 
-						const int tex = atoi(texcoord);
-						index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1;
+						// https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vertex_Normal_Indices_Without_Texture_Coordinate_Indices
+						if(*texcoord != '\0')
+						{
+							const int tex = atoi(texcoord);
+							index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1;
+						}
 					}
 					}
 
 
 					const int pos = atoi(vertex);
 					const int pos = atoi(vertex);
@@ -716,8 +720,8 @@ int main(int _argc, const char* _argv[])
 	bool hasTexcoord;
 	bool hasTexcoord;
 	{
 	{
 		Index3Map::const_iterator it = indexMap.begin();
 		Index3Map::const_iterator it = indexMap.begin();
-		hasNormal   = 0 != it->second.m_normal;
-		hasTexcoord = 0 != it->second.m_texcoord;
+		hasNormal   = -1 != it->second.m_normal;
+		hasTexcoord = -1 != it->second.m_texcoord;
 
 
 		if (!hasTexcoord
 		if (!hasTexcoord
 		&&  texcoords.size() == positions.size() )
 		&&  texcoords.size() == positions.size() )