Page 1 of 1

custom geometry in DX10/11

Posted: Sun Oct 27, 2013 22:19
by KN4CK3R
Hi,

I was playing around with custom geometry in the CEGUI Sample App and found a problem:
I added this code inside RenderSingleFrame (CEGuiBaseApplication.cpp).

Code: Select all

gui_renderer->beginRendering();

d_sampleApp->renderGUIContexts();

static auto *buffer = &gui_renderer->createGeometryBuffer();
static bool once = true;
if (once)
{
   once = false;

   using namespace CEGUI;

   const Rectf scrn(d_renderer->getDefaultRenderTarget().getArea());
   buffer->setClippingRegion(scrn);

   int x = 50, y = 50;
   
   Vertex vertices[6];
   #define init(i, v, t, c) vertices[i].position = v; vertices[i].tex_coords = t; vertices[i].colour_val = c;
   init(0,Vector3f(x, y, 0.0f), Vector2f(0, 0), Colour(0xFFFFFFFF))
   init(1,Vector3f(x + 100, y, 0.0f), Vector2f(0, 0), Colour(0xFFFFFFFF))
   init(2,Vector3f(x, y + 100, 0.0f), Vector2f(0, 0), Colour(0xFFFFFFFF))
   init(3,Vector3f(x + 100, y + 100, 0.0f), Vector2f(0, 0), Colour(0xFFFFFFFF))
   init(4,Vector3f(x, y + 100, 0.0f), Vector2f(0, 0), Colour(0xFFFFFFFF))
   init(5,Vector3f(x + 100, y, 0.0f), Vector2f(0, 0), Colour(0xFFFFFFFF))

   buffer->appendGeometry(vertices, 6);

   auto fnt = System::getSingleton().getDefaultGUIContext().getDefaultFont();
   if (fnt)
   {
      fnt->drawText(*buffer, "test", Vector2f(10, 10), nullptr, Colour(0xFFFFFFFF));
   }
}

buffer->draw();

gui_renderer->endRendering();


This will draw "test" and a white rectangle. It works fine in DX9 and OpenGL but not in DX10/11. Only the text is drawn there. I think it is because the text uses a texture while the rectangle doesn't.
Did I miss something? How can I draw the rectangle in DX10/11 too?

Re: custom geometry in DX10/11

Posted: Mon Oct 28, 2013 16:04
by KN4CK3R
I fixed it.
I think it is because the text uses a texture while the rectangle doesn't.

This was true, so I rewrote some parts of the shader.

Shader:

Code: Select all

[...]

Texture2D BoundTexture;
bool useShaderTexture;

[...]

float4 PSMain(PSSceneIn input) : SV_Target
{
   float4 colour;
   if (useShaderTexture)
      colour = BoundTexture.Sample(LinearSampler, input.tex) * input.colour;
   else
      colour = input.colour;
   return colour;
}

[...]


Renderer:

Code: Select all

//in Direct3D10Renderer::Direct3D10Renderer(ID3D10Device* device)
useShaderTextureVariable = effect->GetVariableByName("useShaderTexture")->AsScalar();

//in Direct3D10Renderer::setCurrentTextureShaderResource(ID3D10ShaderResourceView* srv)
d_boundTextureVariable->SetResource(srv);
useShaderTextureVariable->SetBool(srv != nullptr);


I haven't tested it for DX11 but it must be the same problem. ;)

Re: custom geometry in DX10/11

Posted: Thu Nov 07, 2013 10:55
by Kulik
Interesting, it looks like we definitely want this fixed.

Could you provide a pull request / patch for both DX10 and 11? I don't have Windows so it's hard for me to test this fix.

Re: custom geometry in DX10/11

Posted: Mon Nov 11, 2013 21:41
by Ident
this does not seem like a correct solution to me, and if/else in fragment shaders are kind of nasty. Can you explain exactly what you are trying to achieve? you want to render a rectanlge with CEGUI if i got that right? Is everything i nthe samples working for you though?