1
0
Fork 0

Graphics class: use GfxDriver API.

This commit is contained in:
Henrik Hautakoski 2022-09-17 12:07:28 +02:00
parent d3debea41a
commit 4dad1a5d75
2 changed files with 14 additions and 20 deletions

View file

@ -2,6 +2,7 @@
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <Spectre/GfxDriver/GfxDriver.h>
#include <Spectre/Display/Display.h>
namespace sp {
@ -42,12 +43,17 @@ public :
void swapBuffers();
GfxDriver* getDriver();
protected :
int m_width;
int m_height;
Display *m_display;
// Graphics Driver. OpenGL/Vulcan/DirectX etc.
GfxDriver *m_gfxdrv;
};
} // namespace sp

View file

@ -1,6 +1,6 @@
#include "GfxDriver/OpenGL/OpenGLDrv.h"
#include <Spectre/Graphics.h>
#include <Graphics/GL/gl.h>
#include <string>
namespace sp {
@ -11,6 +11,9 @@ Graphics::Graphics(PlatformApplication *platform)
m_height = 600;
m_display = new Display();
// Only have OpenGL atm.
m_gfxdrv = new OpenGLDrv();
}
Graphics::~Graphics()
@ -42,22 +45,7 @@ void Graphics::shutdown()
std::string Graphics::getVersion() const
{
char buf[512];
std::string prof = "Compability";
char *ver = (char*) glGetString(GL_VERSION);
char *ven = (char*) glGetString(GL_VENDOR);
char *ren = (char*) glGetString(GL_RENDERER);
GLint flags;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &flags);
if (flags & GL_CONTEXT_CORE_PROFILE_BIT) {
prof = "Core";
}
snprintf(buf, sizeof(buf), "OpenGL %s %s profile - %s %s", ver, prof.c_str(), ren, ven);
return std::string(buf);
return m_gfxdrv->getVendor();
}
void Graphics::setDisplayMode(Display::Mode mode)
@ -72,17 +60,17 @@ void Graphics::setSize(int width, int height)
void Graphics::setViewport(int x, int y, int width, int height)
{
glViewport(x, y, width, height);
m_gfxdrv->setViewport(x, y, width, height);
}
void Graphics::setClearColor(float r, float g, float b)
{
glClearColor(r, g, b, 1.0f);
m_gfxdrv->setClearColor(r, g, b, 1.0f);
}
void Graphics::clearBuffer()
{
glClear(GL_COLOR_BUFFER_BIT);
m_gfxdrv->clearColorBuffer();
}
void Graphics::swapBuffers()