Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


lephyrius

Member Since 20 Apr 2003
Offline Last Active Dec 02 2014 06:47 AM

Topics I've Started

Algorithm for covering as much dots a as possible?

14 September 2014 - 10:24 AM

If I have a rectangle of random size and it has random dots in it.( = Rectangle A)

I want to take a rectangle that's inside A to cover as many dots as possible.

 

Is there any possible way of doing this without going bruteforce: iterating through all the dots and use them as a corner of the rectangle only saving the one with most dots in it?


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);


PARTNERS