Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpu: OpenGL 4 implementation #7

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,13 @@ if(SDL_VIDEO)
endif()
endif()

if (SDL_OPENGL)
set(SDL_GPU_OPENGL 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/gpu/opengl/*.c")
else()
set(SDL_GPU_OPENGL 0)
endif()

# Dummies
# configure.ac does it differently:
# if not have X
Expand Down
172 changes: 87 additions & 85 deletions include/SDL3/SDL_gpu.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions include/build_config/SDL_build_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
#cmakedefine SDL_VIDEO_RENDER_VITA_GXM @SDL_VIDEO_RENDER_VITA_GXM@

#cmakedefine SDL_GPU_METAL @SDL_GPU_METAL@
#cmakedefine SDL_GPU_OPENGL @SDL_GPU_OPENGL@

/* Enable OpenGL support */
#cmakedefine SDL_VIDEO_OPENGL @SDL_VIDEO_OPENGL@
Expand Down
24 changes: 19 additions & 5 deletions src/gpu/SDL_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@


extern const SDL_GpuDriver DUMMY_GpuDriver;
extern const SDL_GpuDriver OPENGL_GpuDriver;
extern const SDL_GpuDriver METAL_GpuDriver;

static const SDL_GpuDriver *gpu_drivers[] = {
#ifdef SDL_GPU_METAL
&METAL_GpuDriver,
#endif
#ifdef SDL_GPU_OPENGL
&OPENGL_GpuDriver,
#endif
&DUMMY_GpuDriver
};
Expand Down Expand Up @@ -275,6 +279,8 @@ SDL_CreateGpuTexture(SDL_GpuDevice *device, const SDL_GpuTextureDescription *des
SDL_InvalidParamError("desc");
} else if (desc->depth_or_slices == 0) {
SDL_SetError("depth_or_slices must be > 0");
} else if (desc->mipmap_levels == 0) {
SDL_SetError("mipmap_levels must be > 0");
} else if ((desc->texture_type == SDL_GPUTEXTYPE_CUBE) && (desc->depth_or_slices != 6)) {
SDL_SetError("depth_or_slices for a cubemap must be 6");
} else if ((desc->texture_type == SDL_GPUTEXTYPE_CUBE_ARRAY) && ((desc->depth_or_slices % 6) != 0)) {
Expand Down Expand Up @@ -887,6 +893,12 @@ SDL_SetGpuRenderPassFragmentTexture(SDL_GpuRenderPass *pass, SDL_GpuTexture *tex
return pass ? pass->device->SetRenderPassFragmentTexture(pass, texture, index) : SDL_InvalidParamError("pass");
}

int
SDL_SetGpuMesh(SDL_GpuRenderPass *pass, SDL_GpuBuffer *buffer, const Uint32 offset, const Uint32 index)
{
return pass ? pass->device->SetMesh(pass, buffer, offset, index) : SDL_InvalidParamError("pass");
}

int
SDL_GpuDraw(SDL_GpuRenderPass *pass, Uint32 vertex_start, Uint32 vertex_count)
{
Expand Down Expand Up @@ -1309,7 +1321,9 @@ SDL_MatchingGpuDepthTexture(const char *label, SDL_GpuDevice *device, SDL_GpuTex
depthtexdesc.pixel_format = SDL_GPUPIXELFMT_Depth24_Stencil8;
depthtexdesc.usage = SDL_GPUTEXUSAGE_RENDER_TARGET; /* !!! FIXME: does this need shader read or write to be the depth buffer? */
depthtexdesc.width = bbtexdesc.width;
depthtexdesc.height = bbtexdesc.width;
depthtexdesc.height = bbtexdesc.height;
depthtexdesc.depth_or_slices = 1;
depthtexdesc.mipmap_levels = 1;
SDL_DestroyGpuTexture(*depthtex);
*depthtex = SDL_CreateGpuTexture(device, &depthtexdesc);
}
Expand All @@ -1322,7 +1336,7 @@ SDL_MatchingGpuDepthTexture(const char *label, SDL_GpuDevice *device, SDL_GpuTex
#define SDL_GPUCYCLEITEMTYPE SDL_CpuBuffer
#define SDL_GPUCYCLECREATEFNSIG SDL_CreateCpuBufferCycle(const char *label, SDL_GpuDevice *device, const Uint32 bufsize, const void *data, const Uint32 numitems)
#define SDL_GPUCYCLENEXTFNNAME SDL_GetNextCpuBufferInCycle
#define SDL_GPUCYCLENEXTPTRFNNAME SDL_NextCpuBufferPtrInCycle
#define SDL_GPUCYCLENEXTPTRFNNAME SDL_GetNextCpuBufferPtrInCycle
#define SDL_GPUCYCLEDESTROYFNNAME SDL_DestroyCpuBufferCycle
#define SDL_GPUCYCLECREATE(lbl, failvar, itemvar) { itemvar = SDL_CreateCpuBuffer(lbl, device, bufsize, data); failvar = (itemvar == NULL); }
#define SDL_GPUCYCLEDESTROY SDL_DestroyCpuBuffer
Expand All @@ -1331,7 +1345,7 @@ SDL_MatchingGpuDepthTexture(const char *label, SDL_GpuDevice *device, SDL_GpuTex
#define SDL_GPUCYCLETYPE SDL_GpuBufferCycle
#define SDL_GPUCYCLEITEMTYPE SDL_GpuBuffer
#define SDL_GPUCYCLECREATEFNSIG SDL_CreateGpuBufferCycle(const char *label, SDL_GpuDevice *device, const Uint32 bufsize, const Uint32 numitems)
#define SDL_GPUCYCLENEXTFNNAME SDL_GetNextGpuBufferCycle
#define SDL_GPUCYCLENEXTFNNAME SDL_GetNextGpuBufferInCycle
#define SDL_GPUCYCLENEXTPTRFNNAME SDL_GetNextGpuBufferPtrInCycle
#define SDL_GPUCYCLEDESTROYFNNAME SDL_DestroyGpuBufferCycle
#define SDL_GPUCYCLECREATE(lbl, failvar, itemvar) { itemvar = SDL_CreateGpuBuffer(lbl, device, bufsize); failvar = (itemvar == NULL); }
Expand All @@ -1341,8 +1355,8 @@ SDL_MatchingGpuDepthTexture(const char *label, SDL_GpuDevice *device, SDL_GpuTex
#define SDL_GPUCYCLETYPE SDL_GpuTextureCycle
#define SDL_GPUCYCLEITEMTYPE SDL_GpuTexture
#define SDL_GPUCYCLECREATEFNSIG SDL_CreateGpuTextureCycle(const char *label, SDL_GpuDevice *device, const SDL_GpuTextureDescription *texdesc, const Uint32 numitems)
#define SDL_GPUCYCLENEXTFNNAME SDL_GpuNextTextureCycle
#define SDL_GPUCYCLENEXTPTRFNNAME SDL_GpuNextTexturePtrCycle
#define SDL_GPUCYCLENEXTFNNAME SDL_GetNextGpuTextureInCycle
#define SDL_GPUCYCLENEXTPTRFNNAME SDL_GetNextGpuTexturePtrInCycle
#define SDL_GPUCYCLEDESTROYFNNAME SDL_DestroyGpuTextureCycle
#define SDL_GPUCYCLECREATE(lbl, failvar, itemvar) { if (texdesc) { SDL_GpuTextureDescription td; SDL_memcpy(&td, texdesc, sizeof (td)); td.label = lbl; itemvar = SDL_CreateGpuTexture(device, &td); failvar = (itemvar == NULL); } else { itemvar = NULL; failvar = SDL_FALSE; } }
#define SDL_GPUCYCLEDESTROY SDL_DestroyGpuTexture
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/SDL_gpu_cycle_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SDL_GPUCYCLECREATEFNSIG
{
/* allocate the whole thing as one block: `items` as a variable length array at the end, the label data after that. */
const size_t labellen = label ? (SDL_strlen(label) + 1) : 0;
const size_t thislabellen = label ? 0 : labellen + 32;
const size_t thislabellen = label ? labellen + 32 : 0;
const size_t alloclen = sizeof (SDL_GPUCYCLETYPE) + (sizeof (SDL_GPUCYCLEITEMTYPE *) * numitems) + labellen;
SDL_GPUCYCLETYPE *retval = (SDL_GPUCYCLETYPE *) SDL_calloc(1, alloclen);
char *thislabel = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/gpu/SDL_sysgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct SDL_GpuDevice
int (*SetRenderPassFragmentBuffer)(SDL_GpuRenderPass *pass, SDL_GpuBuffer *buffer, Uint32 offset, Uint32 index);
int (*SetRenderPassFragmentSampler)(SDL_GpuRenderPass *pass, SDL_GpuSampler *sampler, Uint32 index);
int (*SetRenderPassFragmentTexture)(SDL_GpuRenderPass *pass, SDL_GpuTexture *texture, Uint32 index);
int (*SetMesh)(SDL_GpuRenderPass *pass, SDL_GpuBuffer *buffer, Uint32 offset, Uint32 index);
int (*Draw)(SDL_GpuRenderPass *pass, Uint32 vertex_start, Uint32 vertex_count);
int (*DrawIndexed)(SDL_GpuRenderPass *pass, Uint32 index_count, SDL_GpuIndexType index_type, SDL_GpuBuffer *index_buffer, Uint32 index_offset);
int (*DrawInstanced)(SDL_GpuRenderPass *pass, Uint32 vertex_start, Uint32 vertex_count, Uint32 instance_count, Uint32 base_instance);
Expand Down
2 changes: 2 additions & 0 deletions src/gpu/dummy/SDL_gpu_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static int DUMMY_GpuSetRenderPassVertexTexture(SDL_GpuRenderPass *pass, SDL_GpuT
static int DUMMY_GpuSetRenderPassFragmentBuffer(SDL_GpuRenderPass *pass, SDL_GpuBuffer *buffer, Uint32 offset, Uint32 index) { return 0; }
static int DUMMY_GpuSetRenderPassFragmentSampler(SDL_GpuRenderPass *pass, SDL_GpuSampler *sampler, Uint32 index) { return 0; }
static int DUMMY_GpuSetRenderPassFragmentTexture(SDL_GpuRenderPass *pass, SDL_GpuTexture *texture, Uint32 index) { return 0; }
static int DUMMY_GpuSetMeshBuffer(SDL_GpuRenderPass *pass, SDL_GpuBuffer *buffer, Uint32 offset, Uint32 index) { return 0; }
static int DUMMY_GpuDraw(SDL_GpuRenderPass *pass, Uint32 vertex_start, Uint32 vertex_count) { return 0; }
static int DUMMY_GpuDrawIndexed(SDL_GpuRenderPass *pass, Uint32 index_count, SDL_GpuIndexType index_type, SDL_GpuBuffer *index_buffer, Uint32 index_offset) { return 0; }
static int DUMMY_GpuDrawInstanced(SDL_GpuRenderPass *pass, Uint32 vertex_start, Uint32 vertex_count, Uint32 instance_count, Uint32 base_instance) { return 0; }
Expand Down Expand Up @@ -134,6 +135,7 @@ DUMMY_GpuCreateDevice(SDL_GpuDevice *device)
device->SetRenderPassFragmentBuffer = DUMMY_GpuSetRenderPassFragmentBuffer;
device->SetRenderPassFragmentSampler = DUMMY_GpuSetRenderPassFragmentSampler;
device->SetRenderPassFragmentTexture = DUMMY_GpuSetRenderPassFragmentTexture;
device->SetMesh = DUMMY_GpuSetMeshBuffer;
device->Draw = DUMMY_GpuDraw;
device->DrawIndexed = DUMMY_GpuDrawIndexed;
device->DrawInstanced = DUMMY_GpuDrawInstanced;
Expand Down
Loading