Jump to content

  • Log In with Google      Sign In   
  • Create Account


lephyrius

Member Since 20 Apr 2003
Offline Last Active Mar 22 2014 11:19 AM
-----

Topics I've Started

Render queue ids/design?

04 November 2013 - 05:13 AM

I've deciding that I want a render queue!  

I have decided 2 things:

1. Not submitting a new queue on each frame.(seems like it creates a lot of memory fragmentation). I will have to have some reference to the scenegraph then. Is this a bad thing?

2. Have separate queues to "opaque 3D", "transparent 3D" and "2D". Because they have a bit different sorting order.

Im using OpenGL in my example but I feel that this could apply to any other API as well.

So the ID is 64-bit you need to sort after.

The parameters are in the priority order for the opaque 3D queue:
1. Shader id
2. Material id(probably an UBO or a combination of texture id)
3. VBO id
4. IBO id

Now how do I combine the ids into one 64 bit integer?
Something like this?

uint64_t queue_id = ((shader_id % USHRT_MAX) << 48) | ((material_id % USHRT_MAX) << 32) | ((vbo_id % USHRT_MAX) << 16) | ibo_id % USHRT_MAX

Is there some other way of compacting the 32-bits numbers into 16-bit?

Or should I maybe create more of a wrapper around the GL ids?
So the shader permutation class:

class Shader {
public:
uint16_t id;
GLuint shader_id;
};


And have a manager(factory) that takes care of assigning ids that is compact.
 

class ShaderManager {
  public:
 
  Shader& get(const char* filename);  // The shader configuration file.
 
  std::map<std::string, uint16_t> loaded_shaders;
  std::vector<uint16_t> free_ids;
  std::vector<Shader> shaders;
};

Hmmm..
This solution is probably a bit more compact and robust.

Hmmm...
I don't think I ever will have 65535 different shaders, materials, vbos or ibos at least not at the same time. Then I could use uint8 and add z order also.

Maybe I should have different kind of queues so that:
 

class ShaderCommand {
public:
  GLuint shader_id;
 
  std::vector<MaterialQueue> texture_queue;
};

class ShaderQueue { // The root of the tree.
public:
  ShaderCommand& add();
  void remove(ShaderCommand& command);
  void render();
std::vector<ShaderCommand> commands;

};
// This is just an example of the render function.
void ShaderQueue::render() {
  // Sort the commands based on shader_id.(skipped)
  GLuint current_shader_id = 0;
  for (ShaderCommand& command : commands  ) {
    glUseProgram(command.shader_id);     // Apply the shader!
    for (TextureQueue& queue : command.texture_queue  ) {
      queue.render();
    }
  }
}
class MaterialCommand {
public:
  size_t material_id;
  GLuint textures[4];  // Probably will be ubo:s but I use textures for now for simplicity.  
 
  std::vector<MaterialQueue> texture_queue;
};

class MaterialQueue { 
public:
  MaterialCommand& add();
  void remove(MaterialCommand& command);
  void render();
std::vector<MaterialCommand> commands;

};

The problem is that I feel that with this approach is that it probably creates more memory fragmentation(+ maybe some cache) and it's harder to change materials on things(I wonder how often that needs to be done). But this will be more of a bucket approach. Also another problem is that this needs a lot copying when I sort unless I use pointers for storing the command. Another problem I see is that like for instance a mesh node in the scene graph will need to have: ShaderCommand, MaterialCommand, VBOCommand and IBOCommand references in their nodes so they could change the Material, Shaders and VBO:s/IBO:s.
At least it will solve the generating of the ids.

Am I overthinking this now?
Is there something I have totally missed? Or I need to have/think about?


Scripting garbage collection and destructor

15 October 2013 - 01:18 AM

I've been thinking of using Squirrel as a scripting language.

My idea was to use the garbage collector as a memory manager:(squirrel as an example script)

class Model
{	
	constructor(filename)
	{
		model_id = load_model(filename);
	}

       destructor() 
       {
                unload_model(model_id);
       }
       								
	model_id = null;
}

Something like this.(load_model and unload_model is native functions that are really easy to bind no need to worry about binding complicated classes)

It's obvious that this isn't going to work. Because Squirrel is missing the destructor.

Am I thinking of something wrong?

Is there a reason why Squirrel doesn't have a destructor?

Am I just using scripting in a wrong way?

Are there any alternatives to Squirrel that is similar to it but with a destructor?

Should I rethink the problem with binding to the native functions?


GLExpert and GLee error?

29 October 2010 - 01:55 AM

I'm using GLee for GL 2.0 support. Thats not a problem.
But now I investigate a bug so I need NVidia GLExpert for debugging. What include order do I need for the "nvapi.h" and "Glee.h"?
I only get these errors:
1>graphicssubsystem.cpp(239): error C3861: 'glDrawBuffers': identifier not found
1>graphicssubsystem.cpp(257): error C3861: 'glGenBuffers': identifier not found
1>graphicssubsystem.cpp(258): error C3861: 'glBindBuffer': identifier not found
1>graphicssubsystem.cpp(265): error C3861: 'glBufferData': identifier not found
1>graphicssubsystem.cpp(277): error C3861: 'glDrawBuffers': identifier not found
1>graphicssubsystem.cpp(406): error C3861: 'glBlendEquation': identifier not found
1>graphicssubsystem.cpp(468): error C3861: 'glBindBuffer': identifier not found
1>graphicssubsystem.cpp(494): error C3861: 'glBindBuffer': identifier not found

In any order I include them.

OpenGL/FBO/Cg blend error

26 May 2010 - 05:15 AM

OpenGL blend error! As you can see there is a black border around the letters. I want it to blend to transparent. I think the alpha in the shader works otherwise ALPHA_TEST doesn't work. This is how I render the FBO:
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);
	glDepthFunc(GL_LEQUAL);	
	glAlphaFunc(GL_GEQUAL,0.01f);
	glShadeModel(GL_SMOOTH);
	glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
	glBlendEquation ( GL_FUNC_ADD ) ;

	cgGLEnableProfile(cgVertexProfile);
	cgGLEnableProfile(cgFragmentProfile);

// Render as normal.

Here is how I setup the FBO:
	sceneTexture = new Texture();
	glBindTexture(GL_TEXTURE_2D,sceneTexture->getTextureId());
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glGenRenderbuffers(1, &depthBuffer);
	glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sceneTexture->getTextureId(), 0);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, bloomTexture->getTextureId(), 0);
	GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
	glDrawBuffers(2, buffers);


Boost phoenix find_if?

12 May 2010 - 02:43 AM

I am trying to learn boost phoenix. Here I am trying to find the test object based on their name using a property. This is a small test case:
#include <boost/spirit/home/phoenix/algorithm.hpp>
#include <boost/spirit/home/phoenix/stl/algorithm/querying.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/home/phoenix/bind/bind_member_function.hpp>
#include <vector>

class Test
{
public:
	Test(const std::string& _name = "");
	const std::string& Name() const;
	void Name(const std::string& _name);
protected:
private:
	std::string name;
};

Test::Test(const std::string& _name) : name(_name) {

}

const std::string& Test::Name() const {
	return name;
}

void Test::Name(const std::string& _name) {
	name = _name;
}

typedef std::vector<Test> ChildVector;
void fetch() {
	std::string name = "bob";
	ChildVector children;
        // Here comes the evil error code
	ChildVector::iterator it = std::find_if( children.begin(), children.end(),((Test&)(boost::phoenix::arg_names::_1)).Name()  == name);
}

I get lots of error. I am using Visual Studio 2010.

PARTNERS