this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added GPU_AddDepthBuffer() to enable support for depth test on image targets. This will not work for GLES 1.1.

+123 -13
+5
include/SDL_gpu.h
··· 1027 1027 /*! Returns 1 if the camera transforms are enabled, 0 otherwise. */ 1028 1028 DECLSPEC GPU_bool SDLCALL GPU_IsCameraEnabled(GPU_Target* target); 1029 1029 1030 + /*! Attach a new depth buffer to the given target so that it can use depth testing. Context targets automatically have a depth buffer already. 1031 + * If successful, also enables depth testing for this target. 1032 + */ 1033 + DECLSPEC GPU_bool SDLCALL GPU_AddDepthBuffer(GPU_Target* target); 1034 + 1030 1035 /*! Enables or disables the depth test, which will skip drawing pixels/fragments behind other fragments. Disabled by default. 1031 1036 * This has implications for alpha blending, where compositing might not work correctly depending on render order. 1032 1037 */
+3
include/SDL_gpu_RendererImpl.h
··· 37 37 /*! \see GPU_ResetRendererState() */ 38 38 void (SDLCALL *ResetRendererState)(GPU_Renderer* renderer); 39 39 40 + /*! \see GPU_AddDepthBuffer() */ 41 + GPU_bool (SDLCALL *AddDepthBuffer)(GPU_Renderer* renderer, GPU_Target* target); 42 + 40 43 /*! \see GPU_SetWindowResolution() */ 41 44 GPU_bool (SDLCALL *SetWindowResolution)(GPU_Renderer* renderer, Uint16 w, Uint16 h); 42 45
+7
src/SDL_gpu.c
··· 526 526 #endif 527 527 } 528 528 529 + GPU_bool GPU_AddDepthBuffer(GPU_Target* target) 530 + { 531 + if(_gpu_current_renderer == NULL || _gpu_current_renderer->current_context_target == NULL || target == NULL) 532 + return GPU_FALSE; 533 + 534 + return _gpu_current_renderer->impl->AddDepthBuffer(_gpu_current_renderer, target); 535 + } 529 536 530 537 void GPU_SetDepthTest(GPU_Target* target, GPU_bool enable) 531 538 {
+53
src/renderer_GL_common.inl
··· 1954 1954 extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)target->data)->handle); 1955 1955 } 1956 1956 1957 + 1958 + static GPU_bool AddDepthBuffer(GPU_Renderer* renderer, GPU_Target* target) 1959 + { 1960 + #if defined(SDL_GPU_USE_GLES) && SDL_GPU_GLES_MAJOR_VERSION == 1 1961 + GPU_PushErrorCode("GPU_AddDepthBuffer", GPU_ERROR_USER_ERROR, "Not supported in GL ES 1.1."); 1962 + return GPU_FALSE; 1963 + #else 1964 + GLuint depth_buffer; 1965 + GLenum status; 1966 + GPU_CONTEXT_DATA* cdata; 1967 + 1968 + if(renderer->current_context_target == NULL) 1969 + { 1970 + GPU_PushErrorCode("GPU_AddDepthBuffer", GPU_ERROR_BACKEND_ERROR, "NULL context."); 1971 + return GPU_FALSE; 1972 + } 1973 + 1974 + if(isCurrentTarget(renderer, target)) 1975 + renderer->impl->FlushBlitBuffer(renderer); 1976 + 1977 + if(!bindFramebuffer(renderer, target)) 1978 + { 1979 + GPU_PushErrorCode("GPU_AddDepthBuffer", GPU_ERROR_BACKEND_ERROR, "Failed to bind target framebuffer."); 1980 + return GPU_FALSE; 1981 + } 1982 + 1983 + glGenRenderbuffers(1, &depth_buffer); 1984 + glBindRenderbuffer(GL_RENDERBUFFER, depth_buffer); 1985 + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, target->base_w, target->base_h); 1986 + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_buffer); 1987 + 1988 + status = glCheckFramebufferStatusPROC(GL_FRAMEBUFFER); 1989 + if(status != GL_FRAMEBUFFER_COMPLETE) 1990 + { 1991 + GPU_PushErrorCode("GPU_AddDepthBuffer", GPU_ERROR_BACKEND_ERROR, "Failed to attach depth buffer to target."); 1992 + return GPU_FALSE; 1993 + } 1994 + 1995 + 1996 + cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; 1997 + cdata->last_depth_write = target->use_depth_write; 1998 + glDepthMask(target->use_depth_write); 1999 + 2000 + GPU_SetDepthTest(target, 1); 2001 + 2002 + return GPU_TRUE; 2003 + #endif 2004 + } 2005 + 1957 2006 static GPU_bool SetWindowResolution(GPU_Renderer* renderer, Uint16 w, Uint16 h) 1958 2007 { 1959 2008 GPU_Target* target = renderer->current_context_target; ··· 3886 3935 3887 3936 result->camera = GPU_GetDefaultCamera(); 3888 3937 result->use_camera = GPU_TRUE; 3938 + 3939 + result->use_depth_test = GPU_FALSE; 3940 + result->use_depth_write = GPU_TRUE; 3889 3941 3890 3942 result->use_clip_rect = GPU_FALSE; 3891 3943 result->clip_rect.x = 0; ··· 6788 6840 impl->MakeCurrent = &MakeCurrent; \ 6789 6841 impl->SetAsCurrent = &SetAsCurrent; \ 6790 6842 impl->ResetRendererState = &ResetRendererState; \ 6843 + impl->AddDepthBuffer = &AddDepthBuffer; \ 6791 6844 impl->SetWindowResolution = &SetWindowResolution; \ 6792 6845 impl->SetVirtualResolution = &SetVirtualResolution; \ 6793 6846 impl->UnsetVirtualResolution = &UnsetVirtualResolution; \
+48 -13
tests/depth/main.c
··· 26 26 Uint8 done; 27 27 SDL_Event event; 28 28 GPU_Image* image; 29 + GPU_Image* target_image = GPU_CreateImage(screen->w, screen->h, GPU_FORMAT_RGBA); 30 + GPU_Target* target = GPU_LoadTarget(target_image); 31 + int mode = 0; 29 32 30 33 image = GPU_LoadImage(IMAGE_FILE); 31 34 if(image == NULL) ··· 34 37 return -1; 35 38 } 36 39 40 + GPU_SetAnchor(target_image, 0, 0); 41 + 37 42 startTime = SDL_GetTicks(); 38 43 frameCount = 0; 39 44 40 45 GPU_SetDepthTest(screen, 1); 46 + if(!GPU_AddDepthBuffer(target)) 47 + return -2; 41 48 42 49 done = 0; 43 50 while(!done) ··· 50 57 { 51 58 if(event.key.keysym.sym == SDLK_ESCAPE) 52 59 done = 1; 60 + if(event.key.keysym.sym == SDLK_SPACE) 61 + mode = !mode; 53 62 } 54 63 } 55 64 56 65 GPU_ClearRGB(screen, 200, 200, 200); 57 66 58 - // Images drawn left to right, but layered alternating. Positive z values are on top. 59 - GPU_Blit(image, NULL, screen, 150, 300); 60 - 61 - GPU_PushMatrix(); 62 - GPU_Translate(0, 0, 5); 63 - GPU_Blit(image, NULL, screen, 300, 300); 64 - 65 - GPU_Translate(0, 0, -10); 66 - GPU_Blit(image, NULL, screen, 450, 300); 67 - 68 - GPU_Translate(0, 0, 10); 69 - GPU_Blit(image, NULL, screen, 600, 300); 70 - GPU_PopMatrix(); 67 + if(!mode) 68 + { 69 + // Draw to screen directly 70 + 71 + // Images drawn left to right, but layered alternating. Positive z values are on top. 72 + GPU_Blit(image, NULL, screen, 150, 300); 73 + 74 + GPU_PushMatrix(); 75 + GPU_Translate(0, 0, 5); 76 + GPU_Blit(image, NULL, screen, 300, 300); 77 + 78 + GPU_Translate(0, 0, -10); 79 + GPU_Blit(image, NULL, screen, 450, 300); 80 + 81 + GPU_Translate(0, 0, 10); 82 + GPU_Blit(image, NULL, screen, 600, 300); 83 + GPU_PopMatrix(); 84 + } 85 + else 86 + { 87 + // Draw to temp buffer 88 + GPU_Clear(target); 89 + 90 + // Images drawn left to right, but layered alternating. Positive z values are on top. 91 + GPU_Blit(image, NULL, target, 150, 300); 92 + 93 + GPU_PushMatrix(); 94 + GPU_Translate(0, 0, 5); 95 + GPU_Blit(image, NULL, target, 300, 300); 96 + 97 + GPU_Translate(0, 0, -10); 98 + GPU_Blit(image, NULL, target, 450, 300); 99 + 100 + GPU_Translate(0, 0, 10); 101 + GPU_Blit(image, NULL, target, 600, 300); 102 + GPU_PopMatrix(); 103 + 104 + GPU_Blit(target_image, NULL, screen, 0, 0); 105 + } 71 106 72 107 GPU_Flip(screen); 73 108
+7
tests/renderer/main.c
··· 224 224 { 225 225 GPU_Log(" %s (dummy)\n", __func__); 226 226 } 227 + 228 + static GPU_bool AddDepthBuffer(GPU_Renderer* renderer, GPU_Target* target) 229 + { 230 + GPU_Log(" %s (dummy)\n", __func__); 231 + return GPU_TRUE; 232 + } 227 233 228 234 static GPU_bool SetWindowResolution(GPU_Renderer* renderer, Uint16 w, Uint16 h) 229 235 { ··· 1172 1178 impl->MakeCurrent = &MakeCurrent; 1173 1179 impl->SetAsCurrent = &SetAsCurrent; 1174 1180 impl->ResetRendererState = &ResetRendererState; 1181 + impl->AddDepthBuffer = &AddDepthBuffer; 1175 1182 impl->SetWindowResolution = &SetWindowResolution; 1176 1183 impl->SetVirtualResolution = &SetVirtualResolution; 1177 1184 impl->UnsetVirtualResolution = &UnsetVirtualResolution;