Live renderings is now working.
parent
2597a160f8
commit
7b379f722d
Binary file not shown.
|
@ -48,3 +48,27 @@
|
|||
2 979 1666934238694879112 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
1 1916 1666934239630907257 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||
1916 1979 1666934239694909183 Step_3 8e1012bfab9235e9
|
||||
2 1132 1666973684372901616 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
1 1928 1666973685168926327 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
|
||||
1 4712 1666973687953012743 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
||||
4712 4813 1666973688053015848 Step_3 8e1012bfab9235e9
|
||||
1 972 1666973802264549771 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
972 1039 1666973802332551868 Step_3 8e1012bfab9235e9
|
||||
1 957 1666973853034114376 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
957 1024 1666973853098116348 Step_3 8e1012bfab9235e9
|
||||
1 957 1666974027615470803 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
957 1026 1666974027683472884 Step_3 8e1012bfab9235e9
|
||||
1 958 1666974062028522979 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
958 1026 1666974062096525059 Step_3 8e1012bfab9235e9
|
||||
1 971 1666974109329967557 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
|
||||
971 1037 1666974109393969509 Step_3 8e1012bfab9235e9
|
||||
1 4589 1666974300435787409 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
||||
4589 4657 1666974300503789473 Step_3 8e1012bfab9235e9
|
||||
1 4563 1666974526658651253 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
||||
4563 4626 1666974526722653192 Step_3 8e1012bfab9235e9
|
||||
1 4557 1666974781086349492 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
||||
4557 4626 1666974781154351547 Step_3 8e1012bfab9235e9
|
||||
1 5008 1666974850596449938 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
||||
5008 5075 1666974850664451993 Step_3 8e1012bfab9235e9
|
||||
1 4945 1666974914782388699 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
|
||||
4945 5009 1666974914846390631 Step_3 8e1012bfab9235e9
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Start testing: Oct 28 01:17 EDT
|
||||
Start testing: Oct 28 12:41 EDT
|
||||
----------------------------------------------------------
|
||||
End testing: Oct 28 01:17 EDT
|
||||
End testing: Oct 28 12:41 EDT
|
||||
|
|
|
@ -4,7 +4,7 @@ Size=95,60
|
|||
Collapsed=0
|
||||
|
||||
[Window][Dear ImGui Demo]
|
||||
Pos=501,181
|
||||
Pos=874,4
|
||||
Size=550,680
|
||||
Collapsed=1
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ Texture::Texture(Raytracing::Image* image): _image(image), width(image->getWidth
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glTexStorage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, width, height);
|
||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
// no sense sending data now since this texture is likely all black.
|
||||
|
@ -298,8 +298,9 @@ void Texture::updateImage() {
|
|||
// unfortunately we do have to put the data into a format that OpenGL can read. This is a TODO:?
|
||||
data = new unsigned char[(unsigned long)(width) * (unsigned long)height * 3];
|
||||
int pixelIndex = 0;
|
||||
for (int j = width-1; j >= 0; j--) {
|
||||
for (int i = 0; i < height; i++) {
|
||||
// slightly different order from STBi
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
data[pixelIndex++] = _image->getPixelR(i, j);
|
||||
data[pixelIndex++] = _image->getPixelG(i, j);
|
||||
data[pixelIndex++] = _image->getPixelB(i, j);
|
||||
|
|
|
@ -61,9 +61,13 @@ namespace Raytracing {
|
|||
delete (quad);
|
||||
}
|
||||
|
||||
// unfortunately GLX doesn't provide a typedef for the context creation, so we must define our own. I've chosen to go with the same style as
|
||||
// GL function pointers, "Pointer to the FunctioN GLX createContextAttribsARB PROCedure"
|
||||
typedef GLXContext (* PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
||||
|
||||
XWindow::XWindow(int width, int height): m_width(width), m_height(height) {
|
||||
// open the DEFAULT display. We don't want to open a specific screen as that is annoying.
|
||||
dlog << "Creating X11 display!";
|
||||
dlog << "Creating X11 display!\n";
|
||||
display = XOpenDisplay(NULL);
|
||||
if (display == NULL)
|
||||
throw std::runtime_error("Unable to open an X11 display! Is the X server running?");
|
||||
|
@ -76,9 +80,9 @@ namespace Raytracing {
|
|||
frameBufferConfig = glXChooseFBConfig(display, DefaultScreen(display), visual_attribs, &frameBufferCount);
|
||||
if (!frameBufferConfig)
|
||||
throw std::runtime_error("Unable to get window framebuffer configs!");
|
||||
dlog << "We have " << frameBufferCount << " framebuffers\nSelecting the best!";
|
||||
dlog << "We have " << frameBufferCount << " framebuffers\n";
|
||||
// select the best config from available ones.
|
||||
int bestConfigIndex = -1, worstConfig = -1, bestSamples = -1, worstSamples = 999;
|
||||
int bestConfigIndex = 0, bestSamples = -1;
|
||||
for (int i = 0; i < frameBufferCount; i++) {
|
||||
XVisualInfo* xVisualInfo = glXGetVisualFromFBConfig(display, frameBufferConfig[i]);
|
||||
if (xVisualInfo) {
|
||||
|
@ -86,19 +90,18 @@ namespace Raytracing {
|
|||
glXGetFBConfigAttrib(display, frameBufferConfig[i], GLX_SAMPLE_BUFFERS, &sampleBuffer);
|
||||
glXGetFBConfigAttrib(display, frameBufferConfig[i], GLX_SAMPLES, &samples);
|
||||
|
||||
dlog << "Checking framebuffer config " << i << " with samples: " << samples;
|
||||
|
||||
if ( bestConfigIndex < 0 || sampleBuffer && samples > bestSamples )
|
||||
bestConfigIndex = i, bestSamples = samples;
|
||||
if ( worstConfig < 0 || !sampleBuffer || samples < worstSamples )
|
||||
worstConfig = i, worstSamples = samples;
|
||||
// if the sample buffer exists, and we have more samples in this config, make this config the one we use.
|
||||
if (sampleBuffer && samples > bestSamples) {
|
||||
bestConfigIndex = i;
|
||||
bestSamples = samples;
|
||||
}
|
||||
}
|
||||
XFree(xVisualInfo);
|
||||
}
|
||||
dlog << "We selected config: " << bestConfigIndex << " with " << bestSamples << "# of samples!\n";
|
||||
GLXFBConfig bestConfig = frameBufferConfig[bestConfigIndex];
|
||||
// we need to make sure we remember to free memory since we are working with c pointers!
|
||||
XFree(frameBufferConfig);
|
||||
|
||||
// as I understand it every window in X11 is a sub-window of the root, or desktop window
|
||||
// which is why I guess wayland was created, because X11 can't handle a bunch of stuff like VRF (variable refresh rate)
|
||||
// because your say two monitors are treated as one big window, in effect limiting the refresh rate
|
||||
|
@ -106,7 +109,7 @@ namespace Raytracing {
|
|||
// plus needless security in a low level lib preventing stuff like discord screen sharing. Annoying as hell. /rant/.
|
||||
desktop = DefaultRootWindow(display);
|
||||
// try to open a gl visual context that meets our attributes' requirements
|
||||
dlog << "Getting visual info!";
|
||||
dlog << "Getting visual info!\n";
|
||||
visualInfo = glXChooseVisual(display, 0, OpenGLAttributes);
|
||||
// if our attributes are too much for the display, let's try reducing them. (modern hardware should support 24bit depth though)
|
||||
if (visualInfo == NULL) {
|
||||
|
@ -114,7 +117,7 @@ namespace Raytracing {
|
|||
OpenGLAttributes[2] = 16;
|
||||
visualInfo = glXChooseVisual(display, 0, OpenGLAttributes);
|
||||
if (visualInfo == NULL) {
|
||||
throw std::runtime_error("Unable to create window's visual context. Is your driver up to date?");
|
||||
throw std::runtime_error("Unable to create window's visual context. Is your driver up to date?\n");
|
||||
}
|
||||
}
|
||||
ilog << visualInfo->visualid << ": With depth: " << visualInfo->depth << " and RGB: " << visualInfo->bits_per_rgb << "\n";
|
||||
|
@ -141,6 +144,13 @@ namespace Raytracing {
|
|||
visualInfo->visual,
|
||||
CWColormap | CWEventMask,
|
||||
&xSetWindowAttributes);
|
||||
// install a error handler
|
||||
// maybe we should set back the old one but i'd rather it goto std:err than crash the window
|
||||
XSetErrorHandler([](Display* displayPtr, XErrorEvent* eventPtr) -> int {
|
||||
elog << "An error occurred while trying to setup X11: " << eventPtr->error_code << ";\n " << eventPtr->minor_code << ";\n "
|
||||
<< eventPtr->request_code << "\n";
|
||||
return 0;
|
||||
});
|
||||
|
||||
// Now show the window
|
||||
XMapWindow(display, window);
|
||||
|
@ -148,9 +158,32 @@ namespace Raytracing {
|
|||
// there might actually be an argument to be made about X11 being outdated....
|
||||
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
|
||||
XSetWMProtocols(display, window, &wmDelete, 1);
|
||||
|
||||
// get the list of GLX extensions for this system
|
||||
const char* glExtensions = glXQueryExtensionsString(display, DefaultScreen(display));
|
||||
// much in the same way that we get GL function pointers and use them we will do the same with the context creation
|
||||
auto glXCreateContextAttribsARBPtr = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((unsigned char*) "glXCreateContextAttribsARB");
|
||||
// now we can finally create a OpenGL context for our window
|
||||
glContext = glXCreateContext(display, visualInfo, NULL, GL_TRUE);
|
||||
int OpenGLContextAttributes[] = {
|
||||
// OpenGL major version, we want GL4.5+
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||
// OpenGL minor version,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, 5,
|
||||
// I don't remember what this does, but I know GLFW recommends that forward compatability be set true,
|
||||
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||
// Core profile for better Renderdoc compatibility + I don't need non core extensions
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
None
|
||||
};
|
||||
// now we can actually create and acquire the context
|
||||
glContext = glXCreateContextAttribsARBPtr(display, bestConfig, 0, True, OpenGLContextAttributes);
|
||||
// make sure if there was any error we are notified
|
||||
XSync(display, False);
|
||||
if (!glContext)
|
||||
flog << "Unable to create GL context!";
|
||||
if (glXIsDirect(display, glContext)){
|
||||
ilog << "A direct GL context was acquired!\n";
|
||||
} else // direct contexts are faster than indirect!
|
||||
wlog << "Warning! Indirect context!\n";
|
||||
// make the currently executing thread the one current to the OpenGL context
|
||||
// since OpenGL is a single threaded finite state machine if we want to do mutli-threading with OpenGL (we don't)
|
||||
// this has to be called in each thread before we make use of any OpenGL function.
|
||||
|
|
Loading…
Reference in New Issue