Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


miggs

Member Since 28 Dec 2008
Offline Last Active Jun 29 2014 02:48 AM

Topics I've Started

multiple windows/instances and gl::GL_MAX_DRAW_BUFFERS

05 February 2013 - 08:14 PM

hi,

 

my current renderer uses a number of frame+renderbuffers and rendertextures at the moment. I wanted to implenent the possibility to render to multiple independent windows and got multiple OpenGL 3.0 contexts running and at first it worked, without render buffers on the other windows.

 

But when the second windows' scene got more complex and I added renderbuffers and framebuffers the problems began.

 

 

GLint maxBuffers;
gl::GetIntegerv(gl::GL_MAX_DRAW_BUFFERS, &maxBuffers);

returns 8, and the first window consumes 5-6. I tried starting my app.exe twice with only 1 window and both ran without any trouble (2 app.exe each 1 window), but when starting only 1 app.exe and having it spawn 2 windows with each a context, i get GL_INVALID_VALUE on gl::GenFramebuffers, which indicates to me that both contexts' buffer count add up.

 

 

How can i have my HGLRC's work indepentent like 2 separate apps, within one?

Thanks in advance


shadow buffer depth not reset properly

07 August 2012 - 02:53 PM

it seems as if glClear(GL_DEPTH_BUFFER_BIT); does not do it's job properly (probably due to some wrong setup on my side).

when i render the depth into a color attachment (the commented code instead of the uncommented code) using the gl_Position.z component in the fragment shader everything works fine, when my sun is moving and the shadow map is recalculated, it is correctly reset and redrawn and i have correct shadows.

here is the setup code:

  CheckGL(glGenFramebuffers(1, &m_Fbo));
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, m_Fbo));

  //glActiveTexture(GL_TEXTURE0);
  CheckGL(glGenTextures(1, &m_ShadowTexture));
  // depth
  CheckGL(glBindTexture(GL_TEXTURE_2D, m_ShadowTexture));
  CheckGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, sMapWidth, sMapHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0));
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
  CheckGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE));
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));//GL_CLAMP_TO_BORDER
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));//GL_CLAMP_TO_BORDER
  CheckGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_ShadowTexture, 0));
  //CheckGL(glBindTexture(GL_TEXTURE_2D, m_ShadowTexture));
  //CheckGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sMapWidth, sMapHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
  //CheckGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ShadowTexture, 0));
  // disable writing to the color buffer
  CheckGL(glDrawBuffer(GL_NONE));
  CheckGL(glReadBuffer(GL_NONE));
  CheckGL(glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ));
  CheckGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
  bool succeeded = OpenGLCheckFramebuffer(__FILE__, __LINE__);
  CheckGL(glBindTexture(GL_TEXTURE_2D, 0));
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));


and thats how i use them
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, m_Fbo));

  CheckGL(glDrawBuffer(GL_NONE));
  CheckGL(glReadBuffer(GL_NONE));

  // when using color attachment
  //CheckGL(glDrawBuffer(GL_COLOR_ATTACHMENT0));

  CheckGL(glViewport(0,0,sMapWidth, sMapHeight));
 
  CheckGL(glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ));
  CheckGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); // when using GL_DEPTH_BUFFER_BIT with depth_attachment, i only see black, while when clearing both color and depth i see the depth attachment without beeing cleared (screenshot attached)
  CheckGL(glColorMask(0,0,0,0)); // this is 1,1,1,1 if i use color_attachment
 
 
  // render scene...
 
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
  CheckGL(glColorMask(1,1,1,1));

here's how it looks like:
the top 2 images are using the depth attachment, i can't provide a video, but when the sun is moving, this is what happens (no depth clearing)
the bottom 2 images clear and render correctly

Posted Image

problems with position and depth range in fbo texture

22 July 2012 - 03:10 PM

hi

i have a fbo mrt setup that currently works for normals and color, and i tried to add the possibility to render the depth and position values, and it seems as if my shaders render correctly into the frame buffer (gDebugger screenshot), but when i try rendering them like i do with normals, i either get a white screen for the depth texture, or some red glitch for the positions.

for the depth texture, i'm guessing because of my nearZ and farZ values beeing 1 and 100000, the depth values range between 0.9992 and 0.995, but i don't know how i could transform them to get a decent rendered depth texture.

as for the positions, i'm clueless, maybe my formats are wrong?

the opengl context is 4.2.11733 Compatibility Profile Context

here is what gdebugger shows for the textures:

Posted Image

and this is the failed result for the positions (depth buffer result is a white screen, and positions is like the gdebugger output):

Posted Image



that is how i set up the fbo and textures:

bool KBuffer::Initialize(uint width, uint height)
{
  GLint maxBuffers;
  glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxBuffers);
  if(maxBuffers < 3)
   FCThrow("MRT max buffer < 3");

  m_Width = width;
  m_Height = height;
  m_Quad = MeshProvider::CreateTexturedScreenQuad();
  
  // generate buffers
  glGenFramebuffers(1, &m_Fbo));  
  glGenRenderbuffers(1, &m_DepthBuffer);
  glGenRenderbuffers(1, &m_ColorBuffer);
  glGenRenderbuffers(1, &m_PositionBuffer);
  glGenRenderbuffers(1, &m_NormalBuffer);

  glBindFramebuffer(GL_FRAMEBUFFER, m_Fbo);

  glBindRenderbufferEXT(GL_RENDERBUFFER, m_ColorBuffer);
  glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA, width, height);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_ColorBuffer);

  glBindRenderbufferEXT(GL_RENDERBUFFER, m_PositionBuffer);
  glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA32F, width, height);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, m_PositionBuffer);

  glBindRenderbufferEXT(GL_RENDERBUFFER, m_NormalBuffer);
  glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA16F, width, height);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, m_NormalBuffer);

  glBindRenderbufferEXT(GL_RENDERBUFFER, m_DepthBuffer);
  glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width, height);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_DepthBuffer);

  // create the textures
  glGenTextures(eGBufferTexture::_Count, m_Textures);
  
  // diffuse/color - 8 bit per channel
  glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Color]);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Color], 0);
  
  // position - HDR texture with 32 bit per channel
  glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Position]);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, 0);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Position], 0);

  // normal - 16 bit per channel
  glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Normal]);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, 0);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Normal], 0));

  // depth
  glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Depth]);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Depth], 0);

  bool succeeded = OpenGLCheckFramebuffer(__FILE__, __LINE__);

  glBindTexture(GL_TEXTURE_2D, 0);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  return succeeded;
}

// render completed scene position texture a quad:
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Position]); // Normals and Color draws correctly
  glUniform1i(colorSamplerParam, 0);
  m_Quad->Render();

// vertex shader
#version 330 core
precision highp float;
...
out block
{
vec2 TexCoord0;
} Out;
void main()
{
	gl_Position = u_mMVP * vec4(a_vPosition, 1.0);
	Out.TexCoord0 = a_vTexCoord0;
}
// fragment shader
uniform sampler2D u_sColor;
void main()
{
	FragColor = vec4(texture(u_sColor, In.TexCoord0).xyz, 1);
}




EDIT :

i thoght maybe somehow my quad is rendered wrong and tried with

glBindFramebuffer(GL_READ_FRAMEBUFFER, m_Fbo);
glReadBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, m_Width, m_Height, 0, 0, m_Width, m_Height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

but that yields the same wrong result

multiple shaders per model

22 March 2012 - 02:58 PM

hi
(i'm using opengl 4.0 but this question is rather theroetical so thats not important)

currently i have a structure, like this (simplified)
model{ // object on screen with a world matrix
  modelpart{ // a part of the model with a material, e.g. arm, leg, or pants, or window (if model is a house..)
	 mesh { vertBuffer, iBUffer... etc.. }
  }
}

when i render, i activate the models shader, a normal shader for example ( sometimes in renderlists a shader is even activated along multiple models)

my question is, what if i would like to have different shaders on each modelpart, how do you guys go on about that?
if for example the naked arm has a different shader than some fancy blink metal armor on the chest, or a part has normalmapping, and a part is parallax?

because at the moment the Model->Render() method sets a ModelViewMatrix for the active shader, and now each ModelPart would need a reference to the parent Model's ModelViewMatrix, and activate it's own shader and set the modelviewmatrix


is this situation even realistic or does a shader per model suffice in most cases? Or is it that extreme that instead of rendering Models, you have renderlists of modelparts with the same shader?

would it help to chang my model structure somehow?


thanks in advance

accessing c++ class members with luaplus

25 February 2011 - 07:24 AM

i've implemented LuaPlus in my engine eventmanager successfully and really like the flexibility i gained.

but i'm still not exactly where i want to by, because i can't link my c++ classes to a lua class.

for example i have a Actor class in c++, and i want to be able to create the same class in lua and gain access to members with luaplus, but i can't figure how i can achieve that.

Is this actually luaplus built in functionality, or do i have to write my own interface that exchanges data tables between c++ and lua?

my current approach would be to fire an event in luascript that creates an new actor class in c++ code, and transfer its id and the data i need to back to lua. when i modify the data i send the modifications back to c++ code again, but i actually thought there's something in luaplus that exposes this functionality already.


PARTNERS