Git Product home page Git Product logo

Comments (9)

soufianekhiat avatar soufianekhiat commented on July 16, 2024 1

Yes indeed It need extra for to add more data etc.
https://github.com/soufianekhiat/ImPlatform/blob/main/ImPlatform/ImPlatform.cpp#L1173
If I need another Vertex Format I'll need to create my own data struct for draw call, and by pass the ImDrawList pass.
image
Interpretation of that available on ImPlatform:
https://github.com/soufianekhiat/ImPlatform/blob/main/ImPlatformDemo/main.cpp#L106
https://github.com/soufianekhiat/ImPlatform/blob/main/ImPlatformDemo/main.cpp#L201
https://github.com/soufianekhiat/ImPlatform/blob/main/ImPlatformDemo/main.cpp#L201
Hidden under 'IM_SUPPORT_CUSTOM_SHADER' while I don't support "enough" backend.

from imgui.

ocornut avatar ocornut commented on July 16, 2024

This code is not working, and produce a gpu hang.

I'm not sure how we can help, it's seems likely a problem with your use of DX11.

It will be a simpler (no brainer) to have a trivial pixel shader with 4 vertices instead.

It doesn't seem simpler to me IMHO because you are going to need lots of shader variants.
But maybe you can find a way to let dear imgui generate the mesh and only act on the shader.

from imgui.

soufianekhiat avatar soufianekhiat commented on July 16, 2024

I'm not sure how we can help, it's seems likely a problem with your use of DX11.

If it's dx11 problem I can work on it. I never saw a proper usage of draw callback I'm not sure of the proper use.

It doesn't seem simpler to me IMHO because you are going to need lots of shader variants.
But maybe you can find a way to let dear imgui generate the mesh and only act on the shader.

True! More shader variant, but traded for more flexibility, for a simple linear gradient I need lot of vertices (based on where the gradient start end).
What do you mean by the last sentence?
Current I had to tesselate the geometry
https://github.com/soufianekhiat/DearWidgets/blob/rework/src/api/dear_widgets.cpp#L2078
From a simple geometry:
https://github.com/soufianekhiat/DearWidgets/blob/rework/src/api/dear_widgets.cpp#L2355
To have a sense of a simple linear gradient:
https://github.com/soufianekhiat/DearWidgets/blob/rework/src/api/dear_widgets.cpp#L2439

from imgui.

soufianekhiat avatar soufianekhiat commented on July 16, 2024

Here an illustration of the problem:

from imgui.

ocornut avatar ocornut commented on July 16, 2024

You should probably use RenderDoc or another gpu debugger to understand why your code is crashing.

What do you mean by the last sentence?

DrawQuadWithCustomShader output a simple quad which can already be output by ImDrawList, so maybe you can simply your callback logic to set shader + some uniforms for your shader, and not attempt to create/bind buffers.

AddCallback(bind your shader and data)
AddRectFilled()
AddCallback(ImDrawCallback_ResetRenderState)

from imgui.

soufianekhiat avatar soufianekhiat commented on July 16, 2024

[Fixed]

ImGui::Begin( "Custom Shader" );
	ImDrawList* draw = ImGui::GetWindowDrawList();
	ImVec2 cur = ImGui::GetCursorScreenPos();
	draw->AddCallback( &DrawCustomShaderQuad, &shader );
	ImRect bb( cur, cur + ImGui::GetContentRegionAvail() );
	draw->AddImageQuad( img, bb.GetBL(), bb.GetBR(), bb.GetTR(), bb.GetTL(), ImVec2( 0, 0 ), ImVec2( 1, 0 ), ImVec2( 1, 1 ), ImVec2( 0, 1 ), IM_COL32_WHITE );
	draw->AddCallback( ImDrawCallback_ResetRenderState, NULL );
ImGui::End();

Your second recommendation is much simple, it simplify the memory management etc. And rely on unique Vertex Buffer.

void DrawCustomShaderQuad( const ImDrawList* parent_list, const ImDrawCmd* cmd )
{
	ImPlatform::ImShader* shaders = ( ImPlatform::ImShader* )cmd->UserCallbackData;
	ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
	ID3D11DeviceContext* ctx = bd->pd3dDeviceContext;
	ctx->PSSetShader( ( ID3D11PixelShader* )( shaders->ps ), nullptr, 0 );
}

from imgui.

ocornut avatar ocornut commented on July 16, 2024

I guess you’ll need to pass some extra data to your shader but that’s the general idea yes (as long as the vertex format used by ImDrawList is sufficient for you).

from imgui.

soufianekhiat avatar soufianekhiat commented on July 16, 2024

Sidenote to have it portable for GLSL and GLSL I prefix all shaders with:
https://github.com/soufianekhiat/ImPlatform/blob/main/ImPlatform/ImPlatform.cpp#L1016

from imgui.

ocornut avatar ocornut commented on July 16, 2024

Good to hear. Do you need anything else on my end or can we close this?

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.