Commit 5378e142 by Nicolas Capens Committed by Nicolas Capens

Remove libGL project.

Change-Id: I36237afe7b01070cd665f4ab990e9d7cc87a6360 Reviewed-on: https://swiftshader-review.googlesource.com/c/21390Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent f417d9d7
...@@ -47,9 +47,6 @@ endif() ...@@ -47,9 +47,6 @@ endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
option(BUILD_EGL "Build the EGL library" 1) option(BUILD_EGL "Build the EGL library" 1)
if(WIN32)
option(BUILD_GL32 "Build the OpenGL32 library" 1)
endif()
option(BUILD_GLESv2 "Build the OpenGL ES 2 library" 1) option(BUILD_GLESv2 "Build the OpenGL ES 2 library" 1)
option(BUILD_GLES_CM "Build the OpenGL ES 1.1 library" 1) option(BUILD_GLES_CM "Build the OpenGL ES 1.1 library" 1)
option(BUILD_VULKAN "Build the Vulkan library" 1) option(BUILD_VULKAN "Build the Vulkan library" 1)
...@@ -1839,16 +1836,6 @@ file(GLOB_RECURSE EGL_LIST ...@@ -1839,16 +1836,6 @@ file(GLOB_RECURSE EGL_LIST
${CMAKE_SOURCE_DIR}/include/*.h ${CMAKE_SOURCE_DIR}/include/*.h
) )
file(GLOB_RECURSE GL32_LIST
${OPENGL_DIR}/libGL/*.cpp
${OPENGL_DIR}/libGL/*.h
${OPENGL_DIR}/libGL/*.hpp
${OPENGL_DIR}/common/*.cpp
${OPENGL_DIR}/common/*.h
${OPENGL_DIR}/common/*.hpp
${CMAKE_SOURCE_DIR}/include/GL/*.h
)
file(GLOB_RECURSE GLES2_LIST file(GLOB_RECURSE GLES2_LIST
${OPENGL_DIR}/libGLESv2/*.cpp ${OPENGL_DIR}/libGLESv2/*.cpp
${OPENGL_DIR}/libGLESv2/*.h ${OPENGL_DIR}/libGLESv2/*.h
...@@ -1905,7 +1892,6 @@ if(WIN32) ...@@ -1905,7 +1892,6 @@ if(WIN32)
) )
list(APPEND OPENGL_COMPILER_LIST ${OPENGL_COMPILER_DIR}/ossource_win.cpp) list(APPEND OPENGL_COMPILER_LIST ${OPENGL_COMPILER_DIR}/ossource_win.cpp)
list(APPEND EGL_LIST ${OPENGL_DIR}/libEGL/libEGL.rc) list(APPEND EGL_LIST ${OPENGL_DIR}/libEGL/libEGL.rc)
list(APPEND GL32_LIST ${OPENGL_DIR}/libGL/libGL.rc)
list(APPEND GLES2_LIST ${OPENGL_DIR}/libGLESv2/libGLESv2.rc) list(APPEND GLES2_LIST ${OPENGL_DIR}/libGLESv2/libGLESv2.rc)
list(APPEND GLES_CM_LIST ${OPENGL_DIR}/libGLES_CM/libGLES_CM.rc) list(APPEND GLES_CM_LIST ${OPENGL_DIR}/libGLES_CM/libGLES_CM.rc)
elseif(LINUX) elseif(LINUX)
...@@ -2013,18 +1999,6 @@ if(BUILD_EGL) ...@@ -2013,18 +1999,6 @@ if(BUILD_EGL)
) )
endif() endif()
if(BUILD_GL32)
add_library(libGL SHARED ${GL32_LIST})
set_target_properties(libGL PROPERTIES
INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
FOLDER "OpenGL"
COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES"
PREFIX ""
)
set_shared_library_export_map(libGL ${SOURCE_DIR}/OpenGL/libGL)
target_link_libraries(libGL SwiftShader ${Reactor} GLCompiler ${OS_LIBS})
endif()
if(BUILD_GLESv2) if(BUILD_GLESv2)
add_library(libGLESv2 SHARED ${GLES2_LIST}) add_library(libGLESv2 SHARED ${GLES2_LIST})
set_target_properties(libGLESv2 PROPERTIES set_target_properties(libGLESv2 PROPERTIES
......
...@@ -206,13 +206,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLES_CM", "src\OpenGL\li ...@@ -206,13 +206,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLES_CM", "src\OpenGL\li
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{B7E24D8E-6BE9-4DEF-A8B9-6A6E60CA60E9}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{B7E24D8E-6BE9-4DEF-A8B9-6A6E60CA60E9}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGL", "src\OpenGL\libGL\libGL.vcxproj", "{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLSimpleCube", "tests\OGLSimpleCube\OGLSimpleCube.vcxproj", "{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}"
ProjectSection(ProjectDependencies) = postProject
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67} = {3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D3D9", "src\D3D9\D3D9.vcxproj", "{F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D3D9", "src\D3D9\D3D9.vcxproj", "{F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2ChameleonMan", "third_party\PowerVR_SDK\Examples\Advanced\ChameleonMan\OGLES2\Build\WindowsVC2010\OGLES2ChameleonMan.vcxproj", "{9CF4408B-9B08-481F-95DA-3DF0846DABE4}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2ChameleonMan", "third_party\PowerVR_SDK\Examples\Advanced\ChameleonMan\OGLES2\Build\WindowsVC2010\OGLES2ChameleonMan.vcxproj", "{9CF4408B-9B08-481F-95DA-3DF0846DABE4}"
...@@ -613,30 +606,6 @@ Global ...@@ -613,30 +606,6 @@ Global
{235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|Win32.Build.0 = Release|Win32 {235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|Win32.Build.0 = Release|Win32
{235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|x64.ActiveCfg = Release|x64 {235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|x64.ActiveCfg = Release|x64
{235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|x64.Build.0 = Release|x64 {235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|x64.Build.0 = Release|x64
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Debug|Win32.ActiveCfg = Debug|Win32
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Debug|Win32.Build.0 = Debug|Win32
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Debug|x64.ActiveCfg = Debug|x64
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Debug|x64.Build.0 = Debug|x64
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Profile|Win32.ActiveCfg = Profile|Win32
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Profile|Win32.Build.0 = Profile|Win32
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Profile|x64.ActiveCfg = Profile|x64
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Profile|x64.Build.0 = Profile|x64
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Release|Win32.ActiveCfg = Release|Win32
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Release|Win32.Build.0 = Release|Win32
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Release|x64.ActiveCfg = Release|x64
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67}.Release|x64.Build.0 = Release|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|Win32.ActiveCfg = Debug|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|Win32.Build.0 = Debug|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|x64.ActiveCfg = Debug|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Debug|x64.Build.0 = Debug|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|Win32.ActiveCfg = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|Win32.Build.0 = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|x64.ActiveCfg = Release|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Profile|x64.Build.0 = Release|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|Win32.ActiveCfg = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|Win32.Build.0 = Release|Win32
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|x64.ActiveCfg = Release|x64
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747}.Release|x64.Build.0 = Release|x64
{F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}.Debug|Win32.ActiveCfg = Debug|Win32 {F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}.Debug|Win32.ActiveCfg = Debug|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}.Debug|Win32.Build.0 = Debug|Win32 {F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}.Debug|Win32.Build.0 = Debug|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}.Debug|x64.ActiveCfg = Debug|x64 {F18D5ABF-CA3A-4B74-BDB2-4A1957C86F18}.Debug|x64.ActiveCfg = Debug|x64
...@@ -846,8 +815,6 @@ Global ...@@ -846,8 +815,6 @@ Global
{92940255-AB4B-42FB-A2C4-0FAB19C3C48A} = {D33114D7-E582-4D61-B27D-FAB0297C43FF} {92940255-AB4B-42FB-A2C4-0FAB19C3C48A} = {D33114D7-E582-4D61-B27D-FAB0297C43FF}
{235B1D85-E6B6-45E2-BA5D-5C60396428FF} = {D33114D7-E582-4D61-B27D-FAB0297C43FF} {235B1D85-E6B6-45E2-BA5D-5C60396428FF} = {D33114D7-E582-4D61-B27D-FAB0297C43FF}
{B7E24D8E-6BE9-4DEF-A8B9-6A6E60CA60E9} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {B7E24D8E-6BE9-4DEF-A8B9-6A6E60CA60E9} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{3EF851E7-4AAB-4C7C-9A79-3122CEA1EB67} = {D33114D7-E582-4D61-B27D-FAB0297C43FF}
{27E15292-4A8D-4BA0-8D9B-5D1ECFF85747} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{9CF4408B-9B08-481F-95DA-3DF0846DABE4} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {9CF4408B-9B08-481F-95DA-3DF0846DABE4} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{9DAFEE32-19F6-4410-AA09-2B564FB86F62} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {9DAFEE32-19F6-4410-AA09-2B564FB86F62} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Buffer.cpp: Implements the Buffer class, representing storage of vertex and/or
// index data. Implements GL buffer objects and related functionality.
#include "Buffer.h"
#include "main.h"
#include "VertexDataManager.h"
#include "IndexDataManager.h"
namespace gl
{
Buffer::Buffer(GLuint name) : NamedObject(name)
{
mContents = 0;
mSize = 0;
mUsage = GL_DYNAMIC_DRAW;
}
Buffer::~Buffer()
{
if(mContents)
{
mContents->destruct();
}
}
void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage)
{
if(mContents)
{
mContents->destruct();
mContents = 0;
}
mSize = size;
mUsage = usage;
if(size > 0)
{
const int padding = 1024; // For SIMD processing of vertices
mContents = new sw::Resource(size + padding);
if(!mContents)
{
return error(GL_OUT_OF_MEMORY);
}
if(data)
{
memcpy((void*)mContents->data(), data, size);
}
}
}
void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset)
{
if(mContents)
{
char *buffer = (char*)mContents->lock(sw::PUBLIC);
memcpy(buffer + offset, data, size);
mContents->unlock();
}
}
sw::Resource *Buffer::getResource()
{
return mContents;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Buffer.h: Defines the Buffer class, representing storage of vertex and/or
// index data. Implements GL buffer objects and related functionality.
#ifndef LIBGL_BUFFER_H_
#define LIBGL_BUFFER_H_
#include "common/Object.hpp"
#include "Common/Resource.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
#include <cstddef>
#include <vector>
namespace gl
{
class Buffer : public NamedObject
{
public:
explicit Buffer(GLuint name);
virtual ~Buffer();
void bufferData(const void *data, GLsizeiptr size, GLenum usage);
void bufferSubData(const void *data, GLsizeiptr size, GLintptr offset);
const void *data() { return mContents ? mContents->data() : 0; }
size_t size() const { return mSize; }
GLenum usage() const { return mUsage; }
sw::Resource *getResource();
private:
sw::Resource *mContents;
size_t mSize;
GLenum mUsage;
};
}
#endif // LIBGL_BUFFER_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef gl_Device_hpp
#define gl_Device_hpp
#include "Renderer/Renderer.hpp"
namespace gl
{
class Image;
class Texture;
enum PrimitiveType
{
DRAW_POINTLIST,
DRAW_LINELIST,
DRAW_LINESTRIP,
DRAW_LINELOOP,
DRAW_TRIANGLELIST,
DRAW_TRIANGLESTRIP,
DRAW_TRIANGLEFAN,
DRAW_QUADLIST
};
struct Viewport
{
int x0;
int y0;
unsigned int width;
unsigned int height;
float minZ;
float maxZ;
};
class Device : public sw::Renderer
{
public:
explicit Device(sw::Context *context);
virtual ~Device();
void *operator new(size_t size);
void operator delete(void * mem);
void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask);
void clearDepth(float z);
void clearStencil(unsigned int stencil, unsigned int mask);
Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize);
void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount);
void setDepthStencilSurface(Image *newDepthStencil);
void setPixelShader(sw::PixelShader *shader);
void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
void setScissorEnable(bool enable);
void setRenderTarget(int index, Image *renderTarget);
void setScissorRect(const sw::Rect &rect);
void setVertexShader(sw::VertexShader *shader);
void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
void setViewport(const Viewport &viewport);
virtual bool stretchRect(Image *sourceSurface, const sw::SliceRect *sourceRect, Image *destSurface, const sw::SliceRect *destRect, bool filter);
virtual void finish();
private:
sw::Context *const context;
bool bindResources();
void bindShaderConstants();
bool bindViewport(); // Also adjusts for scissoring
bool validRectangle(const sw::Rect *rect, Image *surface);
Viewport viewport;
sw::Rect scissorRect;
bool scissorEnable;
sw::PixelShader *pixelShader;
sw::VertexShader *vertexShader;
bool pixelShaderDirty;
unsigned int pixelShaderConstantsFDirty;
bool vertexShaderDirty;
unsigned int vertexShaderConstantsFDirty;
float pixelShaderConstantF[sw::FRAGMENT_UNIFORM_VECTORS][4];
float vertexShaderConstantF[sw::VERTEX_UNIFORM_VECTORS][4];
Image *renderTarget;
Image *depthStencil;
};
}
#endif // gl_Device_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Display.cpp: Implements the Display class, representing the abstract
// display on which graphics are drawn.
#include "Display.h"
#include "main.h"
#include "mathutil.h"
#include "Device.hpp"
#include "common/debug.h"
#include <algorithm>
#include <vector>
#include <map>
namespace gl
{
typedef std::map<NativeDisplayType, Display*> DisplayMap;
DisplayMap displays;
Display *Display::getDisplay(NativeDisplayType displayId)
{
if(displays.find(displayId) != displays.end())
{
return displays[displayId];
}
// FIXME: Check if displayId is a valid display device context
Display *display = new Display(displayId);
displays[displayId] = display;
return display;
}
Display::Display(NativeDisplayType displayId) : displayId(displayId)
{
mMinSwapInterval = 1;
mMaxSwapInterval = 0;
}
Display::~Display()
{
terminate();
displays.erase(displayId);
}
static void cpuid(int registers[4], int info)
{
#if defined(_WIN32)
__cpuid(registers, info);
#else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#endif
}
static bool detectSSE()
{
#if defined(__APPLE__)
int SSE = false;
size_t length = sizeof(SSE);
sysctlbyname("hw.optional.sse", &SSE, &length, 0, 0);
return SSE;
#else
int registers[4];
cpuid(registers, 1);
return (registers[3] & 0x02000000) != 0;
#endif
}
bool Display::initialize()
{
if(isInitialized())
{
return true;
}
if(!detectSSE())
{
return false;
}
mMinSwapInterval = 0;
mMaxSwapInterval = 4;
if(!isInitialized())
{
terminate();
return false;
}
return true;
}
void Display::terminate()
{
while(!mSurfaceSet.empty())
{
destroySurface(*mSurfaceSet.begin());
}
while(!mContextSet.empty())
{
destroyContext(*mContextSet.begin());
}
}
gl::Context *Display::createContext(const gl::Context *shareContext)
{
gl::Context *context = new gl::Context(shareContext);
mContextSet.insert(context);
return context;
}
void Display::destroySurface(Surface *surface)
{
delete surface;
mSurfaceSet.erase(surface);
}
void Display::destroyContext(gl::Context *context)
{
delete context;
if(context == gl::getContext())
{
gl::makeCurrent(nullptr, nullptr, nullptr);
}
mContextSet.erase(context);
}
bool Display::isInitialized() const
{
return mMinSwapInterval <= mMaxSwapInterval;
}
bool Display::isValidContext(gl::Context *context)
{
return mContextSet.find(context) != mContextSet.end();
}
bool Display::isValidSurface(Surface *surface)
{
return mSurfaceSet.find(surface) != mSurfaceSet.end();
}
bool Display::isValidWindow(NativeWindowType window)
{
#if defined(_WIN32)
return IsWindow(window) == TRUE;
#else
XWindowAttributes windowAttributes;
Status status = XGetWindowAttributes(displayId, window, &windowAttributes);
return status == True;
#endif
}
GLint Display::getMinSwapInterval()
{
return mMinSwapInterval;
}
GLint Display::getMaxSwapInterval()
{
return mMaxSwapInterval;
}
Surface *Display::getPrimarySurface()
{
if(mSurfaceSet.size() == 0)
{
Surface *surface = new Surface(this, WindowFromDC(displayId));
if(!surface->initialize())
{
delete surface;
return 0;
}
mSurfaceSet.insert(surface);
gl::setCurrentDrawSurface(surface);
}
return *mSurfaceSet.begin();
}
NativeDisplayType Display::getNativeDisplay() const
{
return displayId;
}
DisplayMode Display::getDisplayMode() const
{
DisplayMode displayMode = {0};
#if defined(_WIN32)
HDC deviceContext = GetDC(0);
displayMode.width = ::GetDeviceCaps(deviceContext, HORZRES);
displayMode.height = ::GetDeviceCaps(deviceContext, VERTRES);
unsigned int bpp = ::GetDeviceCaps(deviceContext, BITSPIXEL);
switch(bpp)
{
case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break;
case 24: displayMode.format = sw::FORMAT_R8G8B8; break;
case 16: displayMode.format = sw::FORMAT_R5G6B5; break;
default:
ASSERT(false); // Unexpected display mode color depth
}
ReleaseDC(0, deviceContext);
#else
Screen *screen = XDefaultScreenOfDisplay(displayId);
displayMode.width = XWidthOfScreen(screen);
displayMode.height = XHeightOfScreen(screen);
unsigned int bpp = XPlanesOfScreen(screen);
switch(bpp)
{
case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break;
case 24: displayMode.format = sw::FORMAT_R8G8B8; break;
case 16: displayMode.format = sw::FORMAT_R5G6B5; break;
default:
ASSERT(false); // Unexpected display mode color depth
}
#endif
return displayMode;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Display.h: Defines the Display class, representing the abstract
// display on which graphics are drawn.
#ifndef INCLUDE_DISPLAY_H_
#define INCLUDE_DISPLAY_H_
#include "Surface.h"
#include "Context.h"
#include "Device.hpp"
#include <set>
namespace gl
{
struct DisplayMode
{
unsigned int width;
unsigned int height;
sw::Format format;
};
class Display
{
public:
~Display();
static Display *getDisplay(NativeDisplayType displayId);
bool initialize();
void terminate();
Context *createContext(const Context *shareContext);
void destroySurface(Surface *surface);
void destroyContext(Context *context);
bool isInitialized() const;
bool isValidContext(Context *context);
bool isValidSurface(Surface *surface);
bool isValidWindow(NativeWindowType window);
GLint getMinSwapInterval();
GLint getMaxSwapInterval();
virtual Surface *getPrimarySurface();
NativeDisplayType getNativeDisplay() const;
private:
Display(NativeDisplayType displayId);
DisplayMode getDisplayMode() const;
const NativeDisplayType displayId;
GLint mMaxSwapInterval;
GLint mMinSwapInterval;
typedef std::set<Surface*> SurfaceSet;
SurfaceSet mSurfaceSet;
typedef std::set<Context*> ContextSet;
ContextSet mContextSet;
};
}
#endif // INCLUDE_DISPLAY_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Fence.cpp: Implements the Fence class, which supports the GL_NV_fence extension.
#include "Fence.h"
#include "main.h"
#include "Common/Thread.hpp"
namespace gl
{
Fence::Fence()
{
mQuery = false;
mCondition = GL_NONE;
mStatus = GL_FALSE;
}
Fence::~Fence()
{
mQuery = false;
}
GLboolean Fence::isFence()
{
// GL_NV_fence spec:
// A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence.
return mQuery;
}
void Fence::setFence(GLenum condition)
{
if(condition != GL_ALL_COMPLETED_NV)
{
return error(GL_INVALID_VALUE);
}
mQuery = true;
mCondition = condition;
mStatus = GL_FALSE;
}
GLboolean Fence::testFence()
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION, GL_TRUE);
}
// The current assumtion is that no matter where the fence is placed, it is
// done by the time it is tested, which is similar to Context::flush(), since
// we don't queue anything without processing it as fast as possible.
mStatus = GL_TRUE;
return mStatus;
}
void Fence::finishFence()
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION);
}
while(!testFence())
{
sw::Thread::yield();
}
}
void Fence::getFenceiv(GLenum pname, GLint *params)
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION);
}
switch(pname)
{
case GL_FENCE_STATUS_NV:
{
// GL_NV_fence spec:
// Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV
// or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
if(mStatus)
{
params[0] = GL_TRUE;
return;
}
mStatus = testFence();
params[0] = mStatus;
break;
}
case GL_FENCE_CONDITION_NV:
params[0] = mCondition;
break;
default:
return error(GL_INVALID_ENUM);
break;
}
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Fence.h: Defines the Fence class, which supports the GL_NV_fence extension.
#ifndef LIBGL_FENCE_H_
#define LIBGL_FENCE_H_
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
class Fence
{
public:
Fence();
virtual ~Fence();
GLboolean isFence();
void setFence(GLenum condition);
GLboolean testFence();
void finishFence();
void getFenceiv(GLenum pname, GLint *params);
private:
bool mQuery;
GLenum mCondition;
GLboolean mStatus;
};
}
#endif // LIBGL_FENCE_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Framebuffer.cpp: Implements the Framebuffer class. Implements GL framebuffer
// objects and related functionality.
#include "Framebuffer.h"
#include "main.h"
#include "Renderbuffer.h"
#include "Texture.h"
#include "utilities.h"
namespace gl
{
Framebuffer::Framebuffer()
{
mColorbufferType = GL_NONE;
mDepthbufferType = GL_NONE;
mStencilbufferType = GL_NONE;
}
Framebuffer::~Framebuffer()
{
mColorbufferPointer = nullptr;
mDepthbufferPointer = nullptr;
mStencilbufferPointer = nullptr;
}
Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const
{
Context *context = getContext();
Renderbuffer *buffer = nullptr;
if(type == GL_NONE)
{
buffer = nullptr;
}
else if(type == GL_RENDERBUFFER)
{
buffer = context->getRenderbuffer(handle);
}
else if(IsTextureTarget(type))
{
buffer = context->getTexture(handle)->getRenderbuffer(type);
}
else UNREACHABLE(type);
return buffer;
}
void Framebuffer::setColorbuffer(GLenum type, GLuint colorbuffer)
{
mColorbufferType = (colorbuffer != 0) ? type : GL_NONE;
mColorbufferPointer = lookupRenderbuffer(type, colorbuffer);
}
void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer)
{
mDepthbufferType = (depthbuffer != 0) ? type : GL_NONE;
mDepthbufferPointer = lookupRenderbuffer(type, depthbuffer);
}
void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer)
{
mStencilbufferType = (stencilbuffer != 0) ? type : GL_NONE;
mStencilbufferPointer = lookupRenderbuffer(type, stencilbuffer);
}
void Framebuffer::detachTexture(GLuint texture)
{
if(mColorbufferPointer.name() == texture && IsTextureTarget(mColorbufferType))
{
mColorbufferType = GL_NONE;
mColorbufferPointer = nullptr;
}
if(mDepthbufferPointer.name() == texture && IsTextureTarget(mDepthbufferType))
{
mDepthbufferType = GL_NONE;
mDepthbufferPointer = nullptr;
}
if(mStencilbufferPointer.name() == texture && IsTextureTarget(mStencilbufferType))
{
mStencilbufferType = GL_NONE;
mStencilbufferPointer = nullptr;
}
}
void Framebuffer::detachRenderbuffer(GLuint renderbuffer)
{
if(mColorbufferPointer.name() == renderbuffer && mColorbufferType == GL_RENDERBUFFER)
{
mColorbufferType = GL_NONE;
mColorbufferPointer = nullptr;
}
if(mDepthbufferPointer.name() == renderbuffer && mDepthbufferType == GL_RENDERBUFFER)
{
mDepthbufferType = GL_NONE;
mDepthbufferPointer = nullptr;
}
if(mStencilbufferPointer.name() == renderbuffer && mStencilbufferType == GL_RENDERBUFFER)
{
mStencilbufferType = GL_NONE;
mStencilbufferPointer = nullptr;
}
}
// Increments refcount on surface.
// caller must Release() the returned surface
Image *Framebuffer::getRenderTarget()
{
Renderbuffer *colorbuffer = mColorbufferPointer;
if(colorbuffer)
{
return colorbuffer->getRenderTarget();
}
return nullptr;
}
// Increments refcount on surface.
// caller must Release() the returned surface
Image *Framebuffer::getDepthStencil()
{
Renderbuffer *depthstencilbuffer = mDepthbufferPointer;
if(!depthstencilbuffer)
{
depthstencilbuffer = mStencilbufferPointer;
}
if(depthstencilbuffer)
{
return depthstencilbuffer->getRenderTarget();
}
return nullptr;
}
Renderbuffer *Framebuffer::getColorbuffer()
{
return mColorbufferPointer;
}
Renderbuffer *Framebuffer::getDepthbuffer()
{
return mDepthbufferPointer;
}
Renderbuffer *Framebuffer::getStencilbuffer()
{
return mStencilbufferPointer;
}
GLenum Framebuffer::getColorbufferType()
{
return mColorbufferType;
}
GLenum Framebuffer::getDepthbufferType()
{
return mDepthbufferType;
}
GLenum Framebuffer::getStencilbufferType()
{
return mStencilbufferType;
}
GLuint Framebuffer::getColorbufferName()
{
return mColorbufferPointer.name();
}
GLuint Framebuffer::getDepthbufferName()
{
return mDepthbufferPointer.name();
}
GLuint Framebuffer::getStencilbufferName()
{
return mStencilbufferPointer.name();
}
bool Framebuffer::hasStencil()
{
if(mStencilbufferType != GL_NONE)
{
Renderbuffer *stencilbufferObject = getStencilbuffer();
if(stencilbufferObject)
{
return stencilbufferObject->getStencilSize() > 0;
}
}
return false;
}
GLenum Framebuffer::completeness()
{
int width;
int height;
int samples;
return completeness(width, height, samples);
}
GLenum Framebuffer::completeness(int &width, int &height, int &samples)
{
width = -1;
height = -1;
samples = -1;
if(mColorbufferType != GL_NONE)
{
Renderbuffer *colorbuffer = getColorbuffer();
if(!colorbuffer)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(mColorbufferType == GL_RENDERBUFFER)
{
if(!gl::IsColorRenderable(colorbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if(IsTextureTarget(mColorbufferType))
{
GLenum format = colorbuffer->getFormat();
if(IsCompressed(format) ||
format == GL_ALPHA ||
format == GL_LUMINANCE ||
format == GL_LUMINANCE_ALPHA)
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
if(gl::IsDepthTexture(format) || gl::IsStencilTexture(format))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else
{
UNREACHABLE(mColorbufferType);
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
width = colorbuffer->getWidth();
height = colorbuffer->getHeight();
samples = colorbuffer->getSamples();
}
Renderbuffer *depthbuffer = nullptr;
Renderbuffer *stencilbuffer = nullptr;
if(mDepthbufferType != GL_NONE)
{
depthbuffer = getDepthbuffer();
if(!depthbuffer)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(depthbuffer->getWidth() == 0 || depthbuffer->getHeight() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(mDepthbufferType == GL_RENDERBUFFER)
{
if(!gl::IsDepthRenderable(depthbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if(IsTextureTarget(mDepthbufferType))
{
if(!gl::IsDepthTexture(depthbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else
{
UNREACHABLE(mDepthbufferType);
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(width == -1 || height == -1)
{
width = depthbuffer->getWidth();
height = depthbuffer->getHeight();
samples = depthbuffer->getSamples();
}
else if(width != depthbuffer->getWidth() || height != depthbuffer->getHeight())
{
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
}
else if(samples != depthbuffer->getSamples())
{
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT;
}
}
if(mStencilbufferType != GL_NONE)
{
stencilbuffer = getStencilbuffer();
if(!stencilbuffer)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(stencilbuffer->getWidth() == 0 || stencilbuffer->getHeight() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(mStencilbufferType == GL_RENDERBUFFER)
{
if(!gl::IsStencilRenderable(stencilbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if(IsTextureTarget(mStencilbufferType))
{
GLenum internalformat = stencilbuffer->getFormat();
if(!gl::IsStencilTexture(internalformat))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else
{
UNREACHABLE(mStencilbufferType);
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(width == -1 || height == -1)
{
width = stencilbuffer->getWidth();
height = stencilbuffer->getHeight();
samples = stencilbuffer->getSamples();
}
else if(width != stencilbuffer->getWidth() || height != stencilbuffer->getHeight())
{
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
}
else if(samples != stencilbuffer->getSamples())
{
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT;
}
}
// If we have both a depth and stencil buffer, they must refer to the same object
// since we only support packed_depth_stencil and not separate depth and stencil
if(depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer))
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
// We need to have at least one attachment to be complete
if(width == -1 || height == -1)
{
return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
}
return GL_FRAMEBUFFER_COMPLETE;
}
DefaultFramebuffer::DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil)
{
mColorbufferPointer = new Renderbuffer(0, colorbuffer);
Renderbuffer *depthStencilRenderbuffer = new Renderbuffer(0, depthStencil);
mDepthbufferPointer = depthStencilRenderbuffer;
mStencilbufferPointer = depthStencilRenderbuffer;
mColorbufferType = GL_RENDERBUFFER;
mDepthbufferType = (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE;
mStencilbufferType = (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE;
}
GLenum DefaultFramebuffer::completeness()
{
// The default framebuffer should always be complete
ASSERT(Framebuffer::completeness() == GL_FRAMEBUFFER_COMPLETE);
return GL_FRAMEBUFFER_COMPLETE;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Framebuffer.h: Defines the Framebuffer class. Implements GL framebuffer
// objects and related functionality.
#ifndef LIBGL_FRAMEBUFFER_H_
#define LIBGL_FRAMEBUFFER_H_
#include "common/Object.hpp"
#include "Image.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
class Renderbuffer;
class Colorbuffer;
class Depthbuffer;
class Stencilbuffer;
class DepthStencilbuffer;
class Framebuffer
{
public:
Framebuffer();
virtual ~Framebuffer();
void setColorbuffer(GLenum type, GLuint colorbuffer);
void setDepthbuffer(GLenum type, GLuint depthbuffer);
void setStencilbuffer(GLenum type, GLuint stencilbuffer);
void detachTexture(GLuint texture);
void detachRenderbuffer(GLuint renderbuffer);
Image *getRenderTarget();
Image *getDepthStencil();
Renderbuffer *getColorbuffer();
Renderbuffer *getDepthbuffer();
Renderbuffer *getStencilbuffer();
GLenum getColorbufferType();
GLenum getDepthbufferType();
GLenum getStencilbufferType();
GLuint getColorbufferName();
GLuint getDepthbufferName();
GLuint getStencilbufferName();
bool hasStencil();
virtual GLenum completeness();
GLenum completeness(int &width, int &height, int &samples);
protected:
GLenum mColorbufferType;
BindingPointer<Renderbuffer> mColorbufferPointer;
GLenum mDepthbufferType;
BindingPointer<Renderbuffer> mDepthbufferPointer;
GLenum mStencilbufferType;
BindingPointer<Renderbuffer> mStencilbufferPointer;
private:
Renderbuffer *lookupRenderbuffer(GLenum type, GLuint handle) const;
};
class DefaultFramebuffer : public Framebuffer
{
public:
DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
virtual GLenum completeness();
};
}
#endif // LIBGL_FRAMEBUFFER_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef gl_Image_hpp
#define gl_Image_hpp
#include "Renderer/Surface.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
class Texture;
class Image : public sw::Surface
{
public:
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget);
void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
void *lock(unsigned int left, unsigned int top, sw::Lock lock);
unsigned int getPitch() const;
void unlock();
void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) override;
void unlockInternal() override;
int getWidth();
int getHeight();
GLenum getFormat();
GLenum getType();
virtual sw::Format getInternalFormat();
int getMultiSampleDepth();
virtual void addRef();
virtual void release();
void unbind(); // Break parent ownership and release
static sw::Format selectInternalFormat(GLenum format, GLenum type);
private:
~Image() override;
void loadAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGB565ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBA4444ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBA5551ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadBGRAImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD16ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD32ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer);
Texture *parentTexture;
const GLsizei width;
const GLsizei height;
const GLenum format;
const GLenum type;
const sw::Format internalFormat;
const int multiSampleDepth;
volatile int referenceCount;
};
}
#endif // gl_Image_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// IndexDataManager.cpp: Defines the IndexDataManager, a class that
// runs the Buffer translation process for index buffers.
#include "IndexDataManager.h"
#include "Buffer.h"
#include "common/debug.h"
#include <string.h>
#include <algorithm>
namespace
{
enum { INITIAL_INDEX_BUFFER_SIZE = 4096 * sizeof(GLuint) };
}
namespace gl
{
IndexDataManager::IndexDataManager()
{
mStreamingBuffer = new StreamingIndexBuffer(INITIAL_INDEX_BUFFER_SIZE);
if(!mStreamingBuffer)
{
ERR("Failed to allocate the streaming index buffer.");
}
}
IndexDataManager::~IndexDataManager()
{
delete mStreamingBuffer;
}
void copyIndices(GLenum type, const void *input, GLsizei count, void *output)
{
if(type == GL_UNSIGNED_BYTE)
{
memcpy(output, input, count * sizeof(GLubyte));
}
else if(type == GL_UNSIGNED_INT)
{
memcpy(output, input, count * sizeof(GLuint));
}
else if(type == GL_UNSIGNED_SHORT)
{
memcpy(output, input, count * sizeof(GLushort));
}
else UNREACHABLE(type);
}
template<class IndexType>
void computeRange(const IndexType *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex)
{
*minIndex = indices[0];
*maxIndex = indices[0];
for(GLsizei i = 0; i < count; i++)
{
if(*minIndex > indices[i]) *minIndex = indices[i];
if(*maxIndex < indices[i]) *maxIndex = indices[i];
}
}
void computeRange(GLenum type, const void *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex)
{
if(type == GL_UNSIGNED_BYTE)
{
computeRange(static_cast<const GLubyte*>(indices), count, minIndex, maxIndex);
}
else if(type == GL_UNSIGNED_INT)
{
computeRange(static_cast<const GLuint*>(indices), count, minIndex, maxIndex);
}
else if(type == GL_UNSIGNED_SHORT)
{
computeRange(static_cast<const GLushort*>(indices), count, minIndex, maxIndex);
}
else UNREACHABLE(type);
}
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)
{
if(!mStreamingBuffer)
{
return GL_OUT_OF_MEMORY;
}
intptr_t offset = reinterpret_cast<intptr_t>(indices);
bool alignedOffset = false;
if(buffer)
{
switch(type)
{
case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break;
case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break;
case GL_UNSIGNED_INT: alignedOffset = (offset % sizeof(GLuint) == 0); break;
default: UNREACHABLE(type); alignedOffset = false;
}
if(typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size()))
{
return GL_INVALID_OPERATION;
}
indices = static_cast<const GLubyte*>(buffer->data()) + offset;
}
StreamingIndexBuffer *streamingBuffer = mStreamingBuffer;
sw::Resource *staticBuffer = buffer ? buffer->getResource() : nullptr;
if(staticBuffer)
{
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
translated->indexBuffer = staticBuffer;
translated->indexOffset = offset;
}
else
{
unsigned int streamOffset = 0;
int convertCount = count;
streamingBuffer->reserveSpace(convertCount * typeSize(type), type);
void *output = streamingBuffer->map(typeSize(type) * convertCount, &streamOffset);
if(!output)
{
ERR("Failed to map index buffer.");
return GL_OUT_OF_MEMORY;
}
copyIndices(type, staticBuffer ? buffer->data() : indices, convertCount, output);
streamingBuffer->unmap();
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
translated->indexBuffer = streamingBuffer->getResource();
translated->indexOffset = streamOffset;
}
return GL_NO_ERROR;
}
std::size_t IndexDataManager::typeSize(GLenum type)
{
switch(type)
{
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
default: UNREACHABLE(type); return sizeof(GLushort);
}
}
StreamingIndexBuffer::StreamingIndexBuffer(unsigned int initialSize) : mIndexBuffer(nullptr), mBufferSize(initialSize)
{
if(initialSize > 0)
{
mIndexBuffer = new sw::Resource(initialSize + 16);
if(!mIndexBuffer)
{
ERR("Out of memory allocating an index buffer of size %u.", initialSize);
}
}
mWritePosition = 0;
}
StreamingIndexBuffer::~StreamingIndexBuffer()
{
if(mIndexBuffer)
{
mIndexBuffer->destruct();
}
}
void *StreamingIndexBuffer::map(unsigned int requiredSpace, unsigned int *offset)
{
void *mapPtr = nullptr;
if(mIndexBuffer)
{
mapPtr = (char*)mIndexBuffer->lock(sw::PUBLIC) + mWritePosition;
if(!mapPtr)
{
ERR(" Lock failed");
return nullptr;
}
*offset = mWritePosition;
mWritePosition += requiredSpace;
}
return mapPtr;
}
void StreamingIndexBuffer::unmap()
{
if(mIndexBuffer)
{
mIndexBuffer->unlock();
}
}
void StreamingIndexBuffer::reserveSpace(unsigned int requiredSpace, GLenum type)
{
if(requiredSpace > mBufferSize)
{
if(mIndexBuffer)
{
mIndexBuffer->destruct();
mIndexBuffer = 0;
}
mBufferSize = std::max(requiredSpace, 2 * mBufferSize);
mIndexBuffer = new sw::Resource(mBufferSize + 16);
if(!mIndexBuffer)
{
ERR("Out of memory allocating an index buffer of size %u.", mBufferSize);
}
mWritePosition = 0;
}
else if(mWritePosition + requiredSpace > mBufferSize) // Recycle
{
if(mIndexBuffer)
{
mIndexBuffer->destruct();
mIndexBuffer = new sw::Resource(mBufferSize + 16);
}
mWritePosition = 0;
}
}
sw::Resource *StreamingIndexBuffer::getResource() const
{
return mIndexBuffer;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// IndexDataManager.h: Defines the IndexDataManager, a class that
// runs the Buffer translation process for index buffers.
#ifndef LIBGL_INDEXDATAMANAGER_H_
#define LIBGL_INDEXDATAMANAGER_H_
#include "Context.h"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
struct TranslatedIndexData
{
unsigned int minIndex;
unsigned int maxIndex;
unsigned int indexOffset;
sw::Resource *indexBuffer;
};
class StreamingIndexBuffer
{
public:
StreamingIndexBuffer(unsigned int initialSize);
virtual ~StreamingIndexBuffer();
void *map(unsigned int requiredSpace, unsigned int *offset);
void unmap();
void reserveSpace(unsigned int requiredSpace, GLenum type);
sw::Resource *getResource() const;
private:
sw::Resource *mIndexBuffer;
unsigned int mBufferSize;
unsigned int mWritePosition;
};
class IndexDataManager
{
public:
IndexDataManager();
virtual ~IndexDataManager();
GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);
static std::size_t typeSize(GLenum type);
private:
StreamingIndexBuffer *mStreamingBuffer;
};
}
#endif // LIBGL_INDEXDATAMANAGER_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Program.h: Defines the Program class. Implements GL program objects
// and related functionality.
#ifndef LIBGL_PROGRAM_H_
#define LIBGL_PROGRAM_H_
#include "Shader.h"
#include "Context.h"
#include "Shader/PixelShader.hpp"
#include "Shader/VertexShader.hpp"
#include <string>
#include <vector>
#include <set>
namespace gl
{
class Device;
class ResourceManager;
class FragmentShader;
class VertexShader;
// Helper struct representing a single shader uniform
struct Uniform
{
Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize);
~Uniform();
bool isArray() const;
int size() const;
int registerCount() const;
const GLenum type;
const GLenum precision;
const std::string name;
const unsigned int arraySize;
unsigned char *data;
bool dirty;
short psRegisterIndex;
short vsRegisterIndex;
};
// Struct used for correlating uniforms/elements of uniform arrays to handles
struct UniformLocation
{
UniformLocation(const std::string &name, unsigned int element, unsigned int index);
std::string name;
unsigned int element;
unsigned int index;
};
class Program
{
public:
Program(ResourceManager *manager, GLuint handle);
~Program();
bool attachShader(Shader *shader);
bool detachShader(Shader *shader);
int getAttachedShadersCount() const;
sw::PixelShader *getPixelShader();
sw::VertexShader *getVertexShader();
void bindAttributeLocation(GLuint index, const char *name);
GLuint getAttributeLocation(const char *name);
int getAttributeStream(int attributeIndex);
GLint getSamplerMapping(sw::SamplerType type, unsigned int samplerIndex);
TextureType getSamplerTextureType(sw::SamplerType type, unsigned int samplerIndex);
GLint getUniformLocation(std::string name);
bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
bool setUniform2iv(GLint location, GLsizei count, const GLint *v);
bool setUniform3iv(GLint location, GLsizei count, const GLint *v);
bool setUniform4iv(GLint location, GLsizei count, const GLint *v);
bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
void dirtyAllUniforms();
void applyUniforms();
void link();
bool isLinked();
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
size_t getActiveAttributeCount() const;
GLint getActiveAttributeMaxLength() const;
void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
size_t getActiveUniformCount() const;
GLint getActiveUniformMaxLength() const;
void addRef();
void release();
unsigned int getRefCount() const;
void flagForDeletion();
bool isFlaggedForDeletion() const;
void validate();
bool validateSamplers(bool logErrors);
bool isValidated() const;
unsigned int getSerial() const;
private:
void unlink();
int packVaryings(const glsl::Varying *packing[][4]);
bool linkVaryings();
bool linkAttributes();
int getAttributeBinding(const std::string &name);
bool linkUniforms(Shader *shader);
bool defineUniform(GLenum shader, GLenum type, GLenum precision, const std::string &_name, unsigned int arraySize, int registerIndex);
bool applyUniform1bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform2bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform3bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform4bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
bool applyUniform1iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform2iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform3iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform4iv(GLint location, GLsizei count, const GLint *v);
void appendToInfoLog(const char *info, ...);
void resetInfoLog();
static unsigned int issueSerial();
private:
gl::Device *device;
FragmentShader *fragmentShader;
VertexShader *vertexShader;
sw::PixelShader *pixelBinary;
sw::VertexShader *vertexBinary;
std::set<std::string> attributeBinding[MAX_VERTEX_ATTRIBS];
glsl::Attribute linkedAttribute[MAX_VERTEX_ATTRIBS];
int attributeStream[MAX_VERTEX_ATTRIBS];
struct Sampler
{
bool active;
GLint logicalTextureUnit;
TextureType textureType;
};
Sampler samplersPS[MAX_TEXTURE_IMAGE_UNITS];
Sampler samplersVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS];
typedef std::vector<Uniform*> UniformArray;
UniformArray uniforms;
typedef std::vector<UniformLocation> UniformIndex;
UniformIndex uniformIndex;
bool linked;
bool orphaned; // Flag to indicate that the program can be deleted when no longer in use
char *infoLog;
bool validated;
unsigned int referenceCount;
const unsigned int serial;
static unsigned int currentSerial;
ResourceManager *resourceManager;
const GLuint handle;
};
}
#endif // LIBGL_PROGRAM_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Query.cpp: Implements the gl::Query class
#include "Query.h"
#include "main.h"
#include "Common/Thread.hpp"
namespace gl
{
Query::Query(GLuint name, GLenum type) : NamedObject(name)
{
mQuery = nullptr;
mStatus = GL_FALSE;
mResult = GL_FALSE;
mType = type;
}
Query::~Query()
{
delete mQuery;
}
void Query::begin()
{
if(!mQuery)
{
sw::Query::Type type;
switch(mType)
{
case GL_ANY_SAMPLES_PASSED:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
type = sw::Query::FRAGMENTS_PASSED;
break;
default:
ASSERT(false);
}
mQuery = new sw::Query(type);
if(!mQuery)
{
return error(GL_OUT_OF_MEMORY);
}
}
Device *device = getDevice();
mQuery->begin();
device->addQuery(mQuery);
device->setOcclusionEnabled(true);
}
void Query::end()
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION);
}
Device *device = getDevice();
mQuery->end();
device->removeQuery(mQuery);
device->setOcclusionEnabled(false);
mStatus = GL_FALSE;
mResult = GL_FALSE;
}
GLuint Query::getResult()
{
if(mQuery)
{
while(!testQuery())
{
sw::Thread::yield();
}
}
return (GLuint)mResult;
}
GLboolean Query::isResultAvailable()
{
if(mQuery)
{
testQuery();
}
return mStatus;
}
GLenum Query::getType() const
{
return mType;
}
GLboolean Query::testQuery()
{
if(mQuery && mStatus != GL_TRUE)
{
if(!mQuery->building && mQuery->reference == 0)
{
unsigned int numPixels = mQuery->data;
mStatus = GL_TRUE;
switch(mType)
{
case GL_ANY_SAMPLES_PASSED:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE;
break;
default:
ASSERT(false);
}
}
return mStatus;
}
return GL_TRUE; // Prevent blocking when query is null
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Query.h: Defines the gl::Query class
#ifndef LIBGL_QUERY_H_
#define LIBGL_QUERY_H_
#include "common/Object.hpp"
#include "Renderer/Renderer.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
class Query : public NamedObject
{
public:
Query(GLuint name, GLenum type);
virtual ~Query();
void begin();
void end();
GLuint getResult();
GLboolean isResultAvailable();
GLenum getType() const;
private:
GLboolean testQuery();
sw::Query* mQuery;
GLenum mType;
GLboolean mStatus;
GLint mResult;
};
}
#endif // LIBGL_QUERY_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Renderbuffer.h: Defines the wrapper class Renderbuffer, as well as the
// class hierarchy used to store its contents: RenderbufferStorage, Colorbuffer,
// DepthStencilbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
// objects and related functionality.
#ifndef LIBGL_RENDERBUFFER_H_
#define LIBGL_RENDERBUFFER_H_
#include "common/Object.hpp"
#include "Image.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
class Texture2D;
class TextureCubeMap;
class Renderbuffer;
class Colorbuffer;
class DepthStencilbuffer;
class RenderbufferInterface
{
public:
RenderbufferInterface();
virtual ~RenderbufferInterface() {};
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
virtual Image *getRenderTarget() = 0;
virtual GLsizei getWidth() const = 0;
virtual GLsizei getHeight() const = 0;
virtual GLenum getFormat() const = 0;
virtual sw::Format getInternalFormat() const = 0;
virtual GLsizei getSamples() const = 0;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
};
class RenderbufferTexture2D : public RenderbufferInterface
{
public:
RenderbufferTexture2D(Texture2D *texture);
virtual ~RenderbufferTexture2D();
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
Image *getRenderTarget();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
private:
BindingPointer<Texture2D> mTexture2D;
};
class RenderbufferTextureCubeMap : public RenderbufferInterface
{
public:
RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target);
virtual ~RenderbufferTextureCubeMap();
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
Image *getRenderTarget();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
private:
BindingPointer<TextureCubeMap> mTextureCubeMap;
GLenum mTarget;
};
// A class derived from RenderbufferStorage is created whenever glRenderbufferStorage
// is called. The specific concrete type depends on whether the internal format is
// colour depth, stencil or packed depth/stencil.
class RenderbufferStorage : public RenderbufferInterface
{
public:
RenderbufferStorage();
virtual ~RenderbufferStorage() = 0;
virtual Image *getRenderTarget();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
protected:
GLsizei mWidth;
GLsizei mHeight;
GLenum format;
sw::Format internalFormat;
GLsizei mSamples;
};
// Renderbuffer implements the GL renderbuffer object.
// It's only a proxy for a RenderbufferInterface instance; the internal object
// can change whenever glRenderbufferStorage is called.
class Renderbuffer : public NamedObject
{
public:
Renderbuffer(GLuint name, RenderbufferInterface *storage);
virtual ~Renderbuffer();
// These functions from Object are overloaded here because
// Textures need to maintain their own count of references to them via
// Renderbuffers/RenderbufferTextures. These functions invoke those
// reference counting functions on the RenderbufferInterface.
virtual void addRef();
virtual void release();
Image *getRenderTarget();
GLsizei getWidth() const;
GLsizei getHeight() const;
GLenum getFormat() const;
sw::Format getInternalFormat() const;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
GLsizei getSamples() const;
void setStorage(RenderbufferStorage *newStorage);
private:
RenderbufferInterface *mInstance;
};
class Colorbuffer : public RenderbufferStorage
{
public:
explicit Colorbuffer(Image *renderTarget);
Colorbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
virtual ~Colorbuffer();
virtual Image *getRenderTarget();
private:
Image *mRenderTarget;
};
class DepthStencilbuffer : public RenderbufferStorage
{
public:
explicit DepthStencilbuffer(Image *depthStencil);
DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
~DepthStencilbuffer();
virtual Image *getRenderTarget();
protected:
Image *mDepthStencil;
};
class Depthbuffer : public DepthStencilbuffer
{
public:
explicit Depthbuffer(Image *depthStencil);
Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
virtual ~Depthbuffer();
};
class Stencilbuffer : public DepthStencilbuffer
{
public:
explicit Stencilbuffer(Image *depthStencil);
Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
virtual ~Stencilbuffer();
};
}
#endif // LIBGL_RENDERBUFFER_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ResourceManager.cpp: Implements the ResourceManager class, which tracks and
// retrieves objects which may be shared by multiple Contexts.
#include "ResourceManager.h"
#include "Buffer.h"
#include "Program.h"
#include "Renderbuffer.h"
#include "Shader.h"
#include "Texture.h"
namespace gl
{
ResourceManager::ResourceManager()
{
mRefCount = 1;
}
ResourceManager::~ResourceManager()
{
while(!mBufferMap.empty())
{
deleteBuffer(mBufferMap.begin()->first);
}
while(!mProgramMap.empty())
{
deleteProgram(mProgramMap.begin()->first);
}
while(!mShaderMap.empty())
{
deleteShader(mShaderMap.begin()->first);
}
while(!mRenderbufferMap.empty())
{
deleteRenderbuffer(mRenderbufferMap.begin()->first);
}
while(!mTextureMap.empty())
{
deleteTexture(mTextureMap.begin()->first);
}
}
void ResourceManager::addRef()
{
mRefCount++;
}
void ResourceManager::release()
{
if(--mRefCount == 0)
{
delete this;
}
}
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
//GLuint handle = mBufferNameSpace.allocate();
unsigned int handle = 1;
while (mBufferMap.find(handle) != mBufferMap.end())
{
handle++;
}
mBufferMap[handle] = nullptr;
return handle;
}
// Returns an unused shader/program name
GLuint ResourceManager::createShader(GLenum type)
{
//GLuint handle = mProgramShaderNameSpace.allocate();
unsigned int handle = 1;
while (mShaderMap.find(handle) != mShaderMap.end())
{
handle++;
}
if(type == GL_VERTEX_SHADER)
{
mShaderMap[handle] = new VertexShader(this, handle);
}
else if(type == GL_FRAGMENT_SHADER)
{
mShaderMap[handle] = new FragmentShader(this, handle);
}
else UNREACHABLE(type);
return handle;
}
// Returns an unused program/shader name
GLuint ResourceManager::createProgram()
{
//GLuint handle = mProgramShaderNameSpace.allocate();
unsigned int handle = 1;
while (mProgramMap.find(handle) != mProgramMap.end())
{
handle++;
}
mProgramMap[handle] = new Program(this, handle);
return handle;
}
// Returns an unused texture name
GLuint ResourceManager::createTexture()
{
//GLuint handle = mTextureNameSpace.allocate();
unsigned int handle = 1;
while (mTextureMap.find(handle) != mTextureMap.end())
{
handle++;
}
mTextureMap[handle] = nullptr;
return handle;
}
// Returns an unused renderbuffer name
GLuint ResourceManager::createRenderbuffer()
{
//GLuint handle = mRenderbufferNameSpace.allocate();
unsigned int handle = 1;
while (mRenderbufferMap.find(handle) != mRenderbufferMap.end())
{
handle++;
}
mRenderbufferMap[handle] = nullptr;
return handle;
}
void ResourceManager::deleteBuffer(GLuint buffer)
{
BufferMap::iterator bufferObject = mBufferMap.find(buffer);
if(bufferObject != mBufferMap.end())
{
//mBufferNameSpace.release(bufferObject->first);
if(bufferObject->second) bufferObject->second->release();
mBufferMap.erase(bufferObject);
}
}
void ResourceManager::deleteShader(GLuint shader)
{
ShaderMap::iterator shaderObject = mShaderMap.find(shader);
if(shaderObject != mShaderMap.end())
{
if(shaderObject->second->getRefCount() == 0)
{
//mProgramShaderNameSpace.release(shaderObject->first);
delete shaderObject->second;
mShaderMap.erase(shaderObject);
}
else
{
shaderObject->second->flagForDeletion();
}
}
}
void ResourceManager::deleteProgram(GLuint program)
{
ProgramMap::iterator programObject = mProgramMap.find(program);
if(programObject != mProgramMap.end())
{
if(programObject->second->getRefCount() == 0)
{
//mProgramShaderNameSpace.release(programObject->first);
delete programObject->second;
mProgramMap.erase(programObject);
}
else
{
programObject->second->flagForDeletion();
}
}
}
void ResourceManager::deleteTexture(GLuint texture)
{
TextureMap::iterator textureObject = mTextureMap.find(texture);
if(textureObject != mTextureMap.end())
{
//mTextureNameSpace.release(textureObject->first);
if(textureObject->second) textureObject->second->release();
mTextureMap.erase(textureObject);
}
}
void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
{
RenderbufferMap::iterator renderbufferObject = mRenderbufferMap.find(renderbuffer);
if(renderbufferObject != mRenderbufferMap.end())
{
//mRenderbufferNameSpace.release(renderbufferObject->first);
if(renderbufferObject->second) renderbufferObject->second->release();
mRenderbufferMap.erase(renderbufferObject);
}
}
Buffer *ResourceManager::getBuffer(unsigned int handle)
{
BufferMap::iterator buffer = mBufferMap.find(handle);
if(buffer == mBufferMap.end())
{
return nullptr;
}
else
{
return buffer->second;
}
}
Shader *ResourceManager::getShader(unsigned int handle)
{
ShaderMap::iterator shader = mShaderMap.find(handle);
if(shader == mShaderMap.end())
{
return nullptr;
}
else
{
return shader->second;
}
}
Texture *ResourceManager::getTexture(unsigned int handle)
{
if(handle == 0) return nullptr;
TextureMap::iterator texture = mTextureMap.find(handle);
if(texture == mTextureMap.end())
{
return nullptr;
}
else
{
return texture->second;
}
}
Program *ResourceManager::getProgram(unsigned int handle)
{
ProgramMap::iterator program = mProgramMap.find(handle);
if(program == mProgramMap.end())
{
return nullptr;
}
else
{
return program->second;
}
}
Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
{
RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle);
if(renderbuffer == mRenderbufferMap.end())
{
return nullptr;
}
else
{
return renderbuffer->second;
}
}
void ResourceManager::setRenderbuffer(GLuint handle, Renderbuffer *buffer)
{
mRenderbufferMap[handle] = buffer;
}
void ResourceManager::checkBufferAllocation(unsigned int buffer)
{
if(buffer != 0 && !getBuffer(buffer))
{
Buffer *bufferObject = new Buffer(buffer);
mBufferMap[buffer] = bufferObject;
bufferObject->addRef();
}
}
void ResourceManager::checkTextureAllocation(GLuint texture, TextureType type)
{
if(!getTexture(texture) && texture != 0)
{
Texture *textureObject;
if(type == TEXTURE_2D)
{
textureObject = new Texture2D(texture);
}
else if(type == TEXTURE_CUBE)
{
textureObject = new TextureCubeMap(texture);
}
else
{
UNREACHABLE(type);
return;
}
mTextureMap[texture] = textureObject;
textureObject->addRef();
}
}
void ResourceManager::checkRenderbufferAllocation(GLuint renderbuffer)
{
if(renderbuffer != 0 && !getRenderbuffer(renderbuffer))
{
Renderbuffer *renderbufferObject = new Renderbuffer(renderbuffer, new Colorbuffer(0, 0, GL_RGBA4, 0));
mRenderbufferMap[renderbuffer] = renderbufferObject;
renderbufferObject->addRef();
}
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ResourceManager.h : Defines the ResourceManager class, which tracks objects
// shared by multiple GL contexts.
#ifndef LIBGL_RESOURCEMANAGER_H_
#define LIBGL_RESOURCEMANAGER_H_
#include "common/NameSpace.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
#include <map>
namespace gl
{
class Buffer;
class Shader;
class Program;
class Texture;
class Renderbuffer;
enum TextureType
{
TEXTURE_2D,
PROXY_TEXTURE_2D,
TEXTURE_CUBE,
TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN
};
class ResourceManager
{
public:
ResourceManager();
~ResourceManager();
void addRef();
void release();
GLuint createBuffer();
GLuint createShader(GLenum type);
GLuint createProgram();
GLuint createTexture();
GLuint createRenderbuffer();
void deleteBuffer(GLuint buffer);
void deleteShader(GLuint shader);
void deleteProgram(GLuint program);
void deleteTexture(GLuint texture);
void deleteRenderbuffer(GLuint renderbuffer);
Buffer *getBuffer(GLuint handle);
Shader *getShader(GLuint handle);
Program *getProgram(GLuint handle);
Texture *getTexture(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type);
void checkRenderbufferAllocation(GLuint renderbuffer);
private:
std::size_t mRefCount;
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
//NameSpace mBufferNameSpace;
typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap;
//NameSpace mProgramShaderNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
//NameSpace mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
//NameSpace mRenderbufferNameSpace;
};
}
#endif // LIBGL_RESOURCEMANAGER_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Shader.cpp: Implements the Shader class and its derived classes
// VertexShader and FragmentShader. Implements GL shader objects and related
// functionality.
#include "Shader.h"
#include "main.h"
#include "utilities.h"
#include <string>
namespace gl
{
bool Shader::compilerInitialized = false;
Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mResourceManager(manager)
{
mSource = nullptr;
clear();
mRefCount = 0;
mDeleteStatus = false;
}
Shader::~Shader()
{
delete[] mSource;
}
GLuint Shader::getName() const
{
return mHandle;
}
void Shader::setSource(GLsizei count, const char *const *string, const GLint *length)
{
delete[] mSource;
int totalLength = 0;
for(int i = 0; i < count; i++)
{
if(length && length[i] >= 0)
{
totalLength += length[i];
}
else
{
totalLength += (int)strlen(string[i]);
}
}
mSource = new char[totalLength + 1];
char *code = mSource;
for(int i = 0; i < count; i++)
{
int stringLength;
if(length && length[i] >= 0)
{
stringLength = length[i];
}
else
{
stringLength = (int)strlen(string[i]);
}
strncpy(code, string[i], stringLength);
code += stringLength;
}
mSource[totalLength] = '\0';
}
int Shader::getInfoLogLength() const
{
if(infoLog.empty())
{
return 0;
}
else
{
return infoLog.size() + 1;
}
}
void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLogOut)
{
int index = 0;
if(bufSize > 0)
{
if(!infoLog.empty())
{
index = std::min(bufSize - 1, (GLsizei)infoLog.size());
memcpy(infoLogOut, infoLog.c_str(), index);
}
infoLogOut[index] = '\0';
}
if(length)
{
*length = index;
}
}
int Shader::getSourceLength() const
{
if(!mSource)
{
return 0;
}
else
{
return strlen(mSource) + 1;
}
}
void Shader::getSource(GLsizei bufSize, GLsizei *length, char *source)
{
int index = 0;
if(bufSize > 0)
{
if(mSource)
{
index = std::min(bufSize - 1, (int)strlen(mSource));
memcpy(source, mSource, index);
}
source[index] = '\0';
}
if(length)
{
*length = index;
}
}
TranslatorASM *Shader::createCompiler(GLenum shaderType)
{
if(!compilerInitialized)
{
InitCompilerGlobals();
compilerInitialized = true;
}
TranslatorASM *assembler = new TranslatorASM(this, shaderType);
ShBuiltInResources resources;
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = MAX_VARYING_VECTORS;
resources.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
resources.MaxCombinedTextureImageUnits = MAX_COMBINED_TEXTURE_IMAGE_UNITS;
resources.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
resources.MaxFragmentUniformVectors = MAX_FRAGMENT_UNIFORM_VECTORS;
resources.MaxDrawBuffers = MAX_DRAW_BUFFERS;
resources.OES_standard_derivatives = 1;
resources.OES_fragment_precision_high = 1;
resources.MaxCallStackDepth = 16;
assembler->Init(resources);
return assembler;
}
void Shader::clear()
{
infoLog.clear();
varyings.clear();
activeUniforms.clear();
activeAttributes.clear();
}
void Shader::compile()
{
clear();
createShader();
TranslatorASM *compiler = createCompiler(getType());
// Ensure we don't pass a nullptr source to the compiler
const char *source = "\0";
if(mSource)
{
source = mSource;
}
bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false)
{
static int serial = 1;
char buffer[256];
sprintf(buffer, "shader-input-%d-%d.txt", getName(), serial);
FILE *file = fopen(buffer, "wt");
fprintf(file, "%s", mSource);
fclose(file);
getShader()->print("shader-output-%d-%d.txt", getName(), serial);
serial++;
}
if(!success)
{
deleteShader();
infoLog = compiler->getInfoSink().info.c_str();
TRACE("\n%s", infoLog.c_str());
}
delete compiler;
}
bool Shader::isCompiled()
{
return getShader() != 0;
}
void Shader::addRef()
{
mRefCount++;
}
void Shader::release()
{
mRefCount--;
if(mRefCount == 0 && mDeleteStatus)
{
mResourceManager->deleteShader(mHandle);
}
}
unsigned int Shader::getRefCount() const
{
return mRefCount;
}
bool Shader::isFlaggedForDeletion() const
{
return mDeleteStatus;
}
void Shader::flagForDeletion()
{
mDeleteStatus = true;
}
void Shader::releaseCompiler()
{
FreeCompilerGlobals();
compilerInitialized = false;
}
// true if varying x has a higher priority in packing than y
bool Shader::compareVarying(const glsl::Varying &x, const glsl::Varying &y)
{
if(x.type == y.type)
{
return x.size() > y.size();
}
switch(x.type)
{
case GL_FLOAT_MAT4: return true;
case GL_FLOAT_MAT2:
switch(y.type)
{
case GL_FLOAT_MAT4: return false;
case GL_FLOAT_MAT2: return true;
case GL_FLOAT_VEC4: return true;
case GL_FLOAT_MAT3: return true;
case GL_FLOAT_VEC3: return true;
case GL_FLOAT_VEC2: return true;
case GL_FLOAT: return true;
default: UNREACHABLE(y.type);
}
break;
case GL_FLOAT_VEC4:
switch(y.type)
{
case GL_FLOAT_MAT4: return false;
case GL_FLOAT_MAT2: return false;
case GL_FLOAT_VEC4: return true;
case GL_FLOAT_MAT3: return true;
case GL_FLOAT_VEC3: return true;
case GL_FLOAT_VEC2: return true;
case GL_FLOAT: return true;
default: UNREACHABLE(y.type);
}
break;
case GL_FLOAT_MAT3:
switch(y.type)
{
case GL_FLOAT_MAT4: return false;
case GL_FLOAT_MAT2: return false;
case GL_FLOAT_VEC4: return false;
case GL_FLOAT_MAT3: return true;
case GL_FLOAT_VEC3: return true;
case GL_FLOAT_VEC2: return true;
case GL_FLOAT: return true;
default: UNREACHABLE(y.type);
}
break;
case GL_FLOAT_VEC3:
switch(y.type)
{
case GL_FLOAT_MAT4: return false;
case GL_FLOAT_MAT2: return false;
case GL_FLOAT_VEC4: return false;
case GL_FLOAT_MAT3: return false;
case GL_FLOAT_VEC3: return true;
case GL_FLOAT_VEC2: return true;
case GL_FLOAT: return true;
default: UNREACHABLE(y.type);
}
break;
case GL_FLOAT_VEC2:
switch(y.type)
{
case GL_FLOAT_MAT4: return false;
case GL_FLOAT_MAT2: return false;
case GL_FLOAT_VEC4: return false;
case GL_FLOAT_MAT3: return false;
case GL_FLOAT_VEC3: return false;
case GL_FLOAT_VEC2: return true;
case GL_FLOAT: return true;
default: UNREACHABLE(y.type);
}
break;
case GL_FLOAT: return false;
default: UNREACHABLE(x.type);
}
return false;
}
VertexShader::VertexShader(ResourceManager *manager, GLuint handle) : Shader(manager, handle)
{
vertexShader = 0;
}
VertexShader::~VertexShader()
{
delete vertexShader;
}
GLenum VertexShader::getType()
{
return GL_VERTEX_SHADER;
}
int VertexShader::getSemanticIndex(const std::string &attributeName)
{
if(!attributeName.empty())
{
for(glsl::ActiveAttributes::iterator attribute = activeAttributes.begin(); attribute != activeAttributes.end(); attribute++)
{
if(attribute->name == attributeName)
{
return attribute->registerIndex;
}
}
}
return -1;
}
sw::Shader *VertexShader::getShader() const
{
return vertexShader;
}
sw::VertexShader *VertexShader::getVertexShader() const
{
return vertexShader;
}
void VertexShader::createShader()
{
delete vertexShader;
vertexShader = new sw::VertexShader();
}
void VertexShader::deleteShader()
{
delete vertexShader;
vertexShader = nullptr;
}
FragmentShader::FragmentShader(ResourceManager *manager, GLuint handle) : Shader(manager, handle)
{
pixelShader = 0;
}
FragmentShader::~FragmentShader()
{
delete pixelShader;
}
GLenum FragmentShader::getType()
{
return GL_FRAGMENT_SHADER;
}
sw::Shader *FragmentShader::getShader() const
{
return pixelShader;
}
sw::PixelShader *FragmentShader::getPixelShader() const
{
return pixelShader;
}
void FragmentShader::createShader()
{
delete pixelShader;
pixelShader = new sw::PixelShader();
}
void FragmentShader::deleteShader()
{
delete pixelShader;
pixelShader = nullptr;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Shader.h: Defines the abstract Shader class and its concrete derived
// classes VertexShader and FragmentShader. Implements GL shader objects and
// related functionality.
#ifndef LIBGL_SHADER_H_
#define LIBGL_SHADER_H_
#include "ResourceManager.h"
#include "compiler/TranslatorASM.h"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
#include <string>
#include <list>
#include <vector>
namespace glsl
{
class OutputASM;
}
namespace gl
{
class Shader : public glsl::Shader
{
friend class Program;
public:
Shader(ResourceManager *manager, GLuint handle);
virtual ~Shader();
virtual GLenum getType() = 0;
GLuint getName() const;
void deleteSource();
void setSource(GLsizei count, const char *const *string, const GLint *length);
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
int getSourceLength() const;
void getSource(GLsizei bufSize, GLsizei *length, char *source);
void compile();
bool isCompiled();
void addRef();
void release();
unsigned int getRefCount() const;
bool isFlaggedForDeletion() const;
void flagForDeletion();
static void releaseCompiler();
protected:
static bool compilerInitialized;
TranslatorASM *createCompiler(GLenum shaderType);
void clear();
static bool compareVarying(const glsl::Varying &x, const glsl::Varying &y);
char *mSource;
std::string infoLog;
private:
virtual void createShader() = 0;
virtual void deleteShader() = 0;
const GLuint mHandle;
unsigned int mRefCount; // Number of program objects this shader is attached to
bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
ResourceManager *mResourceManager;
};
class VertexShader : public Shader
{
friend class Program;
public:
VertexShader(ResourceManager *manager, GLuint handle);
~VertexShader();
virtual GLenum getType();
int getSemanticIndex(const std::string &attributeName);
virtual sw::Shader *getShader() const;
virtual sw::VertexShader *getVertexShader() const;
private:
virtual void createShader();
virtual void deleteShader();
sw::VertexShader *vertexShader;
};
class FragmentShader : public Shader
{
public:
FragmentShader(ResourceManager *manager, GLuint handle);
~FragmentShader();
virtual GLenum getType();
virtual sw::Shader *getShader() const;
virtual sw::PixelShader *getPixelShader() const;
private:
virtual void createShader();
virtual void deleteShader();
sw::PixelShader *pixelShader;
};
}
#endif // LIBGL_SHADER_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Surface.cpp: Implements the Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers.
#include "Surface.h"
#include "main.h"
#include "Display.h"
#include "Image.hpp"
#include "Context.h"
#include "common/debug.h"
#include "Main/FrameBuffer.hpp"
#if defined(_WIN32)
#include <tchar.h>
#endif
#include <algorithm>
namespace gl
{
Surface::Surface(Display *display, NativeWindowType window)
: mDisplay(display), mWindow(window)
{
frameBuffer = 0;
backBuffer = 0;
mDepthStencil = nullptr;
mTextureFormat = GL_NONE;
mTextureTarget = GL_NONE;
mSwapInterval = -1;
setSwapInterval(1);
}
Surface::Surface(Display *display, GLint width, GLint height, GLenum textureFormat, GLenum textureType)
: mDisplay(display), mWindow(nullptr), mWidth(width), mHeight(height)
{
frameBuffer = 0;
backBuffer = 0;
mDepthStencil = nullptr;
mWindowSubclassed = false;
mTextureFormat = textureFormat;
mTextureTarget = textureType;
mSwapInterval = -1;
setSwapInterval(1);
}
Surface::~Surface()
{
release();
}
bool Surface::initialize()
{
ASSERT(!frameBuffer && !backBuffer && !mDepthStencil);
return reset();
}
void Surface::release()
{
if(mDepthStencil)
{
mDepthStencil->release();
mDepthStencil = nullptr;
}
if(backBuffer)
{
backBuffer->release();
backBuffer = 0;
}
delete frameBuffer;
frameBuffer = 0;
}
bool Surface::reset()
{
if(!mWindow)
{
return reset(mWidth, mHeight);
}
// FIXME: Wrap into an abstract Window class
#if defined(_WIN32)
RECT windowRect;
GetClientRect(mWindow, &windowRect);
return reset(windowRect.right - windowRect.left, windowRect.bottom - windowRect.top);
#else
XWindowAttributes windowAttributes;
XGetWindowAttributes(mDisplay->getNativeDisplay(), mWindow, &windowAttributes);
return reset(windowAttributes.width, windowAttributes.height);
#endif
}
bool Surface::reset(int backBufferWidth, int backBufferHeight)
{
release();
if(mWindow)
{
frameBuffer = ::createFrameBuffer(mDisplay->getNativeDisplay(), mWindow, backBufferWidth, backBufferHeight);
if(!frameBuffer)
{
ERR("Could not create frame buffer");
release();
return error(GL_OUT_OF_MEMORY, false);
}
}
backBuffer = new Image(0, backBufferWidth, backBufferHeight, GL_RGB, GL_UNSIGNED_BYTE);
if(!backBuffer)
{
ERR("Could not create back buffer");
release();
return error(GL_OUT_OF_MEMORY, false);
}
if(true) // Always provide a depth/stencil buffer
{
mDepthStencil = new Image(0, backBufferWidth, backBufferHeight, sw::FORMAT_D24S8, 1, false, true);
if(!mDepthStencil)
{
ERR("Could not create depth/stencil buffer for surface");
release();
return error(GL_OUT_OF_MEMORY, false);
}
}
mWidth = backBufferWidth;
mHeight = backBufferHeight;
return true;
}
void Surface::swap()
{
if(backBuffer)
{
frameBuffer->flip(backBuffer);
checkForResize();
}
}
Image *Surface::getRenderTarget()
{
if(backBuffer)
{
backBuffer->addRef();
}
return backBuffer;
}
Image *Surface::getDepthStencil()
{
if(mDepthStencil)
{
mDepthStencil->addRef();
}
return mDepthStencil;
}
void Surface::setSwapInterval(GLint interval)
{
if(mSwapInterval == interval)
{
return;
}
mSwapInterval = interval;
mSwapInterval = std::max(mSwapInterval, mDisplay->getMinSwapInterval());
mSwapInterval = std::min(mSwapInterval, mDisplay->getMaxSwapInterval());
}
GLint Surface::getWidth() const
{
return mWidth;
}
GLint Surface::getHeight() const
{
return mHeight;
}
GLenum Surface::getTextureFormat() const
{
return mTextureFormat;
}
GLenum Surface::getTextureTarget() const
{
return mTextureTarget;
}
bool Surface::checkForResize()
{
#if defined(_WIN32)
RECT client;
if(!GetClientRect(mWindow, &client))
{
ASSERT(false);
return false;
}
int clientWidth = client.right - client.left;
int clientHeight = client.bottom - client.top;
#else
XWindowAttributes windowAttributes;
XGetWindowAttributes(mDisplay->getNativeDisplay(), mWindow, &windowAttributes);
int clientWidth = windowAttributes.width;
int clientHeight = windowAttributes.height;
#endif
bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight();
if(sizeDirty)
{
reset(clientWidth, clientHeight);
if(getCurrentDrawSurface() == this)
{
getContext()->makeCurrent(this);
}
return true;
}
return false;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Surface.h: Defines the Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers.
#ifndef INCLUDE_SURFACE_H_
#define INCLUDE_SURFACE_H_
#include "Main/FrameBuffer.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
#if defined(_WIN32)
typedef HDC NativeDisplayType;
typedef HBITMAP NativePixmapType;
typedef HWND NativeWindowType;
#else
#error
#endif
namespace gl
{
class Image;
class Display;
class Surface
{
public:
Surface(Display *display, NativeWindowType window);
Surface(Display *display, GLint width, GLint height, GLenum textureFormat, GLenum textureTarget);
virtual ~Surface();
bool initialize();
void swap();
virtual Image *getRenderTarget();
virtual Image *getDepthStencil();
void setSwapInterval(GLint interval);
virtual GLint getWidth() const;
virtual GLint getHeight() const;
virtual GLenum getTextureFormat() const;
virtual GLenum getTextureTarget() const;
bool checkForResize(); // Returns true if surface changed due to resize
private:
void release();
bool reset();
Display *const mDisplay;
Image *mDepthStencil;
sw::FrameBuffer *frameBuffer;
Image *backBuffer;
bool reset(int backbufferWidth, int backbufferHeight);
const NativeWindowType mWindow; // Window that the surface is created for.
bool mWindowSubclassed; // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking
GLint mWidth; // Width of surface
GLint mHeight; // Height of surface
GLenum mTextureFormat; // Format of texture: RGB, RGBA, or no texture
GLenum mTextureTarget; // Type of texture: 2D or no texture
GLint mSwapInterval;
};
}
#endif // INCLUDE_SURFACE_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Texture.h: Defines the abstract Texture class and its concrete derived
// classes Texture2D and TextureCubeMap. Implements GL texture objects and
// related functionality.
#ifndef LIBGL_TEXTURE_H_
#define LIBGL_TEXTURE_H_
#include "Renderbuffer.h"
#include "common/Object.hpp"
#include "utilities.h"
#include "common/debug.h"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
#include <vector>
namespace gl
{
class Surface;
class Config;
class Framebuffer;
enum
{
IMPLEMENTATION_MAX_TEXTURE_LEVELS = sw::MIPMAP_LEVELS,
IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (IMPLEMENTATION_MAX_TEXTURE_LEVELS - 1),
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (IMPLEMENTATION_MAX_TEXTURE_LEVELS - 1),
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = sw::OUTLINE_RESOLUTION,
};
class Texture : public NamedObject
{
public:
explicit Texture(GLuint name);
virtual ~Texture();
sw::Resource *getResource() const;
virtual void addProxyRef(const Renderbuffer *proxy) = 0;
virtual void releaseProxy(const Renderbuffer *proxy) = 0;
virtual GLenum getTarget() const = 0;
bool setMinFilter(GLenum filter);
bool setMagFilter(GLenum filter);
bool setWrapS(GLenum wrap);
bool setWrapT(GLenum wrap);
bool setMaxAnisotropy(GLfloat textureMaxAnisotropy);
bool setMaxLevel(int level);
GLenum getMinFilter() const;
GLenum getMagFilter() const;
GLenum getWrapS() const;
GLenum getWrapT() const;
GLfloat getMaxAnisotropy() const;
virtual GLsizei getWidth(GLenum target, GLint level) const = 0;
virtual GLsizei getHeight(GLenum target, GLint level) const = 0;
virtual GLenum getFormat(GLenum target, GLint level) const = 0;
virtual GLenum getType(GLenum target, GLint level) const = 0;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const = 0;
virtual int getTopLevel() const = 0;
virtual bool isSamplerComplete() const = 0;
virtual bool isCompressed(GLenum target, GLint level) const = 0;
virtual bool isDepth(GLenum target, GLint level) const = 0;
virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
virtual Image *getRenderTarget(GLenum target, unsigned int level) = 0;
virtual void generateMipmaps() = 0;
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
protected:
void setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *image);
void subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, Image *image);
void subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, Image *image);
bool copy(Image *source, const sw::Rect &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, Image *dest);
bool isMipmapFiltered() const;
GLenum mMinFilter;
GLenum mMagFilter;
GLenum mWrapS;
GLenum mWrapT;
GLfloat mMaxAnisotropy;
GLint mMaxLevel;
sw::Resource *resource;
};
class Texture2D : public Texture
{
public:
explicit Texture2D(GLuint name);
virtual ~Texture2D();
void addProxyRef(const Renderbuffer *proxy);
void releaseProxy(const Renderbuffer *proxy);
virtual GLenum getTarget() const;
virtual GLsizei getWidth(GLenum target, GLint level) const;
virtual GLsizei getHeight(GLenum target, GLint level) const;
virtual GLenum getFormat(GLenum target, GLint level) const;
virtual GLenum getType(GLenum target, GLint level) const;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const;
virtual int getTopLevel() const;
void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void setImage(Image *image);
virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const;
virtual bool isDepth(GLenum target, GLint level) const;
virtual void generateMipmaps();
virtual Renderbuffer *getRenderbuffer(GLenum target);
virtual Image *getRenderTarget(GLenum target, unsigned int level);
Image *getImage(unsigned int level);
protected:
bool isMipmapComplete() const;
Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
// A specific internal reference count is kept for colorbuffer proxy references,
// because, as the renderbuffer acting as proxy will maintain a binding pointer
// back to this texture, there would be a circular reference if we used a binding
// pointer here. This reference count will cause the pointer to be set to null if
// the count drops to zero, but will not cause deletion of the Renderbuffer.
Renderbuffer *mColorbufferProxy;
unsigned int mProxyRefs;
};
class TextureCubeMap : public Texture
{
public:
explicit TextureCubeMap(GLuint name);
virtual ~TextureCubeMap();
void addProxyRef(const Renderbuffer *proxy);
void releaseProxy(const Renderbuffer *proxy);
virtual GLenum getTarget() const;
virtual GLsizei getWidth(GLenum target, GLint level) const;
virtual GLsizei getHeight(GLenum target, GLint level) const;
virtual GLenum getFormat(GLenum target, GLint level) const;
virtual GLenum getType(GLenum target, GLint level) const;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const;
virtual int getTopLevel() const;
void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const;
virtual bool isDepth(GLenum target, GLint level) const;
virtual void generateMipmaps();
virtual Renderbuffer *getRenderbuffer(GLenum target);
virtual Image *getRenderTarget(GLenum target, unsigned int level);
Image *getImage(int face, unsigned int level);
private:
bool isCubeComplete() const;
bool isMipmapCubeComplete() const;
// face is one of the GL_TEXTURE_CUBE_MAP_* enumerants. Returns nullptr on failure.
Image *getImage(GLenum face, unsigned int level);
Image *image[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
// A specific internal reference count is kept for colorbuffer proxy references,
// because, as the renderbuffer acting as proxy will maintain a binding pointer
// back to this texture, there would be a circular reference if we used a binding
// pointer here. This reference count will cause the pointer to be set to null if
// the count drops to zero, but will not cause deletion of the Renderbuffer.
Renderbuffer *mFaceProxies[6];
unsigned int mFaceProxyRefs[6];
};
}
#endif // LIBGL_TEXTURE_H_
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// VertexDataManager.h: Defines the VertexDataManager, a class that
// runs the Buffer translation process.
#include "VertexDataManager.h"
#include "Buffer.h"
#include "Program.h"
#include "IndexDataManager.h"
#include "common/debug.h"
namespace
{
enum {INITIAL_STREAM_BUFFER_SIZE = 1024 * 1024};
}
namespace gl
{
VertexDataManager::VertexDataManager(Context *context) : mContext(context)
{
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
mDirtyCurrentValue[i] = true;
mCurrentValueBuffer[i] = nullptr;
}
mStreamingBuffer = new StreamingVertexBuffer(INITIAL_STREAM_BUFFER_SIZE);
if(!mStreamingBuffer)
{
ERR("Failed to allocate the streaming vertex buffer.");
}
}
VertexDataManager::~VertexDataManager()
{
delete mStreamingBuffer;
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
delete mCurrentValueBuffer[i];
}
}
unsigned int VertexDataManager::writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute)
{
Buffer *buffer = attribute.mBoundBuffer;
int inputStride = attribute.stride();
int elementSize = attribute.typeSize();
unsigned int streamOffset = 0;
char *output = nullptr;
if(vertexBuffer)
{
output = (char*)vertexBuffer->map(attribute, attribute.typeSize() * count, &streamOffset);
}
if(!output)
{
ERR("Failed to map vertex buffer.");
return ~0u;
}
const char *input = nullptr;
if(buffer)
{
int offset = attribute.mOffset;
input = static_cast<const char*>(buffer->data()) + offset;
}
else
{
input = static_cast<const char*>(attribute.mPointer);
}
input += inputStride * start;
if(inputStride == elementSize)
{
memcpy(output, input, count * inputStride);
}
else
{
for(int i = 0; i < count; i++)
{
memcpy(output, input, elementSize);
output += elementSize;
input += inputStride;
}
}
vertexBuffer->unmap();
return streamOffset;
}
GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *translated)
{
if(!mStreamingBuffer)
{
return GL_OUT_OF_MEMORY;
}
const VertexAttributeArray &attribs = mContext->getVertexAttributes();
Program *program = mContext->getCurrentProgram();
// Determine the required storage size per used buffer
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
if(!program || program->getAttributeStream(i) != -1)
{
if(attribs[i].mArrayEnabled)
{
if(!attribs[i].mBoundBuffer)
{
mStreamingBuffer->addRequiredSpace(attribs[i].typeSize() * count);
}
}
}
}
mStreamingBuffer->reserveRequiredSpace();
// Perform the vertex data translations
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
if(!program || program->getAttributeStream(i) != -1)
{
if(attribs[i].mArrayEnabled)
{
Buffer *buffer = attribs[i].mBoundBuffer;
if(!buffer && attribs[i].mPointer == nullptr)
{
// This is an application error that would normally result in a crash, but we catch it and return an error
ERR("An enabled vertex array has no buffer and no pointer.");
return GL_INVALID_OPERATION;
}
sw::Resource *staticBuffer = buffer ? buffer->getResource() : nullptr;
if(staticBuffer)
{
translated[i].vertexBuffer = staticBuffer;
translated[i].offset = start * attribs[i].stride() + attribs[i].mOffset;
translated[i].stride = attribs[i].stride();
}
else
{
unsigned int streamOffset = writeAttributeData(mStreamingBuffer, start, count, attribs[i]);
if(streamOffset == ~0u)
{
return GL_OUT_OF_MEMORY;
}
translated[i].vertexBuffer = mStreamingBuffer->getResource();
translated[i].offset = streamOffset;
translated[i].stride = attribs[i].typeSize();
}
switch(attribs[i].mType)
{
case GL_BYTE: translated[i].type = sw::STREAMTYPE_SBYTE; break;
case GL_UNSIGNED_BYTE: translated[i].type = sw::STREAMTYPE_BYTE; break;
case GL_SHORT: translated[i].type = sw::STREAMTYPE_SHORT; break;
case GL_UNSIGNED_SHORT: translated[i].type = sw::STREAMTYPE_USHORT; break;
case GL_INT: translated[i].type = sw::STREAMTYPE_INT; break;
case GL_UNSIGNED_INT: translated[i].type = sw::STREAMTYPE_UINT; break;
case GL_FIXED: translated[i].type = sw::STREAMTYPE_FIXED; break;
case GL_FLOAT: translated[i].type = sw::STREAMTYPE_FLOAT; break;
default: UNREACHABLE(attribs[i].mType); translated[i].type = sw::STREAMTYPE_FLOAT; break;
}
translated[i].count = attribs[i].mSize;
translated[i].normalized = attribs[i].mNormalized;
}
else
{
if(mDirtyCurrentValue[i])
{
delete mCurrentValueBuffer[i];
mCurrentValueBuffer[i] = new ConstantVertexBuffer(attribs[i].mCurrentValue[0], attribs[i].mCurrentValue[1], attribs[i].mCurrentValue[2], attribs[i].mCurrentValue[3]);
mDirtyCurrentValue[i] = false;
}
translated[i].vertexBuffer = mCurrentValueBuffer[i]->getResource();
translated[i].type = sw::STREAMTYPE_FLOAT;
translated[i].count = 4;
translated[i].stride = 0;
translated[i].offset = 0;
}
}
}
return GL_NO_ERROR;
}
VertexBuffer::VertexBuffer(unsigned int size) : mVertexBuffer(nullptr)
{
if(size > 0)
{
mVertexBuffer = new sw::Resource(size + 1024);
if(!mVertexBuffer)
{
ERR("Out of memory allocating a vertex buffer of size %u.", size);
}
}
}
VertexBuffer::~VertexBuffer()
{
if(mVertexBuffer)
{
mVertexBuffer->destruct();
}
}
void VertexBuffer::unmap()
{
if(mVertexBuffer)
{
mVertexBuffer->unlock();
}
}
sw::Resource *VertexBuffer::getResource() const
{
return mVertexBuffer;
}
ConstantVertexBuffer::ConstantVertexBuffer(float x, float y, float z, float w) : VertexBuffer(4 * sizeof(float))
{
if(mVertexBuffer)
{
float *vector = (float*)mVertexBuffer->lock(sw::PUBLIC);
vector[0] = x;
vector[1] = y;
vector[2] = z;
vector[3] = w;
mVertexBuffer->unlock();
}
}
ConstantVertexBuffer::~ConstantVertexBuffer()
{
}
StreamingVertexBuffer::StreamingVertexBuffer(unsigned int size) : VertexBuffer(size)
{
mBufferSize = size;
mWritePosition = 0;
mRequiredSpace = 0;
}
StreamingVertexBuffer::~StreamingVertexBuffer()
{
}
void StreamingVertexBuffer::addRequiredSpace(unsigned int requiredSpace)
{
mRequiredSpace += requiredSpace;
}
void *StreamingVertexBuffer::map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *offset)
{
void *mapPtr = nullptr;
if(mVertexBuffer)
{
// We can use a private lock because we never overwrite the content
mapPtr = (char*)mVertexBuffer->lock(sw::PRIVATE) + mWritePosition;
*offset = mWritePosition;
mWritePosition += requiredSpace;
}
return mapPtr;
}
void StreamingVertexBuffer::reserveRequiredSpace()
{
if(mRequiredSpace > mBufferSize)
{
if(mVertexBuffer)
{
mVertexBuffer->destruct();
mVertexBuffer = 0;
}
mBufferSize = std::max(mRequiredSpace, 3 * mBufferSize / 2); // 1.5 x mBufferSize is arbitrary and should be checked to see we don't have too many reallocations.
mVertexBuffer = new sw::Resource(mBufferSize);
if(!mVertexBuffer)
{
ERR("Out of memory allocating a vertex buffer of size %u.", mBufferSize);
}
mWritePosition = 0;
}
else if(mWritePosition + mRequiredSpace > mBufferSize) // Recycle
{
if(mVertexBuffer)
{
mVertexBuffer->destruct();
mVertexBuffer = new sw::Resource(mBufferSize);
}
mWritePosition = 0;
}
mRequiredSpace = 0;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// VertexDataManager.h: Defines the VertexDataManager, a class that
// runs the Buffer translation process.
#ifndef LIBGL_VERTEXDATAMANAGER_H_
#define LIBGL_VERTEXDATAMANAGER_H_
#include "Context.h"
#include "Device.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#include <GL/glext.h>
namespace gl
{
struct TranslatedAttribute
{
sw::StreamType type;
int count;
bool normalized;
unsigned int offset;
unsigned int stride; // 0 means not to advance the read pointer at all
sw::Resource *vertexBuffer;
};
class VertexBuffer
{
public:
VertexBuffer(unsigned int size);
virtual ~VertexBuffer();
void unmap();
sw::Resource *getResource() const;
protected:
sw::Resource *mVertexBuffer;
};
class ConstantVertexBuffer : public VertexBuffer
{
public:
ConstantVertexBuffer(float x, float y, float z, float w);
~ConstantVertexBuffer();
};
class StreamingVertexBuffer : public VertexBuffer
{
public:
StreamingVertexBuffer(unsigned int size);
~StreamingVertexBuffer();
void *map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *streamOffset);
void reserveRequiredSpace();
void addRequiredSpace(unsigned int requiredSpace);
protected:
unsigned int mBufferSize;
unsigned int mWritePosition;
unsigned int mRequiredSpace;
};
class VertexDataManager
{
public:
VertexDataManager(Context *context);
virtual ~VertexDataManager();
void dirtyCurrentValue(int index) { mDirtyCurrentValue[index] = true; }
GLenum prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *outAttribs);
private:
unsigned int writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute);
Context *const mContext;
StreamingVertexBuffer *mStreamingBuffer;
bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS];
ConstantVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS];
};
}
#endif // LIBGL_VERTEXDATAMANAGER_H_
This source diff could not be displayed because it is too large. You can view the blob instead.
LIBRARY opengl32
EXPORTS
GlmfBeginGlsBlock @1
GlmfCloseMetaFile @2
GlmfEndGlsBlock @3
GlmfEndPlayback @4
GlmfInitPlayback @5
GlmfPlayGlsRecord @6
glAccum @7
glAlphaFunc @8
glAreTexturesResident @9
glArrayElement @10
glBegin @11
glBindTexture @12
glBitmap @13
glBlendFunc @14
glCallList @15
glCallLists @16
glClear @17
glClearAccum @18
glClearColor @19
glClearDepth @20
glClearIndex @21
glClearStencil @22
glClipPlane @23
glColor3b @24
glColor3bv @25
glColor3d @26
glColor3dv @27
glColor3f @28
glColor3fv @29
glColor3i @30
glColor3iv @31
glColor3s @32
glColor3sv @33
glColor3ub @34
glColor3ubv @35
glColor3ui @36
glColor3uiv @37
glColor3us @38
glColor3usv @39
glColor4b @40
glColor4bv @41
glColor4d @42
glColor4dv @43
glColor4f @44
glColor4fv @45
glColor4i @46
glColor4iv @47
glColor4s @48
glColor4sv @49
glColor4ub @50
glColor4ubv @51
glColor4ui @52
glColor4uiv @53
glColor4us @54
glColor4usv @55
glColorMask @56
glColorMaterial @57
glColorPointer @58
glCopyPixels @59
glCopyTexImage1D @60
glCopyTexImage2D @61
glCopyTexSubImage1D @62
glCopyTexSubImage2D @63
glCullFace @64
glDebugEntry @65
glDeleteLists @66
glDeleteTextures @67
glDepthFunc @68
glDepthMask @69
glDepthRange @70
glDisable @71
glDisableClientState @72
glDrawArrays @73
glDrawBuffer @74
glDrawElements @75
glDrawPixels @76
glEdgeFlag @77
glEdgeFlagPointer @78
glEdgeFlagv @79
glEnable @80
glEnableClientState @81
glEnd @82
glEndList @83
glEvalCoord1d @84
glEvalCoord1dv @85
glEvalCoord1f @86
glEvalCoord1fv @87
glEvalCoord2d @88
glEvalCoord2dv @89
glEvalCoord2f @90
glEvalCoord2fv @91
glEvalMesh1 @92
glEvalMesh2 @93
glEvalPoint1 @94
glEvalPoint2 @95
glFeedbackBuffer @96
glFinish @97
glFlush @98
glFogf @99
glFogfv @100
glFogi @101
glFogiv @102
glFrontFace @103
glFrustum @104
glGenLists @105
glGenTextures @106
glGetBooleanv @107
glGetClipPlane @108
glGetDoublev @109
glGetError @110
glGetFloatv @111
glGetIntegerv @112
glGetLightfv @113
glGetLightiv @114
glGetMapdv @115
glGetMapfv @116
glGetMapiv @117
glGetMaterialfv @118
glGetMaterialiv @119
glGetPixelMapfv @120
glGetPixelMapuiv @121
glGetPixelMapusv @122
glGetPointerv @123
glGetPolygonStipple @124
glGetString @125
glGetTexEnvfv @126
glGetTexEnviv @127
glGetTexGendv @128
glGetTexGenfv @129
glGetTexGeniv @130
glGetTexImage @131
glGetTexLevelParameterfv @132
glGetTexLevelParameteriv @133
glGetTexParameterfv @134
glGetTexParameteriv @135
glHint @136
glIndexMask @137
glIndexPointer @138
glIndexd @139
glIndexdv @140
glIndexf @141
glIndexfv @142
glIndexi @143
glIndexiv @144
glIndexs @145
glIndexsv @146
glIndexub @147
glIndexubv @148
glInitNames @149
glInterleavedArrays @150
glIsEnabled @151
glIsList @152
glIsTexture @153
glLightModelf @154
glLightModelfv @155
glLightModeli @156
glLightModeliv @157
glLightf @158
glLightfv @159
glLighti @160
glLightiv @161
glLineStipple @162
glLineWidth @163
glListBase @164
glLoadIdentity @165
glLoadMatrixd @166
glLoadMatrixf @167
glLoadName @168
glLogicOp @169
glMap1d @170
glMap1f @171
glMap2d @172
glMap2f @173
glMapGrid1d @174
glMapGrid1f @175
glMapGrid2d @176
glMapGrid2f @177
glMaterialf @178
glMaterialfv @179
glMateriali @180
glMaterialiv @181
glMatrixMode @182
glMultMatrixd @183
glMultMatrixf @184
glNewList @185
glNormal3b @186
glNormal3bv @187
glNormal3d @188
glNormal3dv @189
glNormal3f @190
glNormal3fv @191
glNormal3i @192
glNormal3iv @193
glNormal3s @194
glNormal3sv @195
glNormalPointer @196
glOrtho @197
glPassThrough @198
glPixelMapfv @199
glPixelMapuiv @200
glPixelMapusv @201
glPixelStoref @202
glPixelStorei @203
glPixelTransferf @204
glPixelTransferi @205
glPixelZoom @206
glPointSize @207
glPolygonMode @208
glPolygonOffset @209
glPolygonStipple @210
glPopAttrib @211
glPopClientAttrib @212
glPopMatrix @213
glPopName @214
glPrioritizeTextures @215
glPushAttrib @216
glPushClientAttrib @217
glPushMatrix @218
glPushName @219
glRasterPos2d @220
glRasterPos2dv @221
glRasterPos2f @222
glRasterPos2fv @223
glRasterPos2i @224
glRasterPos2iv @225
glRasterPos2s @226
glRasterPos2sv @227
glRasterPos3d @228
glRasterPos3dv @229
glRasterPos3f @230
glRasterPos3fv @231
glRasterPos3i @232
glRasterPos3iv @233
glRasterPos3s @234
glRasterPos3sv @235
glRasterPos4d @236
glRasterPos4dv @237
glRasterPos4f @238
glRasterPos4fv @239
glRasterPos4i @240
glRasterPos4iv @241
glRasterPos4s @242
glRasterPos4sv @243
glReadBuffer @244
glReadPixels @245
glRectd @246
glRectdv @247
glRectf @248
glRectfv @249
glRecti @250
glRectiv @251
glRects @252
glRectsv @253
glRenderMode @254
glRotated @255
glRotatef @256
glScaled @257
glScalef @258
glScissor @259
glSelectBuffer @260
glShadeModel @261
glStencilFunc @262
glStencilMask @263
glStencilOp @264
glTexCoord1d @265
glTexCoord1dv @266
glTexCoord1f @267
glTexCoord1fv @268
glTexCoord1i @269
glTexCoord1iv @270
glTexCoord1s @271
glTexCoord1sv @272
glTexCoord2d @273
glTexCoord2dv @274
glTexCoord2f @275
glTexCoord2fv @276
glTexCoord2i @277
glTexCoord2iv @278
glTexCoord2s @279
glTexCoord2sv @280
glTexCoord3d @281
glTexCoord3dv @282
glTexCoord3f @283
glTexCoord3fv @284
glTexCoord3i @285
glTexCoord3iv @286
glTexCoord3s @287
glTexCoord3sv @288
glTexCoord4d @289
glTexCoord4dv @290
glTexCoord4f @291
glTexCoord4fv @292
glTexCoord4i @293
glTexCoord4iv @294
glTexCoord4s @295
glTexCoord4sv @296
glTexCoordPointer @297
glTexEnvf @298
glTexEnvfv @299
glTexEnvi @300
glTexEnviv @301
glTexGend @302
glTexGendv @303
glTexGenf @304
glTexGenfv @305
glTexGeni @306
glTexGeniv @307
glTexImage1D @308
glTexImage2D @309
glTexParameterf @310
glTexParameterfv @311
glTexParameteri @312
glTexParameteriv @313
glTexSubImage1D @314
glTexSubImage2D @315
glTranslated @316
glTranslatef @317
glVertex2d @318
glVertex2dv @319
glVertex2f @320
glVertex2fv @321
glVertex2i @322
glVertex2iv @323
glVertex2s @324
glVertex2sv @325
glVertex3d @326
glVertex3dv @327
glVertex3f @328
glVertex3fv @329
glVertex3i @330
glVertex3iv @331
glVertex3s @332
glVertex3sv @333
glVertex4d @334
glVertex4dv @335
glVertex4f @336
glVertex4fv @337
glVertex4i @338
glVertex4iv @339
glVertex4s @340
glVertex4sv @341
glVertexPointer @342
glViewport @343
wglChoosePixelFormat @344
wglCopyContext @345
wglCreateContext @346
wglCreateLayerContext @347
wglDeleteContext @348
wglDescribeLayerPlane @349
wglDescribePixelFormat @350
wglGetCurrentContext @351
wglGetCurrentDC @352
wglGetDefaultProcAddress @353
wglGetLayerPaletteEntries @354
wglGetPixelFormat @355
wglGetProcAddress @356
wglMakeCurrent @357
wglRealizeLayerPalette @358
wglSetLayerPaletteEntries @359
wglSetPixelFormat @360
wglShareLists @361
wglSwapBuffers @362
wglSwapLayerBuffers @363
wglSwapMultipleBuffers @364
wglUseFontBitmapsA @365
wglUseFontBitmapsW @366
wglUseFontOutlinesA @367
wglUseFontOutlinesW @368
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include "../../Common/Version.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""../Common/Version.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
PRODUCTVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
#ifdef WIN64
VALUE "FileDescription", "SwiftShader OpenGL 64-bit Dynamic Link Library"
#else
VALUE "FileDescription", "SwiftShader OpenGL 32-bit Dynamic Link Library"
#endif
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "libGL"
VALUE "LegalCopyright", "Copyright (C) 2016 Google Inc."
VALUE "OriginalFilename", "opengl32.dll"
VALUE "PrivateBuild", VERSION_STRING
VALUE "ProductName", "SwiftShader openGL Dynamic Link Library"
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOGEX 0, 0, 129, 47
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Waiting for debugger"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,72,26,50,14
LTEXT "Attach a debugger or ESC to cancel",IDC_STATIC,7,7,115,8
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 40
END
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment