OSDN Git Service

Fix OGLES2HelloAPI and Vulkan build.
authorNicolas Capens <capn@google.com>
Fri, 26 Oct 2018 14:34:20 +0000 (10:34 -0400)
committerNicolas Capens <nicolascapens@google.com>
Fri, 26 Oct 2018 15:01:05 +0000 (15:01 +0000)
Assigning string literals to char* has been deprecated since C++98 and
is now an error in Visual Studio. Also, a goto which skips variable
nationalizations is an error now.

std::min/max are defined in <algorithm>

Bug swiftshader:121

Change-Id: Ic087706de810e68849eb021c1e0a9d2f2a960260
Reviewed-on: https://swiftshader-review.googlesource.com/c/21988
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
SwiftShader.sln
src/Vulkan/libVulkan.cpp
third_party/PowerVR_SDK/Examples/Beginner/01_HelloAPI/OGLES2/OGLES2HelloAPI_Windows.cpp

index 9b4895f..8c5b30d 100644 (file)
@@ -1,6 +1,6 @@
 Microsoft Visual Studio Solution File, Format Version 12.00\r
 # Visual Studio 15\r
-VisualStudioVersion = 15.0.27004.2002\r
+VisualStudioVersion = 15.0.27130.2036\r
 MinimumVisualStudioVersion = 10.0.40219.1\r
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LLVM", "LLVM", "{B408B98A-E888-4ECF-81E0-7A37A6854B17}"\r
 EndProject\r
index 4d1f44a..9e03912 100644 (file)
 #include "VkPhysicalDevice.hpp"
 #include "VkQueue.hpp"
 #include "VkSemaphore.hpp"
+
 #include <cstring>
 #include <string>
+#include <algorithm>
 
 extern "C"
 {
@@ -1688,7 +1690,7 @@ VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue2(VkDevice device, const VkDeviceQueu
                UNIMPLEMENTED();
        }
 
-       // The only flag that can be set here is VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT 
+       // The only flag that can be set here is VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT
        // According to the Vulkan spec, 4.3.1. Queue Family Properties:
        // "VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT specifies that the device queue is a
        //  protected-capable queue. If the protected memory feature is not enabled,
index 4f2a734..947861c 100644 (file)
@@ -4,7 +4,7 @@
 \r
  @Title        OpenGL ES 2.0 HelloAPI Tutorial\r
 \r
- @Version      \r
+ @Version\r
 \r
  @Copyright    Copyright (c) Imagination Technologies Limited.\r
 \r
@@ -90,7 +90,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  @Return               bool                    true if no EGL error was detected\r
  @Description  Tests for an EGL error and prints it\r
 ******************************************************************************/\r
-bool TestEGLError(HWND hWnd, char* pszLocation)\r
+bool TestEGLError(HWND hWnd, const char* pszLocation)\r
 {\r
        /*\r
                eglGetError returns the last error that has happened using egl,\r
@@ -110,6 +110,36 @@ bool TestEGLError(HWND hWnd, char* pszLocation)
 }\r
 \r
 /*!****************************************************************************\r
+ @Function             Cleanup\r
+ @Input                        eglDisplay              Handle to the EGL display\r
+ @Input                        hWnd                    Handle to the window\r
+ @Input                        hDC                             Handle to the device context\r
+ @Return               int                             result code to OS\r
+ @Description  Clean up before program termination on error or normal exit\r
+******************************************************************************/\r
+int Cleanup(EGLDisplay eglDisplay, HWND hWnd, HDC hDC)\r
+{\r
+       /*\r
+               eglTerminate takes care of destroying any context or surface created\r
+               with this display, so we don't need to call eglDestroySurface or\r
+               eglDestroyContext here.\r
+       */\r
+\r
+       eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);\r
+       eglTerminate(eglDisplay);\r
+\r
+       /*\r
+               Destroy the eglWindow.\r
+               This is platform specific and delegated to a separate function.\r
+       */\r
+\r
+       // Release the device context\r
+       if (hDC) ReleaseDC(hWnd, hDC);\r
+\r
+       return 0;\r
+}\r
+\r
+/*!****************************************************************************\r
  @Function             WinMain\r
  @Input                        hInstance               Application instance from OS\r
  @Input                        hPrevInstance   Always NULL\r
@@ -141,12 +171,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        };\r
 \r
        // Fragment and vertex shaders code\r
-       char* pszFragShader = "\\r
+       const char* pszFragShader = "\\r
                void main (void)\\r
                {\\r
                        gl_FragColor = vec4(1.0, 1.0, 0.66 ,1.0);\\r
                }";\r
-       char* pszVertShader = "\\r
+       const char* pszVertShader = "\\r
                attribute highp vec4    myVertex;\\r
                uniform mediump mat4    myPMVMatrix;\\r
                void main(void)\\r
@@ -192,7 +222,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        if (!hDC)\r
        {\r
                MessageBox(0, _T("Failed to create the device context"), _T("Error"), MB_OK|MB_ICONEXCLAMATION);\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -220,7 +250,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion))\r
        {\r
                MessageBox(0, _T("eglInitialize() failed."), _T("Error"), MB_OK|MB_ICONEXCLAMATION);\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -232,7 +262,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        eglBindAPI(EGL_OPENGL_ES_API);\r
        if (!TestEGLError(hWnd, "eglBindAPI"))\r
        {\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -264,7 +294,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))\r
        {\r
                MessageBox(0, _T("eglChooseConfig() failed."), _T("Error"), MB_OK|MB_ICONEXCLAMATION);\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -286,7 +316,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
 \r
        if (!TestEGLError(hWnd, "eglCreateWindowSurface"))\r
        {\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -299,7 +329,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32ContextAttribs);\r
        if (!TestEGLError(hWnd, "eglCreateContext"))\r
        {\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -315,7 +345,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
        eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);\r
        if (!TestEGLError(hWnd, "eglMakeCurrent"))\r
        {\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        /*\r
@@ -355,7 +385,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
                MessageBox(hWnd, i32InfoLogLength ? pszInfoLog : _T(""), _T("Failed to compile fragment shader"), MB_OK|MB_ICONEXCLAMATION);\r
                delete[] pszInfoLog;\r
 \r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        // Loads the vertex shader in the same way\r
@@ -375,7 +405,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
 \r
                delete[] pszInfoLog;\r
 \r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        // Create the shader program\r
@@ -404,7 +434,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
                MessageBox(hWnd, i32InfoLogLength ? pszInfoLog : _T(""), _T("Failed to link program"), MB_OK|MB_ICONEXCLAMATION);\r
 \r
                delete[] pszInfoLog;\r
-               goto cleanup;\r
+               return Cleanup(eglDisplay, hWnd, hDC);\r
        }\r
 \r
        // Actually use the created program\r
@@ -419,7 +449,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
 \r
        // We're going to draw a triangle to the screen so create a vertex buffer object for our triangle\r
        GLuint  ui32Vbo; // Vertex buffer object handle\r
-       \r
+\r
        // Interleaved vertex data\r
        GLfloat afVertices[] = {        -0.4f,-0.4f,0.0f, // Position\r
                                                                0.4f ,-0.4f,0.0f,\r
@@ -482,7 +512,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
                eglSwapBuffers(eglDisplay, eglSurface);\r
                if (!TestEGLError(hWnd, "eglSwapBuffers"))\r
                {\r
-                       goto cleanup;\r
+                       return Cleanup(eglDisplay, hWnd, hDC);\r
                }\r
 \r
                // Managing the window messages\r
@@ -503,24 +533,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLin
 \r
        /*\r
                Step 10 - Terminate OpenGL ES and destroy the window (if present).\r
-               eglTerminate takes care of destroying any context or surface created\r
-               with this display, so we don't need to call eglDestroySurface or\r
-               eglDestroyContext here.\r
-       */\r
-cleanup:\r
-       eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);\r
-       eglTerminate(eglDisplay);\r
-\r
-       /*\r
-               Step 11 - Destroy the eglWindow.\r
-               Again, this is platform specific and delegated to a separate function.\r
        */\r
-\r
-       // Release the device context\r
-       if (hDC) ReleaseDC(hWnd, hDC);\r
-\r
-       // Destroy the eglWindow\r
-       return 0;\r
+       return Cleanup(eglDisplay, hWnd, hDC);\r
 }\r
 \r
 /******************************************************************************\r