Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glClearBuffer & glReadAttachmentPixel (updated) #1807

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

saurtron
Copy link
Collaborator

@saurtron saurtron commented Dec 9, 2024

Updated #935 (merged master and resolved some conflicts)

I think it should be fine but just in case I uploaded to a separate PR.

@saurtron saurtron changed the title Clear buffer read attachment pixel (updated) glClearBuffer & glReadAttachmentPixel (updated) Dec 9, 2024
@lhog
Copy link
Collaborator

lhog commented Dec 10, 2024

IDK about this one. Some parts of the PR are nice, the other ones like the ability to read the attachment pixel are very questionable.

@saurtron
Copy link
Collaborator Author

saurtron commented Dec 10, 2024

IDK about this one. Some parts of the PR are nice, the other ones like the ability to read the attachment pixel are very questionable.

Yeah I don't know about that, saw it was approved and updated it just in case. Anyways if glReadAttachmentPixel is more controversial this could be split in two.

Maybe @Krogoth100 has some use case for glReadAttachmentPixel that justifies it.

namespace Impl {
template<class Type>
static inline void ReadAttachmentPixel(lua_State* L, GLint x, GLint y, GLenum format, GLenum readType, int fSize) {
Type data[fSize];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could avoid VLA? As far as I understand fSize is never more than 4 anyway

Suggested change
Type data[fSize];
std::array <Type, 4> data;
assert(fSize <= data.size());

const GLint y = luaL_checkint(L, 3);

const auto activeLuaFBO = CLuaHandle::GetActiveFBOs(L).GetActiveReadFBO();
assert(activeLuaFBO);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is some fallback FBO always active, or will this trigger if I call it inside e.g. GameFrame or other non-drawing context?

case hashString("color14"): { attachment = GL_COLOR_ATTACHMENT14; } break;
case hashString("color15"): { attachment = GL_COLOR_ATTACHMENT15; } break;
case hashString("depth"): { attachment = GL_DEPTH_ATTACHMENT; } break;
default: assert(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't assert on user input

case hashString("color15"): { bufferType = GL_COLOR; attachment = GL_COLOR_ATTACHMENT15; drawBuffer = 15; } break;
case hashString("depth"): { bufferType = GL_DEPTH; attachment = GL_DEPTH_ATTACHMENT; drawBuffer = 0; } break;
case hashString("stencil"): { bufferType = GL_STENCIL; attachment = GL_STENCIL_ATTACHMENT; drawBuffer = 0; } break;
default: assert(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't assert on user input

Comment on lines +5182 to +5185
int LuaOpenGL::ReadAttachmentPixel(lua_State* L)
{
GLenum attachment;
switch(hashString(luaL_checkstring(L, 1))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no #ifndef HEADLESS?

}
}

int LuaOpenGL::ReadAttachmentPixel(lua_State* L)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation would be good. https://github.com/beyond-all-reason/spring/pull/935/files#r1281757982 says that this is rather for development (editor/debug) and can have low perf, which are important caveats

@saurtron saurtron added the enhancement New feature or request label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants