mirror of
https://github.com/JaCzekanski/Avocado.git
synced 2024-06-02 19:27:41 -04:00
opengl: support for webgl 2
updateVramTexture LUT conversion for slower path (Android and Web) fix shader version header
This commit is contained in:
parent
fdece43c53
commit
a3a470384f
6
externals/glad/include/opengl.h
vendored
Normal file
6
externals/glad/include/opengl.h
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <glad/glad.h>
|
||||
#endif
|
|
@ -49,7 +49,7 @@
|
|||
// SDL,GL3W
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
|
||||
// SDL data
|
||||
static Uint64 g_Time = 0;
|
||||
|
@ -439,9 +439,12 @@ void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window)
|
|||
int w, h;
|
||||
static int display_w = 0, display_h = 0;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
// if (display_w == 0 || display_h == 0) { // web optimization
|
||||
#ifdef __EMSCRIPTEN
|
||||
if (display_w == 0 || display_h == 0) // web optimization
|
||||
#endif
|
||||
{
|
||||
SDL_GL_GetDrawableSize(window, &display_w, &display_h);
|
||||
// }
|
||||
}
|
||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||
io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include <opengl.h>
|
||||
#include <string>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <experimental/optional>
|
||||
|
|
|
@ -26,7 +26,13 @@ bool OpenGL::init() {
|
|||
|
||||
void OpenGL::deinit() { bus.unlistenAll(busToken); }
|
||||
|
||||
bool OpenGL::loadExtensions() { return gladLoadGLLoader(SDL_GL_GetProcAddress) != 0; }
|
||||
bool OpenGL::loadExtensions() {
|
||||
#ifdef __glad_h_
|
||||
return gladLoadGLLoader(SDL_GL_GetProcAddress) != 0;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OpenGL::loadShaders() {
|
||||
// PS1 GPU in Shader simulation
|
||||
|
@ -58,12 +64,14 @@ bool OpenGL::setup() {
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef __glad_h_
|
||||
// Check actual version of OpenGL context
|
||||
if (GLVersion.major * 10 + GLVersion.minor < VERSION_MAJOR * 10 + VERSION_MINOR) {
|
||||
printf("Unable to initialize OpenGL context for version %d.%d (got %d.%d)\n", VERSION_MAJOR, VERSION_MINOR, GLVersion.major,
|
||||
GLVersion.minor);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!loadShaders()) return false;
|
||||
|
||||
|
@ -98,9 +106,11 @@ bool OpenGL::setup() {
|
|||
blitBuffer = std::make_unique<Buffer>(makeBlitBuf().size() * sizeof(BlitStruct));
|
||||
|
||||
// Try native texture
|
||||
#ifdef GL_UNSIGNED_SHORT_1_5_5_5_REV
|
||||
vramTex = std::make_unique<Texture>(1024, 512, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false);
|
||||
#endif
|
||||
|
||||
if (vramTex->isCreated()) {
|
||||
if (vramTex && vramTex->isCreated()) {
|
||||
supportNativeTexture = true;
|
||||
} else {
|
||||
// Use compability mode
|
||||
|
@ -240,6 +250,16 @@ void OpenGL::update24bitTexture(gpu::GPU* gpu) {
|
|||
vramTex->update(vramUnpacked.data());
|
||||
}
|
||||
|
||||
constexpr std::array<float, 32> generateFloatLUT() {
|
||||
std::array<float, 32> lut = {{0}};
|
||||
for (int i = 0; i < 32; i++) {
|
||||
lut[i] = i / 31.f;
|
||||
}
|
||||
return lut;
|
||||
}
|
||||
|
||||
const std::array<float, 32> floatLUT = generateFloatLUT();
|
||||
|
||||
void OpenGL::updateVramTexture(gpu::GPU* gpu) {
|
||||
if (supportNativeTexture) {
|
||||
vramTex->update(gpu->vram.data());
|
||||
|
@ -257,10 +277,10 @@ void OpenGL::updateVramTexture(gpu::GPU* gpu) {
|
|||
for (int x = 0; x < gpu::VRAM_WIDTH; x++) {
|
||||
PSXColor c = gpu->vram[y * gpu::VRAM_WIDTH + x];
|
||||
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 0] = c.r / 31.f;
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 1] = c.g / 31.f;
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 2] = c.b / 31.f;
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 3] = (float)c.k;
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 0] = floatLUT[c.r];
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 1] = floatLUT[c.g];
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 2] = floatLUT[c.b];
|
||||
vramUnpacked[(y * gpu::VRAM_WIDTH + x) * 4 + 3] = floatLUT[c.k * 31];
|
||||
}
|
||||
}
|
||||
vramTex->update(vramUnpacked.data());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
#include <memory>
|
||||
#include "device/gpu/gpu.h"
|
||||
#include "shader/buffer.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "glad/glad.h"
|
||||
#include <opengl.h>
|
||||
|
||||
class Attribute {
|
||||
GLuint id;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
|
||||
class Buffer {
|
||||
GLuint id;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
|
||||
class Framebuffer {
|
||||
GLuint id;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "attribute.h"
|
||||
|
|
|
@ -4,16 +4,14 @@
|
|||
#include "utils/file.h"
|
||||
|
||||
#ifdef USE_OPENGLES
|
||||
const char* Shader::header = R"EOF(
|
||||
#version 300 es
|
||||
const char* Shader::header = R"EOF(#version 300 es
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
)EOF";
|
||||
#else
|
||||
const char* Shader::header = R"EOF(
|
||||
#version 150
|
||||
const char* Shader::header = R"EOF(#version 150
|
||||
|
||||
)EOF";
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
#include <string>
|
||||
|
||||
enum class ShaderType { Vertex, Fragment };
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <opengl.h>
|
||||
|
||||
class Texture {
|
||||
GLuint id;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include <opengl.h>
|
||||
#include <tuple>
|
||||
#include "glad/glad.h"
|
||||
|
||||
class Uniform {
|
||||
GLuint id;
|
||||
|
|
Loading…
Reference in a new issue