Jump to content

Render hooks


Josh
 Share

Recommended Posts

@klepto2 @SpiderPig

I am adding rendering hooks into the engine that will be called in the rendering thread. The two hooks I have planned are:

 

  • HOOKID_COMPUTE - called once per render before drawing begins
  • HOOKID_DRAWCAMERA - called once per pass for each camera or shadow render

 

Hooks can be added to an object with this mechanism:

void Object::AddHook(const HookID id, void (*hook)(std::shared_ptr<Object> source, std::shared_ptr<Object> extra), std::shared_ptr<Object> extra = NULL);

They will pass an OpenGLRenderer object as the source argument of the function callback.

void CustomRenderHook(shared_ptr<Object> o, shared_ptr<Object> extra)
{
	auto renderer = o->As<OpenGLRenderer>();
	
	// Start drawing!
  
}

The structure contains this information. Is there anything else missing that you need?

struct OpenGLRenderer : public Object
{
	HGLRC context;
	GLuint framebuffer;
 	iVec4 viewport;
	std::array<GLuint, MAX_STORAGE_BUFFERS> storagebuffers;
	uint32_t cameraid;
	Mat4 cameramatrix;
	std::array<Mat4, 6> projectioncameramatrix;
	OpenGLRenderPass pass;
};

I am trying to stick with the raw OpenGL data and avoid use of the internal API classes as much as possible.

The pass value can be any of the following:

  • RENDERPASS_DEPTH
  • RENDERPASS_SOLID
  • RENDERPASS_SHADOW
  • RENDERPASS_TRANSPARENCY
  • RENDERPASS_REFRACTION

If the depth prepass is disabled, then the solid pass will indicate RENDERPASS_SOLID | RENDERPASS_DEPTH.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Very nice, thank you. Will take a closer look into this soon :)

I have 2 more requests:

  1. Maybe we need a HOOKID_COMPUTE_AT_START and a HOOKID_COMPUTE_AT_END
    1. This is because some computations may rely on data produced after the whole rendering is done.
  2. It would be nice to have also access to camera frustumn (if possible) 
    1. Some geometric code might need this (like my quadtree implemntation)
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

also it would be nice (if possible at all) to have a cancel option. This way it could be possible to have something like this:

 

void DepthOnlyRenderHook(shared_ptr<Object> o, shared_ptr<Object> extra)
{
	auto renderer = o->As<OpenGLRenderer>();
	auto camera = extra->As<Camera>();
  
  	//what is the cameraid actual?
  	if(camera->GetId() == renderer->cameraid && (pass & RENDERPASS_DEPTH) == 0)
    {
      // disable all other passes and just draw the depth pass
      // might be much cheaper for much scenarios where later computations are just dependend on the depth.
      renderer.cancel = true;
    }
}

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

7 hours ago, klepto2 said:
  • Maybe we need a HOOKID_COMPUTE_AT_START and a HOOKID_COMPUTE_AT_END
    1. This is because some computations may rely on data produced after the whole rendering is done.
  • It would be nice to have also access to camera frustumn (if possible) 
    1. Some geometric code might need this (like my quadtree implemntation)

Ah, okay, so like per-camera compute.

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...