SDL compiling for Emscripten
This commit is contained in:
parent
3bfac34979
commit
cb9f6c6932
2
Math.cpp
2
Math.cpp
@ -86,7 +86,7 @@ namespace ZL {
|
||||
|
||||
if (depthRange <= 0)
|
||||
{
|
||||
throw std::exception("zFar must be greater than zNear");
|
||||
throw std::runtime_error("zFar must be greater than zNear");
|
||||
}
|
||||
|
||||
Matrix4f r;
|
||||
|
||||
3
Math.h
3
Math.h
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
namespace ZL {
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
|
||||
//====================================================
|
||||
//===================== GLSL Shaders =================
|
||||
//====================================================
|
||||
@ -112,10 +114,13 @@ PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = NULL;
|
||||
PFNGLBINDVERTEXARRAYPROC glBindVertexArray = NULL;
|
||||
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArray = NULL;
|
||||
|
||||
#endif
|
||||
|
||||
namespace ZL {
|
||||
|
||||
bool BindOpenGlFunctions()
|
||||
{
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
//char* extensionList = (char*)glGetString(GL_EXTENSIONS);
|
||||
char* glVersion = (char*)glGetString(GL_VERSION);
|
||||
bool ok = true;
|
||||
@ -231,8 +236,7 @@ namespace ZL {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
//if (findString("GL_ARB_framebuffer_object", extensionList))
|
||||
{
|
||||
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)wglGetProcAddress("glIsRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)wglGetProcAddress("glBindRenderbuffer");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)wglGetProcAddress("glDeleteRenderbuffers");
|
||||
@ -279,15 +283,6 @@ namespace ZL {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*else
|
||||
{
|
||||
ok = false;
|
||||
}*/
|
||||
|
||||
//if (findString("GL_ARB_uniform_buffer_object", extensionList))
|
||||
{
|
||||
|
||||
glGetUniformIndices = (PFNGLGETUNIFORMINDICESPROC)wglGetProcAddress("glGetUniformIndices");
|
||||
glGetActiveUniformsiv = (PFNGLGETACTIVEUNIFORMSIVPROC)wglGetProcAddress("glGetActiveUniformsiv");
|
||||
glGetActiveUniformName = (PFNGLGETACTIVEUNIFORMNAMEPROC)wglGetProcAddress("glGetActiveUniformName");
|
||||
@ -308,11 +303,7 @@ namespace ZL {
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
/*else
|
||||
{
|
||||
ok = false;
|
||||
}*/
|
||||
|
||||
|
||||
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays");
|
||||
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray");
|
||||
@ -327,6 +318,9 @@ namespace ZL {
|
||||
|
||||
|
||||
return ok;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CheckGlError()
|
||||
@ -335,7 +329,7 @@ namespace ZL {
|
||||
|
||||
if (error != GL_NO_ERROR)
|
||||
{
|
||||
throw std::exception("Gl error");
|
||||
throw std::runtime_error("Gl error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "SDL.h"
|
||||
#ifdef EMSCRIPTEN
|
||||
//#define GL_GLEXT_PROTOTYPES 1
|
||||
//#define EGL_EGLEXT_PROTOTYPES 1
|
||||
//#include <SDL2/SDL_opengl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include "emscripten.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
|
||||
@ -126,9 +141,13 @@ extern PFNGLBINDBUFFERBASEPROC glBindBufferBase;
|
||||
extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
|
||||
extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
|
||||
extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArray;
|
||||
#else
|
||||
|
||||
#endif
|
||||
namespace ZL {
|
||||
|
||||
|
||||
|
||||
bool BindOpenGlFunctions();
|
||||
|
||||
void CheckGlError();
|
||||
|
||||
37
Renderer.cpp
37
Renderer.cpp
@ -21,13 +21,16 @@ namespace ZL {
|
||||
|
||||
VAOHolder::VAOHolder()
|
||||
{
|
||||
#ifndef EMSCRIPTEN
|
||||
glGenVertexArrays(1, &vao);
|
||||
#endif
|
||||
}
|
||||
|
||||
VAOHolder::~VAOHolder()
|
||||
{
|
||||
#ifndef EMSCRIPTEN
|
||||
glDeleteVertexArray(1, &vao);
|
||||
//glDeleteBuffers(1, &Buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
GLuint VAOHolder::getBuffer()
|
||||
@ -122,13 +125,14 @@ namespace ZL {
|
||||
{
|
||||
//Check if main thread, check if data is not empty...
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
if (!vao)
|
||||
{
|
||||
vao = std::make_shared<VAOHolder>();
|
||||
}
|
||||
|
||||
glBindVertexArray(vao->getBuffer());
|
||||
|
||||
#endif
|
||||
if (!positionVBO)
|
||||
{
|
||||
positionVBO = std::make_shared<VBOHolder>();
|
||||
@ -159,8 +163,9 @@ namespace ZL {
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
#endif
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
@ -176,7 +181,7 @@ namespace ZL {
|
||||
|
||||
if (ProjectionMatrixStack.size() > CONST_MATRIX_STACK_SIZE)
|
||||
{
|
||||
throw std::exception("Projection matrix stack overflow!!!!");
|
||||
throw std::runtime_error("Projection matrix stack overflow!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,7 +190,7 @@ namespace ZL {
|
||||
{
|
||||
if (ProjectionMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Projection matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Projection matrix stack underflow!!!!");
|
||||
}
|
||||
ProjectionMatrixStack.pop();
|
||||
SetMatrix();
|
||||
@ -196,12 +201,12 @@ namespace ZL {
|
||||
{
|
||||
if (ProjectionMatrixStack.size() <= 0)
|
||||
{
|
||||
throw std::exception("Projection matrix stack out!");
|
||||
throw std::runtime_error("Projection matrix stack out!");
|
||||
}
|
||||
|
||||
if (ModelviewMatrixStack.size() <= 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack out!");
|
||||
throw std::runtime_error("Modelview matrix stack out!");
|
||||
}
|
||||
|
||||
ProjectionModelViewMatrix = ProjectionMatrixStack.top() * ModelviewMatrixStack.top();
|
||||
@ -220,14 +225,14 @@ namespace ZL {
|
||||
{
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
|
||||
ModelviewMatrixStack.push(ModelviewMatrixStack.top());
|
||||
|
||||
if (ModelviewMatrixStack.size() > CONST_MATRIX_STACK_SIZE)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack overflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack overflow!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +240,7 @@ namespace ZL {
|
||||
{
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
|
||||
ModelviewMatrixStack.pop();
|
||||
@ -256,7 +261,7 @@ namespace ZL {
|
||||
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
|
||||
ModelviewMatrixStack.pop();
|
||||
@ -276,7 +281,7 @@ namespace ZL {
|
||||
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
|
||||
ModelviewMatrixStack.pop();
|
||||
@ -296,7 +301,7 @@ namespace ZL {
|
||||
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
|
||||
ModelviewMatrixStack.pop();
|
||||
@ -326,7 +331,7 @@ namespace ZL {
|
||||
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
|
||||
ModelviewMatrixStack.pop();
|
||||
@ -340,7 +345,7 @@ namespace ZL {
|
||||
{
|
||||
if (ModelviewMatrixStack.size() > 64)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack overflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack overflow!!!!");
|
||||
}
|
||||
ModelviewMatrixStack.push(m);
|
||||
SetMatrix();
|
||||
@ -351,7 +356,7 @@ namespace ZL {
|
||||
{
|
||||
if (ModelviewMatrixStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Modelview matrix stack underflow!!!!");
|
||||
throw std::runtime_error("Modelview matrix stack underflow!!!!");
|
||||
}
|
||||
ModelviewMatrixStack.pop();
|
||||
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
|
||||
#include "OpenGlExtensions.h"
|
||||
#include "Math.h"
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include "ShaderManager.h"
|
||||
|
||||
namespace ZL {
|
||||
|
||||
@ -40,12 +40,12 @@ namespace ZL {
|
||||
|
||||
if (!vertexShaderCompiled)
|
||||
{
|
||||
throw std::exception("Failed to compile vertex shader code!");
|
||||
throw std::runtime_error("Failed to compile vertex shader code!");
|
||||
}
|
||||
|
||||
if (!fragmentShaderCompiled)
|
||||
{
|
||||
throw std::exception("Failed to compile fragment shader code!");
|
||||
throw std::runtime_error("Failed to compile fragment shader code!");
|
||||
}
|
||||
|
||||
shaderProgram = glCreateProgram();
|
||||
@ -64,7 +64,7 @@ namespace ZL {
|
||||
if (!programLinked)
|
||||
{
|
||||
shaderProgram = 0;
|
||||
throw std::exception("Failed to link shader program!");
|
||||
throw std::runtime_error("Failed to link shader program!");
|
||||
}
|
||||
|
||||
|
||||
@ -133,12 +133,12 @@ namespace ZL {
|
||||
{
|
||||
if (shaderStack.size() >= CONST_MAX_SHADER_STACK_SIZE)
|
||||
{
|
||||
throw std::exception("Shader stack overflow!");
|
||||
throw std::runtime_error("Shader stack overflow!");
|
||||
}
|
||||
|
||||
if (shaderResourceMap.find(shaderName) == shaderResourceMap.end())
|
||||
{
|
||||
throw std::exception("Shader does not exist!");
|
||||
throw std::runtime_error("Shader does not exist!");
|
||||
}
|
||||
|
||||
shaderStack.push(shaderName);
|
||||
@ -151,7 +151,7 @@ namespace ZL {
|
||||
{
|
||||
if (shaderStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Shader stack underflow!");
|
||||
throw std::runtime_error("Shader stack underflow!");
|
||||
}
|
||||
|
||||
shaderStack.pop();
|
||||
@ -170,7 +170,7 @@ namespace ZL {
|
||||
{
|
||||
if (shaderStack.size() == 0)
|
||||
{
|
||||
throw std::exception("Shader stack underflow!");
|
||||
throw std::runtime_error("Shader stack underflow!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ZL
|
||||
|
||||
if (texID == 0)
|
||||
{
|
||||
throw std::exception("glGenTextures did not work");
|
||||
throw std::runtime_error("glGenTextures did not work");
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
@ -77,7 +77,7 @@ namespace ZL
|
||||
|
||||
if (fileSize < 22)
|
||||
{
|
||||
throw std::exception("File is too short or not correct!");
|
||||
throw std::runtime_error("File is too short or not correct!");
|
||||
}
|
||||
|
||||
//This refers to BITMAPV5HEADER
|
||||
@ -99,7 +99,7 @@ namespace ZL
|
||||
|
||||
if (pos + 3 > fileSize)
|
||||
{
|
||||
throw std::exception("File is too short!");
|
||||
throw std::runtime_error("File is too short!");
|
||||
}
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ namespace ZL
|
||||
|
||||
if (fileSize < 22)
|
||||
{
|
||||
throw std::exception("File is too short or not correct!");
|
||||
throw std::runtime_error("File is too short or not correct!");
|
||||
}
|
||||
|
||||
//This refers to BITMAPV5HEADER
|
||||
@ -147,7 +147,7 @@ namespace ZL
|
||||
|
||||
if (pos + 4 > fileSize)
|
||||
{
|
||||
throw std::exception("File is too short!");
|
||||
throw std::runtime_error("File is too short!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
Utils.h
3
Utils.h
@ -2,6 +2,9 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
7
main.cpp
7
main.cpp
@ -5,9 +5,6 @@
|
||||
#include "Physics.h"
|
||||
#include <string>
|
||||
|
||||
//#include <windows.h>
|
||||
#include "SDL.h"
|
||||
//#include "SDL_image.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
@ -290,7 +287,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef EMSCRIPTEN
|
||||
SDL_Renderer* renderer = NULL;
|
||||
SDL_CreateWindowAndRenderer(512, 512, SDL_WINDOW_OPENGL, &window, &renderer);
|
||||
SDL_CreateWindowAndRenderer(512, 512, SDL_WINDOW_OPENGL, &ZL::window, &renderer);
|
||||
#else
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
|
||||
SDL_Log("Failed to initialize SDL: %s", SDL_GetError());
|
||||
@ -309,7 +306,7 @@ int main(int argc, char* argv[])
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
ZL::window = SDL_CreateWindow("title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CONST_WIDTH, CONST_HEIGHT, SDL_WINDOW_OPENGL);
|
||||
ZL::window = SDL_CreateWindow("Jumping Bird", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CONST_WIDTH, CONST_HEIGHT, SDL_WINDOW_OPENGL);
|
||||
|
||||
//todo
|
||||
ZL::Env::windowHeaderHeight = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user