Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by 0xnullptr

  1. 0xnullptr

    Index Buffer

    I believe the answer that you're looking for is in the glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); call. It refers to your vertex data size and data layout (vertices[]) that has been loaded into gpu buffer (&VB), which is bound as a vertex buffer. You also use an index data layout that refers to 6 indices (indices[]) loaded into a gpu buffer (&IB) which is bound as an index buffer. When execution gets to glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); The gpu will read the first index as an unsigned short value (0 index in your example) and use vertex 0 from the currently bound vertex buffer - which is made of 2 floats (specified in the glVertexAttribPointer call above). The gpu will work its way through the index buffer buffer until 6 indices are rendered (6 indices via the glDrawElements call). The size of each vertex has defined as 2 * gl_float from your glVertexAttribPointer call. The gpu will use that size and multiply it by the index value to get to the required vertex in the vertex buffer. ps. If the stride parameter in glVertexAttribPointer is anything other that 0 then that stride value (as opposed to the 2 * gl_float value) will used with the index value to find the next vertex in the vertex buffer.
  2. Hiya, I do as fleabay has already suggested. In my code the result of the input is handled in a different place due to supporting multiple OSs but I'm sure you'll get the gist of it. Here's some extracted code specific to Windows, plus the input handling code. void Poll() { MSG msg; BOOL ret = 0; while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE | PM_NOYIELD)) { if ((ret == -1) || (msg.message == WM_QUIT)) RTEX(nullptr); // This just throws an exception that's caught to shut the game system down cleanly TranslateMessage(&msg); DispatchMessage(&msg); } } int32_t keyCode(int32_t wp, int32_t lp) { switch (((lp >> 17) & 0x80) | ((lp >> 16) & 0x7f)) { case 42:return VK_LSHIFT; case 54:return VK_RSHIFT; case 29:return VK_LCONTROL; case 157:return VK_RCONTROL; case 56:return VK_LMENU; case 184:return VK_RMENU; } return wp; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { switch (uiMsg) { // [... other windows input messages are handled similarly - for eg mouse ...] case WM_KEYDOWN: if (!(wParam & 0xFF)) break; onKeyDown(keyCode(static_cast<int32_t>(wParam & 0xFFFFFFFF), static_cast<int32_t>(lParam & 0xFFFFFFFF))); break; case WM_KEYUP: if (!(wParam & 0xFF)) break; onKeyUp(keyCode(static_cast<int32_t>(wParam & 0xFFFFFFFF), static_cast<int32_t>(lParam & 0xFFFFFFFF))); break; default: break; } return DefWindowProc(hWnd, uiMsg, wParam, lParam); } Here's the 'key only' input handling code. I support KeyDown and KeyHit for 2 types of key feedback: bool _KeyDown[256]; bool _KeyHit[256]; // The user code calls these functions bool KeyDown(int32_t keycode) { Poll(); return _KeyDown[static_cast<int32_t>(keycode)]; } bool KeyUp(int32_t keycode) { Poll(); return !_KeyDown[static_cast<int32_t>(keycode)]; } bool KeyHit(int32_t keycode) { Poll(); bool keyhit = _KeyHit[static_cast<int32_t>(keycode)]; _KeyHit[keycode] = false; return keyhit; } void onKeyDown(int keycode) { if (!_KeyDown[keycode]) { _KeyDown[keycode] = true; _KeyHit[keycode] = true; } } void onKeyUp(int keycode) { _KeyDown[keycode] = false; } And an example of user code is as simple as: // The KEY_* values you see here are #defines specific to an OSs keybard values if (KeyHit(KEY_SPACE)) { // [... one time shot of a weapon for eg...] } // or if (KeyDown(KEY_W)) { // [... move forward code ...] } Hope it helps.
  3. 0xnullptr

    DX11 Shader Reflection Problem

    It also gives reason as to why you get an mask value of 15 as you have a float4 in your input struct. Have you tried changing it to float3 to see what happens? Have you looked to debug using PIX or RenderDoc? Awesome tools for these kinds of problems.
  4. 0xnullptr

    DX11 Shader Reflection Problem

    What does your vertex input struct look like in your vertex shader?
  5. 0xnullptr

    DX11 Shader Reflection Problem

    This is some code I made to create an input layout via reflection, you can use it it it fits your use case. EDIT: Although to be honest it looks as though we're doing pretty much the same thing. This works for me loading in models from output from a specific editor. DXGI_FORMAT ImplShaderReflector::InputLayoutRegisterToDXGIFormat(D3D_REGISTER_COMPONENT_TYPE type, BYTE mask) { if (type != D3D_REGISTER_COMPONENT_FLOAT32) return DXGI_FORMAT_UNKNOWN; switch (mask) { case 0b00000001: return DXGI_FORMAT_R32_FLOAT; case 0b00000011: return DXGI_FORMAT_R32G32_FLOAT; case 0b00000111: return DXGI_FORMAT_R32G32B32_FLOAT; case 0b00001111: return DXGI_FORMAT_R32G32B32A32_FLOAT; default: break; } return DXGI_FORMAT_UNKNOWN; } ID3D11InputLayout* ImplShaderReflector::CreateInputLayout(ID3D11Device* pDevice, ID3DBlob* pByteCode) { ID3D11ShaderReflection* pReflector = nullptr; if (FAILED(D3DReflect(pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), __uuidof(ID3D11ShaderReflection), (void**)&pReflector))) { OutputDebugString(L"Could not create reflector for vertex shader\n"); return nullptr; } D3D11_SHADER_DESC shaderDesc = {}; pReflector->GetDesc(&shaderDesc); std::vector<D3D11_INPUT_ELEMENT_DESC> inputDesc; inputDesc.resize(shaderDesc.InputParameters); for (UINT i = 0; i < shaderDesc.InputParameters; i++) { D3D11_SIGNATURE_PARAMETER_DESC sigDesc; pReflector->GetInputParameterDesc(i, &sigDesc); inputDesc[i].SemanticName = sigDesc.SemanticName; inputDesc[i].SemanticIndex = sigDesc.SemanticIndex; inputDesc[i].Format = InputLayoutRegisterToDXGIFormat(sigDesc.ComponentType, sigDesc.Mask); inputDesc[i].InputSlot = sigDesc.Stream; inputDesc[i].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; inputDesc[i].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; inputDesc[i].InstanceDataStepRate = 0; } ID3D11InputLayout* pInputLayout = nullptr; if (FAILED(pDevice->CreateInputLayout(inputDesc.data(), static_cast<UINT>(inputDesc.size()), pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), &pInputLayout))) { OutputDebugString(L"Could not create vertex shader input layout\n"); pReflector->Release(); return nullptr; } pReflector->Release(); return pInputLayout; }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!