Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions src/MultiCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
* SOFTWARE.
*/

#include <SDL2/SDL_opengl.h>
#include "Example.h"

#if defined(TVGEXAMPLE_GL_SUPPORTED) || defined(TVGEXAMPLE_GLES_SUPPORTED)
#include <SDL2/SDL_opengl.h>
#endif

#define WIDTH 1024
#define HEIGHT 1024
#define NUM_PER_LINE 4
Expand Down Expand Up @@ -86,7 +83,7 @@ void mainloop()
/* SW Engine Specific Setup */
/************************************************************************/

void runSw()
bool runSw()
{
auto window = SDL_CreateWindow("ThorVG Example (Software)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_HIDDEN);
auto surface = SDL_GetWindowSurface(window);
Expand All @@ -110,15 +107,15 @@ void runSw()
mainloop();

SDL_DestroyWindow(window);

return true;
}


/************************************************************************/
/* GL Engine Specific Setup */
/************************************************************************/

#if defined(TVGEXAMPLE_GL_SUPPORTED) || defined(TVGEXAMPLE_GLES_SUPPORTED)

typedef void (*PFNGLTEXIMAGE2DPROC)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
typedef void (*PFNGLTEXPARAMETERIPROC)(GLenum target, GLenum pname, GLint param);

Expand Down Expand Up @@ -169,13 +166,10 @@ struct GLFrameBuffer
fglBlitFramebuffer(0, 0, width, height, posX, posY, posX +width, posY + height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
};
#endif

void runGl()
bool runGl()
{
#if defined(TVGEXAMPLE_GL_SUPPORTED) || defined(TVGEXAMPLE_GLES_SUPPORTED)

#ifdef THORVG_GL_TARGET_GLES
#if defined(TVGEXAMPLE_GLES_SUPPORTED)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
Expand All @@ -185,19 +179,27 @@ void runGl()
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#endif

auto failGl = []() -> bool
{
cout << "Not Support OpenGL/ES" << endl;
return false;
};

auto window = SDL_CreateWindow("ThorVG Example (OpenGL)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
if (!window) return failGl();
auto context = SDL_GL_CreateContext(window);

fglBindTexture = (PFNGLBINDTEXTUREEXTPROC)SDL_GL_GetProcAddress("glBindTexture");
fglDeleteTextures = (PFNGLDELETETEXTURESEXTPROC)SDL_GL_GetProcAddress("glDeleteTextures");
fglGenTextures = (PFNGLGENTEXTURESEXTPROC)SDL_GL_GetProcAddress("glGenTextures");
fglTexImage2D = (PFNGLTEXIMAGE2DPROC)SDL_GL_GetProcAddress("glTexImage2D");
fglTexParameteri = (PFNGLTEXPARAMETERIPROC)SDL_GL_GetProcAddress("glTexParameteri");
fglBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)SDL_GL_GetProcAddress("glBindFramebuffer");
fglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)SDL_GL_GetProcAddress("glGenFramebuffers");
fglDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)SDL_GL_GetProcAddress("glDeleteFramebuffers");
fglFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)SDL_GL_GetProcAddress("glFramebufferTexture2D");
fglBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)SDL_GL_GetProcAddress("glBlitFramebuffer");
if (!context) return failGl();

if (!(fglBindTexture = (PFNGLBINDTEXTUREEXTPROC)SDL_GL_GetProcAddress("glBindTexture"))) return failGl();
if (!(fglDeleteTextures = (PFNGLDELETETEXTURESEXTPROC)SDL_GL_GetProcAddress("glDeleteTextures"))) return failGl();
if (!(fglGenTextures = (PFNGLGENTEXTURESEXTPROC)SDL_GL_GetProcAddress("glGenTextures"))) return failGl();
if (!(fglTexImage2D = (PFNGLTEXIMAGE2DPROC)SDL_GL_GetProcAddress("glTexImage2D"))) return failGl();
if (!(fglTexParameteri = (PFNGLTEXPARAMETERIPROC)SDL_GL_GetProcAddress("glTexParameteri"))) return failGl();
if (!(fglBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)SDL_GL_GetProcAddress("glBindFramebuffer"))) return failGl();
if (!(fglGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)SDL_GL_GetProcAddress("glGenFramebuffers"))) return failGl();
if (!(fglDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)SDL_GL_GetProcAddress("glDeleteFramebuffers"))) return failGl();
if (!(fglFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)SDL_GL_GetProcAddress("glFramebufferTexture2D"))) return failGl();
if (!(fglBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)SDL_GL_GetProcAddress("glBlitFramebuffer"))) return failGl();

// Create the framebuffer which the GlCanvas can render to
// Since the example is just a simple demo, and only run the rendering function once
Expand Down Expand Up @@ -231,17 +233,16 @@ void runGl()

SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
#else
cout << "Not Support OpenGL" << endl;
#endif

return true;
}


/************************************************************************/
/* WG Engine Specific Setup */
/************************************************************************/

#ifdef THORVG_WG_RASTER_SUPPORT
#ifdef TVGEXAMPLE_WGPU_SUPPORTED
void wgCopyTextureToTexture(WGPUDevice device, WGPUTexture src, WGPUTexture dst, uint32_t posX, uint32_t posY, uint32_t width, uint32_t height) {
WGPUQueue queue = wgpuDeviceGetQueue(device);

Expand All @@ -266,10 +267,9 @@ void wgCopyTextureToTexture(WGPUDevice device, WGPUTexture src, WGPUTexture dst,
}
#endif

void runWg()
bool runWg()
{
#ifdef THORVG_WG_RASTER_SUPPORT
//TODO with Drawing Target?
#ifdef TVGEXAMPLE_WGPU_SUPPORTED
auto window = SDL_CreateWindow("ThorVG Example (WebGPU)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_HIDDEN);

//Here we create our WebGPU surface from the window!
Expand Down Expand Up @@ -383,8 +383,11 @@ void runWg()
wgpuSurfaceRelease(surface);
wgpuInstanceRelease(instance);
SDL_DestroyWindow(window);

return true;
#else
cout << "Not Support WebGPU" << endl;
return false;
#endif
}

Expand All @@ -411,7 +414,6 @@ int main(int argc, char **argv)

SDL_Quit();

//Terminate ThorVG Engine
tvg::Initializer::term();
}

Expand Down