José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2011 Jose Fonseca |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | * |
| 24 | **************************************************************************/ |
| 25 | |
Jose Fonseca | 9653f95 | 2015-05-19 16:32:43 +0100 | [diff] [blame] | 26 | #pragma once |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 27 | |
| 28 | |
José Fonseca | 219c9f2 | 2012-11-03 10:13:17 +0000 | [diff] [blame] | 29 | #include "glimports.hpp" |
| 30 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 31 | #include "glfeatures.hpp" |
José Fonseca | b0c5972 | 2015-01-05 20:45:41 +0000 | [diff] [blame] | 32 | |
Danylo Piliaiev | 9f18e5d | 2019-07-03 11:12:50 +0300 | [diff] [blame] | 33 | #include "glmemshadow.hpp" |
| 34 | |
| 35 | #include <map> |
| 36 | #include <vector> |
| 37 | #include <memory> |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 38 | |
Jose Fonseca | 27b8d81 | 2016-05-13 07:09:09 -0700 | [diff] [blame] | 39 | void APIENTRY _fake_glScissor(GLint x, GLint y, GLsizei width, GLsizei height); |
| 40 | void APIENTRY _fake_glViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 41 | |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 42 | namespace gltrace { |
| 43 | |
Robert Tarasov | 6ccf5bb | 2020-01-10 12:31:25 -0800 | [diff] [blame] | 44 | class ShareableContextResources { |
| 45 | public: |
| 46 | std::map<GLint, std::unique_ptr<GLMemoryShadow>> bufferToShadowMemory; |
| 47 | |
| 48 | std::vector<GLMemoryShadow*> dirtyShadows; |
| 49 | }; |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 50 | |
Imre Deak | a150c4a | 2012-05-07 09:10:26 +0300 | [diff] [blame] | 51 | class Context { |
| 52 | public: |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 53 | glfeatures::Profile profile; |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 54 | glfeatures::Extensions extensions; |
| 55 | glfeatures::Features features; |
| 56 | |
Jose Fonseca | 830c0be | 2016-05-01 19:46:34 +0100 | [diff] [blame] | 57 | bool user_arrays = false; |
Jose Fonseca | 830c0be | 2016-05-01 19:46:34 +0100 | [diff] [blame] | 58 | bool userArraysOnBegin = false; |
| 59 | unsigned retain_count = 0; |
José Fonseca | 219c9f2 | 2012-11-03 10:13:17 +0000 | [diff] [blame] | 60 | |
José Fonseca | 1e3950d | 2013-06-12 23:13:09 +0100 | [diff] [blame] | 61 | // Whether it has been bound before |
Jose Fonseca | 830c0be | 2016-05-01 19:46:34 +0100 | [diff] [blame] | 62 | bool bound = false; |
Jose Fonseca | fc0ce01 | 2016-05-01 19:51:05 +0100 | [diff] [blame] | 63 | // Whether it has been bound to a drawable |
| 64 | bool boundDrawable = false; |
José Fonseca | 1e3950d | 2013-06-12 23:13:09 +0100 | [diff] [blame] | 65 | |
Jose Fonseca | 97d22a7 | 2016-05-10 04:47:08 -0700 | [diff] [blame] | 66 | // whether glLockArraysEXT() has ever been called |
Jose Fonseca | 1638519 | 2016-05-13 08:55:25 -0700 | [diff] [blame] | 67 | GLuint lockedArrayCount = 0; |
Jose Fonseca | 97d22a7 | 2016-05-10 04:47:08 -0700 | [diff] [blame] | 68 | |
Robert Tarasov | 6ccf5bb | 2020-01-10 12:31:25 -0800 | [diff] [blame] | 69 | // the data which can be shared between shared contexts |
| 70 | std::shared_ptr<ShareableContextResources> sharedRes; |
Danylo Piliaiev | 9f18e5d | 2019-07-03 11:12:50 +0300 | [diff] [blame] | 71 | |
José Fonseca | 5c298db | 2012-07-11 12:14:31 +0100 | [diff] [blame] | 72 | Context(void) : |
Robert Tarasov | 6ccf5bb | 2020-01-10 12:31:25 -0800 | [diff] [blame] | 73 | profile(glfeatures::API_GL, 1, 0), |
| 74 | sharedRes(std::make_shared<ShareableContextResources>()) |
José Fonseca | 5c298db | 2012-07-11 12:14:31 +0100 | [diff] [blame] | 75 | { } |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 76 | }; |
Imre Deak | a150c4a | 2012-05-07 09:10:26 +0300 | [diff] [blame] | 77 | |
| 78 | void |
Robert Tarasov | 6ccf5bb | 2020-01-10 12:31:25 -0800 | [diff] [blame] | 79 | createContext(uintptr_t context_id, uintptr_t shared_context_id); |
Imre Deak | a150c4a | 2012-05-07 09:10:26 +0300 | [diff] [blame] | 80 | |
Imre Deak | a150c4a | 2012-05-07 09:10:26 +0300 | [diff] [blame] | 81 | void |
| 82 | retainContext(uintptr_t context_id); |
| 83 | |
| 84 | bool |
| 85 | releaseContext(uintptr_t context_id); |
| 86 | |
| 87 | void |
| 88 | setContext(uintptr_t context_id); |
| 89 | |
| 90 | void |
| 91 | clearContext(void); |
| 92 | |
| 93 | gltrace::Context * |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 94 | getContext(void); |
| 95 | |
José Fonseca | a08d275 | 2011-08-25 13:26:43 +0100 | [diff] [blame] | 96 | const GLubyte * |
José Fonseca | 632a78d | 2012-04-19 07:18:59 +0100 | [diff] [blame] | 97 | _glGetString_override(GLenum name); |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 98 | |
José Fonseca | a08d275 | 2011-08-25 13:26:43 +0100 | [diff] [blame] | 99 | void |
José Fonseca | 632a78d | 2012-04-19 07:18:59 +0100 | [diff] [blame] | 100 | _glGetIntegerv_override(GLenum pname, GLint *params); |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 101 | |
José Fonseca | a08d275 | 2011-08-25 13:26:43 +0100 | [diff] [blame] | 102 | const GLubyte * |
José Fonseca | 632a78d | 2012-04-19 07:18:59 +0100 | [diff] [blame] | 103 | _glGetStringi_override(GLenum name, GLuint index); |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 104 | |
| 105 | |
| 106 | } /* namespace gltrace */ |